mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 05:26:58 +02:00
We've got nifty output helpers. Use them. BUG=None TEST=build_packages+build_image for x86-alex works Change-Id: I03172a8b1baba770cd425a52a1061e998a9717b6 Reviewed-on: https://gerrit.chromium.org/gerrit/18246 Reviewed-by: Chris Masone <cmasone@chromium.org> Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
102 lines
2.7 KiB
Bash
Executable File
102 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (c) 2011 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.
|
|
|
|
SCRIPT_ROOT=$(readlink -f $(dirname "$0")/..)
|
|
. "${SCRIPT_ROOT}/common.sh" || exit 1
|
|
|
|
# We're invoked only by build_image, which runs in the chroot
|
|
assert_inside_chroot
|
|
|
|
# Flags
|
|
DEFINE_string root "" \
|
|
"The root file system to check."
|
|
|
|
# Parse command line
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
# Die on any errors
|
|
set -e
|
|
|
|
# Check all parts of a pipe
|
|
set -o pipefail
|
|
|
|
ROOT="$FLAGS_root"
|
|
if [[ ! -d "$ROOT" ]]; then
|
|
die "Root FS does not exist ($ROOT)"
|
|
fi
|
|
|
|
BINARIES="$ROOT/usr/bin/Xorg
|
|
$ROOT/boot/vmlinuz
|
|
$ROOT/sbin/session_manager
|
|
$ROOT/bin/sed
|
|
$ROOT/opt/google/chrome/chrome"
|
|
|
|
EXITCODE=0
|
|
for i in $BINARIES; do
|
|
if ! [[ -f $i ]]; then
|
|
error "cannot find $i"
|
|
EXITCODE=1
|
|
fi
|
|
done
|
|
|
|
# Extract the version number from lines like:
|
|
# kCrosAPIMinVersion = 29,
|
|
# kCrosAPIVersion = 30
|
|
extract_cros_version() {
|
|
NAME="$1"
|
|
FILE="$2"
|
|
VERSION=$(perl -ne "print \$1 if /^\\s*${NAME}\\s*=\\s*(\\d+)/" "$FILE")
|
|
test -z "$VERSION" && die "Failed to get $NAME from $FILE"
|
|
echo $VERSION
|
|
}
|
|
|
|
# Check the libcros version compatibility, like we do in libcros at run time.
|
|
# See also platform/cros/version_check.cc and load.cc.
|
|
check_cros_version() {
|
|
CHROME_CROS="${ROOT}/opt/google/chrome/include/chromeos_cros_api.h"
|
|
SYSTEM_CROS="${ROOT}/usr/include/cros/chromeos_cros_api.h"
|
|
|
|
if [ ! -f "$SYSTEM_CROS" ]; then
|
|
echo "test_build_root: Missing libcros headers."
|
|
return 1
|
|
fi
|
|
|
|
|
|
if [ ! -f "$CHROME_CROS" ]; then
|
|
# For compatiblity with old versions of Chrome which don't install headers
|
|
# and already check the libcros version, skip the check here.
|
|
return 0
|
|
fi
|
|
|
|
# Get the version of libcros in the chromium tree.
|
|
VERSION=$(extract_cros_version kCrosAPIVersion "${CHROME_CROS}")
|
|
|
|
# Get the min version of libcros in the chromium os tree.
|
|
MIN_VERSION=$(extract_cros_version kCrosAPIMinVersion "${SYSTEM_CROS}")
|
|
|
|
# Get the max version of libcros in the chromium os tree.
|
|
MAX_VERSION=$(extract_cros_version kCrosAPIVersion "${SYSTEM_CROS}")
|
|
|
|
if [ "$MIN_VERSION" -gt "$VERSION" ]; then
|
|
echo "test_build_root: System libcros not compatible with Chromium."
|
|
echo "Chromium requires version $VERSION, but system provides $MIN_VERSION"
|
|
echo "or later."
|
|
return 1
|
|
fi
|
|
if [ "$VERSION" -gt "$MAX_VERSION" ]; then
|
|
echo "test_build_root: System libcros not compatible with Chromium headers."
|
|
echo "Chromium requires version $VERSION, but system provides $MAX_VERSION"
|
|
echo "or earlier."
|
|
return 1
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
check_cros_version || EXITCODE=1
|
|
|
|
exit $EXITCODE
|