Files
OpenCellular/util/getversion.sh
Randall Spangler fe76b51da0 Truncate version string to 32 characters
The version struct and EC_CMD_GET_VERSION assume 32-character version
strings.  But if the git tree is dirty and the board name is long, the
version string overflows that limit.

This change truncates what's stored in the version string to fit.

The build info still contains the full version string, as it did before.

BUG=chrome-os-partner:21156
BRANCH=none
TEST=build BOARD=mccroskey with a dirty tree; it should build.
     Then cat build/mccroskey/ec_version.h to see CROS_EC_VERSION32 has
     truncated the version string.  Then build a platform of your choice
     and type 'version' to see that the version string and build info is
     still reported correctly.

Change-Id: Ie71b8efd99a83315f8b4d5ad10c51e48781b12f4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/62649
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2013-07-19 18:01:55 -07:00

51 lines
1.5 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
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
dirty=`sh -c "[ '$(git diff-index --name-only HEAD)' ] && echo '-dirty'"`
vbase="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}"
else
vbase="no_version"
fi
ver="${BOARD}_${vbase}"
echo "/* This file is generated by util/getversion.sh */"
echo "/* Version string for use by common/version.c */"
echo "#ifdef SHIFT_CODE_FOR_TEST"
echo "#define CROS_EC_VERSION \"${ver}_shift\""
echo "#else"
echo "#define CROS_EC_VERSION \"${ver}\""
echo "#endif"
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 DATE \"`date '+%F %T'`\""
echo "#define BUILDER \"${USER}@`hostname`\""