Skip to content

Commit

Permalink
[lldb-cmake-matrix] Fix environment leak across runs
Browse files Browse the repository at this point in the history
Any `export` statement in a pipeline description will leak across
different compiler stages or, worse, between two runs of the entire
pipeline. This was seen recently in two ways:

1. The Dwarf 2 / 4 runs were using a Clang 13.0 built on a previous
pipeline run, and they were failing because some tests require ToT
clang.
2. The Dwarf 2 / 4 runs were trying to use Clang 13.0, but the workspace
was cleaned after the previous pipeline run, resulting in a "cannot
find clang" error.

This commit addresses the issue by no longer using environment variables
to communicate which Clang to use when building LLDB tests. Instead, we
now use parameters to the `test_monorepo_build.py` script. More
generally though, there are still a lot of `export` statements in the
pipeline, and these should be examined in isolation to determine how to
best remove them.

Jenkins provides ways to set environment variables more carefully [1];
however, for the purposes of the LLDB test compiler variable, this is
dangerous: we don't want such a flag to last any longer than the CMake
configure step, so this commit uses the script argument approach.

[1]: https://www.jenkins.io/doc/book/pipeline/syntax/#environment

Differential Revision: https://reviews.llvm.org/D132035
  • Loading branch information
felipepiovezan committed Aug 17, 2022
1 parent da73b75 commit 3175929
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 6 additions & 0 deletions test/jenkins/test_monorepo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,9 @@
# RUN: python %{src_root}/zorg/jenkins/monorepo_build.py cmake all > %t-timeout-default.log
# RUN: FileCheck --check-prefix CHECK-TIMEOUT-DEFAULT < %t-timeout-default.log %s
# CHECK-TIMEOUT-DEFAULT: --timeout=600

# RUN: python %{src_root}/zorg/jenkins/monorepo_build.py lldb-cmake-matrix configure \
# RUN: --lldb-test-compiler="MY_LLDB_TEST_COMPILER" > %t-lldb-configure.log
# RUN: FileCheck --check-prefix CHECK-LLDB-CONFIG < %t-lldb-configure.log %s

# CHECK-LLDB-CONFIG: -DLLDB_TEST_COMPILER=MY_LLDB_TEST_COMPILER
10 changes: 5 additions & 5 deletions zorg/jenkins/jobs/jobs/lldb-cmake-matrix
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ pipeline {
timeout(60) {
sh '''
export PATH=$PATH:/usr/bin:/usr/local/bin
export LLDB_TEST_COMPILER="$WORKSPACE/clang_502_build/bin/clang"
python llvm-zorg/zorg/jenkins/monorepo_build.py lldb-cmake-matrix configure \
--assertions \
--lldb-test-compiler="$WORKSPACE/clang_502_build/bin/clang" \
--projects="clang;lldb" \
--runtimes="libcxx;libcxxabi" \
--cmake-type=Release \
Expand Down Expand Up @@ -260,9 +260,9 @@ pipeline {
timeout(60) {
sh '''
export PATH=$PATH:/usr/bin:/usr/local/bin
export LLDB_TEST_COMPILER="$WORKSPACE/clang_701_build/bin/clang"
python llvm-zorg/zorg/jenkins/monorepo_build.py lldb-cmake-matrix configure \
--assertions \
--lldb-test-compiler="$WORKSPACE/clang_701_build/bin/clang" \
--projects="clang;lldb" \
--runtimes="libcxx;libcxxabi" \
--cmake-type=Release \
Expand Down Expand Up @@ -319,9 +319,9 @@ pipeline {
timeout(60) {
sh '''
export PATH=$PATH:/usr/bin:/usr/local/bin
export LLDB_TEST_COMPILER="$WORKSPACE/clang_900_build/bin/clang"
python llvm-zorg/zorg/jenkins/monorepo_build.py lldb-cmake-matrix configure \
--assertions \
--lldb-test-compiler="$WORKSPACE/clang_900_build/bin/clang" \
--projects="clang;lldb" \
--runtimes="libcxx;libcxxabi" \
--cmake-type=Release \
Expand Down Expand Up @@ -378,9 +378,9 @@ pipeline {
timeout(60) {
sh '''
export PATH=$PATH:/usr/bin:/usr/local/bin
export LLDB_TEST_COMPILER="$WORKSPACE/clang_1101_build/bin/clang"
python llvm-zorg/zorg/jenkins/monorepo_build.py lldb-cmake-matrix configure \
--assertions \
--lldb-test-compiler="$WORKSPACE/clang_1101_build/bin/clang" \
--projects="clang;lldb" \
--runtimes="libcxx;libcxxabi" \
--cmake-type=Release \
Expand Down Expand Up @@ -437,9 +437,9 @@ pipeline {
timeout(60) {
sh '''
export PATH=$PATH:/usr/bin:/usr/local/bin
export LLDB_TEST_COMPILER="$WORKSPACE/clang_1300_build/bin/clang"
python llvm-zorg/zorg/jenkins/monorepo_build.py lldb-cmake-matrix configure \
--assertions \
--lldb-test-compiler="$WORKSPACE/clang_1300_build/bin/clang" \
--projects="clang;lldb" \
--runtimes="libcxx;libcxxabi" \
--cmake-type=Release \
Expand Down
11 changes: 4 additions & 7 deletions zorg/jenkins/monorepo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def __init__(self, args):
self._lldb_standalone_type = os.environ.get('LLDB_STANDALONE_TYPE', 'build-tree')
self._lldb_xcode_build_dir = os.environ.get('LLDB_XCODE_BUILD_DIR', 'lldb-xcode-build')
self._lldb_install_dir = os.environ.get('LLDB_INSTALL_DIR', 'lldb-install')
self._lldb_test_compiler = os.environ.get('LLDB_TEST_COMPILER', '')
self._install_dir = os.environ.get('INSTALL_DIR', 'clang-install')
self.j_level = os.environ.get('J_LEVEL', None)
self.max_parallel_tests = os.environ.get('MAX_PARALLEL_TESTS', None)
Expand Down Expand Up @@ -166,10 +165,6 @@ def lldbinstalldir(self):
"""The install directory for the lldb build."""
return os.path.join(self.workspace, self._lldb_install_dir)

def lldbtestcompiler(self):
"""The compiler used to build LLDB tests."""
return self._lldb_test_compiler

def installdir(self):
"""The install directory for the compile."""
return os.path.join(self.workspace, self._install_dir)
Expand Down Expand Up @@ -576,9 +571,9 @@ def lldb_cmake_builder(target, variant=None):
"-DCMAKE_CXX_FLAGS={}".format(' '.join(conf.compiler_flags))
])

if conf.lldbtestcompiler():
if conf.lldb_test_compiler is not None:
cmake_cmd.extend([
'-DLLDB_TEST_COMPILER=' + conf.lldbtestcompiler(),
'-DLLDB_TEST_COMPILER=' + conf.lldb_test_compiler,
])

cmake_cmd.extend(conf.cmake_flags)
Expand Down Expand Up @@ -1071,6 +1066,8 @@ def parse_args():
help="Semicolon seperated list of runtimes to enable.")
parser.add_argument('--timeout', dest='timeout', type=int, default='600',
help='Individual test timeout in seconds.')
parser.add_argument('--lldb-test-compiler',
help='The compiler used to build LLDB tests.')
args = parser.parse_args()
if args.thinlto:
args.lto = True
Expand Down

0 comments on commit 3175929

Please sign in to comment.