diff options
author | Jordan R Abrahams-Whitehead <ajordanr@google.com> | 2022-03-31 16:03:32 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-04-04 18:09:06 +0000 |
commit | bcfe50b5b79bd34b40b8ca5895767bb9540246d9 (patch) | |
tree | d9a7e53733e119904673f2512031360a43cf4d36 /llvm_tools | |
parent | 273a7232175a649c294ceb71de9b8bc6a091cb3c (diff) | |
download | toolchain-utils-bcfe50b5b79bd34b40b8ca5895767bb9540246d9.tar.gz |
llvm_tools: Add llvm_local_bisection.sh
This adds a template for a complete bash script for llvm local
bisection.
This template is from a script that llozano gave to ryanbeltran,
but reworked to be easily extendable to other bisection steps.
Comes with "batteries included" build_llvm and "build_pkg"
functions.
BUG=None
TEST=Run on llvm-project as the `git bisect run` arg.
Change-Id: Ibc0115033d07b76d40ec2f4b7d7950cf9a518152
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3563907
Tested-by: Jordan Abrahams-Whitehead <ajordanr@google.com>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Commit-Queue: Jordan Abrahams-Whitehead <ajordanr@google.com>
Diffstat (limited to 'llvm_tools')
-rwxr-xr-x | llvm_tools/llvm_local_bisection.sh | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/llvm_tools/llvm_local_bisection.sh b/llvm_tools/llvm_local_bisection.sh new file mode 100755 index 00000000..f84c2410 --- /dev/null +++ b/llvm_tools/llvm_local_bisection.sh @@ -0,0 +1,108 @@ +#!/bin/bash -u +# -*- coding: utf-8 -*- +# Copyright 2022 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. + +# llvm_bisection_template.sh +# +# This script is meant to be run inside a `git bisect` process, like so: +# +# $ cd <your llvm-project dir> +# $ git bisect start +# $ git bisect bad <your bad ref> +# $ git bisect good <your good ref> +# $ git bisect run ~/chromimuos/src/scripts/llvm_bisection_template.sh +# +# This template exists as a "batteries included" LLVM bisection script, +# which will modify the LLVM_NEXT hash to help the mage track down issues +# locally. +# +# Modify the fixme sections below to customize to your bisection use-case. + +# FIXME: Replace this for the location of your llvm clone within the chroot. +# We need this for the git history. +LLVM_CLONE_PATH="${HOME}/chromiumos/src/third_party/llvm-project" + +main () { + # Note this builds with USE="llvm-next debug -thinlto -llvm_pgo_use" + build_llvm || exit + + # FIXME: Write your actual bisection command here which uses + # LLVM_NEXT here. + # + # Example bisection command: + # + # build_pkg efitools || exit 1 + # + # You can use build_pkg if you want to emerge a package and print + # out diagnostics along the way + # + # Fail Example: build_pkg "${MY_PACKAGE}" || exit 1 + # Skip Example: build_pkg "${MY_PACKAGE}" || exit 125 + # +} + +# --------------------------------------------------------------------- + +# Current LLVM_NEXT_HASH we're using. Does not need to be set. +CURRENT='UNKNOWN' + +logdo () { + local cmd="${1}" + shift + printf '%1 $ %2' "$(date '+%T')" "${cmd}" + for i in "$@"; do + printf "'%1'" "${i}" + done + printf "\n" + "${cmd}" "$@" +} + +log () { + echo "$(date '+%T') | $*" +} + +build_llvm () { + cd "${LLVM_CLONE_PATH}" || exit 2 # Exit with error + local llvm_ebuild_path + llvm_ebuild_path="$(readlink -f "$(equery which llvm)")" + CURRENT="$(git rev-parse --short HEAD)" + log "Current hash=${CURRENT}" + NEW_LINE="LLVM_NEXT_HASH=\"${CURRENT}\"" + sed -i "s/^LLVM_NEXT_HASH=\".*\"/${NEW_LINE}/" "${llvm_ebuild_path}" + + local logfile="/tmp/build-llvm.${CURRENT}.out" + log "Writing logs to ${logfile}" + log "sudo USE='llvm-next debug -thinlto -llvm_use_pgo' emerge sys-devel/llvm" + logdo sudo USE='llvm-next debug -thinlto -llvm_use_pgo' emerge \ + sys-devel/llvm \ + &> "${logfile}" + local emerge_exit_code="$?" + if [[ "${emerge_exit_code}" -ne 0 ]]; then + log "FAILED to build llvm with hash=${CURRENT}" + log 'Skipping this hash' + return 125 # 125 is the "skip" exit code. + fi + log "Succesfully built LLVM with hash=${CURRENT}" + return 0 # Explicitly returning 0 for "good" even if a command errors out +} + +build_pkg () { + local pkg="${1}" + + local logfile="/tmp/build-${pkg}.${CURRENT}.out" + log "Writing logs to ${logfile}" + log "sudo emerge ${pkg}" + logdo sudo emerge "${pkg}" \ + &> "${logfile}" + local emerge_exit_code="$?" + if [[ "${emerge_exit_code}" -ne 0 ]]; then + log "FAILED to build ${pkg} with hash=${CURRENT}" + return 1 # 1 here isn't for bisection, but for chaining with `||` + fi + log "Successfully built ${pkg} with hash=${CURRENT}" + return 0 # Explicitly returning 0 for "good" even if a command errors out +} + +main |