From 42f882f8ab3978b44276107121f7b851457fcd4d Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Fri, 18 Aug 2023 10:44:20 -0400 Subject: [PATCH] Added a CI test for installed libraries when using CMake. --- .github/workflows/release_build.yml | 12 ++++++++++++ c/test/application_base.py | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index b6b94da..d5debed 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -150,6 +150,12 @@ jobs: POLARIS_API_KEY: ${{ secrets.POLARIS_API_KEY }} run: | ./test/run_unit_tests.sh --tool=${{ matrix.tool }} --unique-id-prefix=${{ matrix.tool }}_cpp + - name: Run Unit Tests With Installed Libraries (CMake, Linux) + if: matrix.arch == 'x64' && matrix.tool == 'cmake' && matrix.os == 'ubuntu-latest' + env: + POLARIS_API_KEY: ${{ secrets.POLARIS_API_KEY }} + run: | + ./test/run_unit_tests.sh --tool=${{ matrix.tool }} --unique-id-prefix=${{ matrix.tool }}_cpp --installed # Package artifacts (Bazel only -- no need to do this for multiple build # tools). @@ -272,6 +278,12 @@ jobs: POLARIS_API_KEY: ${{ secrets.POLARIS_API_KEY }} run: | ./test/run_unit_tests.sh --tool=${{ matrix.tool }} --unique-id-prefix=${{ matrix.tool }}_c_ + - name: Run Unit Tests With Installed Libraries (CMake, Linux) + if: matrix.arch == 'x64' + env: + POLARIS_API_KEY: ${{ secrets.POLARIS_API_KEY }} + run: | + ./test/run_unit_tests.sh --tool=${{ matrix.tool }} --unique-id-prefix=${{ matrix.tool }}_c_ --installed # Package artifacts (Bazel only -- no need to do this for multiple build # tools). diff --git a/c/test/application_base.py b/c/test/application_base.py index abdbe99..7037564 100644 --- a/c/test/application_base.py +++ b/c/test/application_base.py @@ -29,6 +29,9 @@ def __init__(self, application_name, root_dir=None): # Define and parse arguments. self.parser = ArgumentParser(usage='%(prog)s [OPTIONS]...') + self.parser.add_argument( + '--installed', action='store_true', + help="Run the application using shared libraries installed on the system (CMake only).") self.parser.add_argument( '-p', '--path', metavar='PATH', help="The path to the application to be run.") @@ -84,6 +87,10 @@ def parse_args(self): print('Error: Unsupported --tool value.') sys.exit(self.ARGUMENT_ERROR) + if self.options.installed and not self.options.tool == 'cmake': + print('Error: Installed applications only supported for CMake.') + sys.exit(self.ARGUMENT_ERROR) + if self.options.unique_id_prefix is not None: self.options.unique_id = self.options.unique_id_prefix + self.options.unique_id if len(self.options.unique_id) > 36: @@ -114,6 +121,15 @@ def run(self, return_result=False): if command[i].endswith(api_key_standin): command[i] = command[i].replace(api_key_standin, self.options.polaris_api_key) + # If running using installed libraries (CMake), set LD_LIBRARY_PATH to explicitly override the rpath compiled + # into the application. This assumes the application is running out of the build directory, not a copy installed + # on the system. When CMake compiles an application, it sets its rpath to refer to the .so file from the build + # directory. When it installs that application, it strips that rpath. + env = None + if self.options.tool == 'cmake' and self.options.installed: + env = os.environ.copy() + env['LD_LIBRARY_PATH'] = '/usr/local/lib' + # Run the command. def ignore_signal(sig, frame): signal.signal(sig, signal.SIG_DFL) @@ -126,7 +142,7 @@ def preexec_function(): signal.signal(signal.SIGTERM, ignore_signal) self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8', - preexec_fn=preexec_function) + preexec_fn=preexec_function, env=env) # Capture SIGINT and SIGTERM and shutdown the application gracefully. def request_shutdown(sig, frame):