mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 16:41:55 +00:00
The cr50 code comes from four different repositories. This patch
introduces an array of the repositories where version information is
supposed to come from.
For all boards but cr50 this array includes just the local repository,
for cr50 the array is extended with the three other components.
This patch also allows to change the 'tree dirty' marker appended to
the sha1s of the 'dirty' trees, having a shorter marker helps to keep
multicomponent version strings shorter.
All external component's version information in the generated combined
version string is prepended by the component's root directory name.
BRANCH=ToT
BUG=chrome-os-partner:55373
TEST=ran the script for two EC boards, kevin and cr50, verified the
output:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
$ BOARD=kevin ./util/getversion.sh
/* This file is generated by util/getversion.sh */
/* Version string for use by common/version.c */
/* Version string, truncated to 31 chars (+ terminating null = 32) */
/* Sub-fields for use in Makefile.rules and to form build info string
* in common/version.c. */
/* Repo is clean, use the commit date of the last commit */
$
$ BOARD=cr50 ./util/getversion.sh
/* This file is generated by util/getversion.sh */
/* Version string for use by common/version.c */
/* Version string, truncated to 31 chars (+ terminating null = 32) */
/* Sub-fields for use in Makefile.rules and to form build info string
* in common/version.c. */
/* Repo is clean, use the commit date of the last commit */
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
then introduced some local changes in the ec and tpm2 directories and
ran the script again. Note the '+' used as the 'dirty' marker in the
cr50 string:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
$ BOARD=kevin ./util/getversion.sh
/* This file is generated by util/getversion.sh */
/* Version string for use by common/version.c */
/* Version string, truncated to 31 chars (+ terminating null = 32) */
/* Sub-fields for use in Makefile.rules and to form build info string
* in common/version.c. */
/* Repo is dirty, using time of last compilation */
$
$ BOARD=cr50 ./util/getversion.sh
/* This file is generated by util/getversion.sh */
/* Version string for use by common/version.c */
/* Version string, truncated to 31 chars (+ terminating null = 32) */
/* Sub-fields for use in Makefile.rules and to form build info string
* in common/version.c. */
/* Repo is dirty, using time of last compilation */
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Change-Id: I4b4ec23ce003970c09442e8d8aeed2306d4e5dd8
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/363917
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
122 lines
3.7 KiB
Bash
Executable File
122 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
#
|
|
# Generate version information for the EC binary
|
|
|
|
# Use this symbol as a separator to be able to reliably concatenate strings of
|
|
# text.
|
|
dc=$'\001'
|
|
|
|
# Default marker to indicate 'dirty' repositories
|
|
dirty_marker='-dirty'
|
|
|
|
# This function examines the state of the current directory and attempts to
|
|
# extract its version information: the latest tag, if any, how many patches
|
|
# are there since the latest tag, the top sha1, and if there are local
|
|
# modifications.
|
|
#
|
|
# Local modifications are reported by concatenating the revision string and
|
|
# the string '-dirty' using the $dc symbol as the separator.
|
|
#
|
|
# If there is no tags defined in this git repository, the base version is
|
|
# considered to be 0.0.
|
|
#
|
|
# If current directory is not a git depository, this function prints out
|
|
# "no_version"
|
|
|
|
get_tree_version() {
|
|
local dirty
|
|
local ghash
|
|
local numcommits
|
|
local tag
|
|
local vbase
|
|
local ver_branch
|
|
local ver_major
|
|
|
|
if ghash=`git rev-parse --short --verify HEAD 2>/dev/null`; then
|
|
if gdesc=`git describe --dirty --match='v*' 2>/dev/null`; then
|
|
IFS="-" fields=($gdesc)
|
|
tag="${fields[0]}"
|
|
IFS="." vernum=($tag)
|
|
numcommits=$((${vernum[2]}+${fields[1]:-0}))
|
|
ver_major="${vernum[0]}"
|
|
ver_branch="${vernum[1]}"
|
|
else
|
|
numcommits=`git rev-list HEAD | wc -l`
|
|
ver_major="v0"
|
|
ver_branch="0"
|
|
fi
|
|
# avoid putting the -dirty attribute if only the timestamp
|
|
# changed
|
|
git status > /dev/null 2>&1
|
|
|
|
if [ -n "$(git diff-index --name-only HEAD 2>/dev/null)" ]; then
|
|
dirty="${dirty_marker}"
|
|
fi
|
|
vbase="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}"
|
|
else
|
|
# Fall back to the VCSID provided by the packaging system if available.
|
|
if ghash=${VCSID##*-}; then
|
|
vbase="1.1.9999-${ghash:0:7}"
|
|
else
|
|
# then ultimately fails to "no_version"
|
|
vbase="no_version"
|
|
fi
|
|
fi
|
|
echo "${vbase}${dc}${dirty}"
|
|
}
|
|
|
|
|
|
IFS="${dc}"
|
|
ver="${BOARD}_"
|
|
global_dirty= # set if any of the component repos is 'dirty'.
|
|
dir_list=( . ) # list of component directories, always includes the EC tree
|
|
|
|
case "${BOARD}" in
|
|
(cr50)
|
|
# cr50 includes sources from 4 different git trees. Shortened 'dirty' tree
|
|
# marker allows to keep the summary version string shorter.
|
|
dirty_marker='+'
|
|
dir_list+=( private-cr51 ../../third_party/tpm2 ../../third_party/cryptoc )
|
|
;;
|
|
esac
|
|
|
|
# Create a combined version string for all component directories.
|
|
for git_dir in ${dir_list[@]}; do
|
|
pushd "${git_dir}" > /dev/null
|
|
component="$(basename "${git_dir}")"
|
|
values=( $(get_tree_version) )
|
|
vbase="${values[0]}" # Retrieved version information.
|
|
global_dirty+="${values[1]}" # Non-zero, if the repository is 'dirty'
|
|
if [ "${component}" != "." ]; then
|
|
ver+=" ${component}:"
|
|
fi
|
|
ver+="${vbase}"
|
|
popd > /dev/null
|
|
done
|
|
|
|
echo "/* This file is generated by util/getversion.sh */"
|
|
|
|
echo "/* Version string for use by common/version.c */"
|
|
echo "#define CROS_EC_VERSION \"${ver}\""
|
|
|
|
echo "/* Version string, truncated to 31 chars (+ terminating null = 32) */"
|
|
echo "#define CROS_EC_VERSION32 \"${ver:0:31}\""
|
|
|
|
echo "/* Sub-fields for use in Makefile.rules and to form build info string"
|
|
echo " * in common/version.c. */"
|
|
echo "#define VERSION \"${ver}\""
|
|
echo "#define BUILDER \"${USER}@`hostname`\""
|
|
|
|
if [ -n "$global_dirty" ]; then
|
|
echo "/* Repo is dirty, using time of last compilation */"
|
|
echo "#define DATE \"$(date '+%F %T')\""
|
|
else
|
|
echo "/* Repo is clean, use the commit date of the last commit */"
|
|
gitdate=$(git log -1 --format='%ci' HEAD | cut -d ' ' -f '1 2')
|
|
echo "#define DATE \"${gitdate}\""
|
|
fi
|