aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2022-06-09 10:33:57 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-06-10 20:45:29 +0000
commitd9d151871f0500e8cdad2432e40698ca15fbf8b4 (patch)
tree355510ee697b1a822dfa742735c18373a3351fab
parent41e93526f0117ee883353c800f063239fff92ad4 (diff)
downloadtoolchain-utils-d9d151871f0500e8cdad2432e40698ca15fbf8b4.tar.gz
compiler_wrapper: add a --version_suffix flag to build.py
This allows us to provide more information about the compiler being wrapped to the wrapper. The intended use of this is to embed hashes of the compiler being wrapped into the wrapper itself, so as the compiler changes, the wrapper's SHA changes with it. While I'm in the area, fix up a comment, and apply this flag to our manual wrapper installation script. BUG=b:222321317 TEST=`emerge llvm` Change-Id: I20380722e1e539d51fe7ea708c63dad696d84c87 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3696434 Reviewed-by: Denis Nikitin <denik@chromium.org> Tested-by: George Burgess <gbiv@chromium.org> Commit-Queue: George Burgess <gbiv@chromium.org>
-rwxr-xr-xcompiler_wrapper/build.py21
-rw-r--r--compiler_wrapper/config.go2
-rwxr-xr-xcompiler_wrapper/install_compiler_wrapper.sh31
3 files changed, 45 insertions, 9 deletions
diff --git a/compiler_wrapper/build.py b/compiler_wrapper/build.py
index 44c398bf..d004b553 100755
--- a/compiler_wrapper/build.py
+++ b/compiler_wrapper/build.py
@@ -23,7 +23,12 @@ def parse_args():
choices=['cros.hardened', 'cros.nonhardened', 'cros.host', 'android'])
parser.add_argument('--use_ccache', required=True, choices=['true', 'false'])
parser.add_argument(
- '--use_llvm_next', required=True, choices=['true', 'false'])
+ '--version_suffix',
+ help='A string appended to the computed version of the wrapper. This '
+ 'is appeneded directly without any delimiter.')
+ parser.add_argument('--use_llvm_next',
+ required=True,
+ choices=['true', 'false'])
parser.add_argument('--output_file', required=True, type=str)
parser.add_argument(
'--static',
@@ -41,6 +46,11 @@ def parse_args():
def calc_go_args(args, version, build_dir):
+ # These seem unnecessary, and might lead to breakages with Go's ldflag
+ # parsing. Don't allow them.
+ if "'" in version:
+ raise ValueError('`version` should not contain single quotes')
+
ldFlags = [
'-X',
'main.ConfigName=' + args.config,
@@ -49,7 +59,8 @@ def calc_go_args(args, version, build_dir):
'-X',
'main.UseLlvmNext=' + args.use_llvm_next,
'-X',
- 'main.Version=' + version,
+ # Quote this, as `version` may have spaces in it.
+ "'main.Version=" + version + "'",
]
# If the wrapper is intended for ChromeOS, we need to use libc's exec.
@@ -60,8 +71,8 @@ def calc_go_args(args, version, build_dir):
if args.config == 'android':
# If android_llvm_next_flags.go DNE, we'll get an obscure "no
# llvmNextFlags" build error; complaining here is clearer.
- if not os.path.exists(
- os.path.join(build_dir, 'android_llvm_next_flags.go')):
+ if not os.path.exists(os.path.join(build_dir,
+ 'android_llvm_next_flags.go')):
sys.exit('In order to build the Android wrapper, you must have a local '
'android_llvm_next_flags.go file; please see '
'cros_llvm_next_flags.go.')
@@ -92,6 +103,8 @@ def main():
args = parse_args()
build_dir = os.path.dirname(__file__)
version = read_version(build_dir)
+ if args.version_suffix:
+ version += args.version_suffix
# Note: Go does not support using absolute package names.
# So we run go inside the directory of the the build file.
sys.exit(
diff --git a/compiler_wrapper/config.go b/compiler_wrapper/config.go
index c275ae9f..25df476f 100644
--- a/compiler_wrapper/config.go
+++ b/compiler_wrapper/config.go
@@ -34,7 +34,7 @@ type config struct {
triciumNitsDir string
// Directory to store crash artifacts in.
crashArtifactsDir string
- // Version. Only used for printing via -print-cmd.
+ // Version. Only exposed via -print-config.
version string
}
diff --git a/compiler_wrapper/install_compiler_wrapper.sh b/compiler_wrapper/install_compiler_wrapper.sh
index f05f2b4c..a503895f 100755
--- a/compiler_wrapper/install_compiler_wrapper.sh
+++ b/compiler_wrapper/install_compiler_wrapper.sh
@@ -11,18 +11,41 @@ if [[ ! -e /etc/cros_chroot_version ]]; then
exit 1
fi
set -e
+
+# Use a unique value here, since folks doing wrapper dev _likely_ want builds
+# to always be redone.
+version_suffix="manually_installed_wrapper_at_unix_$(date +%s.%6N)"
+echo "Using toolchain hash: ${version_suffix}"
cd "$(dirname "$(readlink -m "$0")")"
+
+build_py() {
+ ./build.py --version_suffix="${version_suffix}" "$@"
+}
+
echo "Updated files:"
# Update the host wrapper
-./build.py --config=cros.host --use_ccache=false --use_llvm_next=false --output_file=./clang_host_wrapper
+build_py \
+ --config=cros.host \
+ --use_ccache=false \
+ --use_llvm_next=false \
+ --output_file=./clang_host_wrapper
sudo mv ./clang_host_wrapper /usr/bin/clang_host_wrapper
echo "/usr/bin/clang_host_wrapper"
sudo cp ../binary_search_tool/bisect_driver.py /usr/bin
echo "/usr/bin/clang_host_wrapper/bisect_driver.py"
# Update the target wrappers
-./build.py --config=cros.hardened --use_ccache=false --use_llvm_next=false --output_file=./sysroot_wrapper.hardened.noccache
-./build.py --config=cros.hardened --use_ccache=true --use_llvm_next=false --output_file=./sysroot_wrapper.hardened.ccache
+build_py \
+ --config=cros.hardened \
+ --use_ccache=false \
+ --use_llvm_next=false \
+ --output_file=./sysroot_wrapper.hardened.noccache
+build_py \
+ --config=cros.hardened \
+ --use_ccache=true \
+ --use_llvm_next=false \
+ --output_file=./sysroot_wrapper.hardened.ccache
+
# Update clang target wrappers.
sudo cp ./sysroot_wrapper.hardened.noccache ./sysroot_wrapper.hardened.ccache /usr/bin
echo "Updated clang wrapper /usr/bin/sysroot_wrapper.hardened.noccache"
@@ -30,7 +53,7 @@ echo "Updated clang wrapper /usr/bin/sysroot_wrapper.hardened.ccache"
# Update GCC target wrappers.
for GCC in cross-x86_64-cros-linux-gnu/gcc cross-armv7a-cros-linux-gnueabihf/gcc cross-aarch64-cros-linux-gnu/gcc; do
- if ! FILES="$(equery f ${GCC})"; then
+ if ! FILES="$(equery f "${GCC}")"; then
if [[ $(equery l "${GCC}" 2>&1 | wc -c) -eq 0 ]]; then
echo "no ${GCC} package found; skipping" >&2
continue