diff options
author | 2024-01-17 16:14:55 -0800 | |
---|---|---|
committer | 2024-01-17 16:14:55 -0800 | |
commit | b559eefb50a34a1f78c3a34dddba89e0ab742c5a (patch) | |
tree | 01b3f59a7ae602ad4f35c7ca5652e00cc2c7d430 /ci/build_test_suites.py | |
parent | d42a053aa8ecaba6cd920d2d8ef281f8dc3d4d25 (diff) |
Add option to print command output and fix env on dumpvars commands
Two fixes:
soong dumpvars commands require TARGET_RELEASE to be set in the env, so
set that.
Added option to print command output which is useful for actually
logging build output not only in the case of command failures.
Test: ABTD run with this change
Bug: 314171817
Change-Id: Ia3ad8ebfa58959c13417abaeeaa42a354c4c61de
Diffstat (limited to 'ci/build_test_suites.py')
-rw-r--r-- | ci/build_test_suites.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/ci/build_test_suites.py b/ci/build_test_suites.py index 0c1d2110a5..10640415e0 100644 --- a/ci/build_test_suites.py +++ b/ci/build_test_suites.py @@ -69,7 +69,7 @@ def build_everything(args: argparse.Namespace): build_command = base_build_command(args) build_command.append('general-tests') - run_command(build_command) + run_command(build_command, print_output=True) def build_affected_modules(args: argparse.Namespace): @@ -81,9 +81,9 @@ def build_affected_modules(args: argparse.Namespace): build_command = base_build_command(args) build_command.extend(modules_to_build) - run_command(build_command) + run_command(build_command, print_output=True) - zip_build_outputs(modules_to_build, args.dist_dir) + zip_build_outputs(modules_to_build, args.dist_dir, args.target_release) def base_build_command(args: argparse.Namespace) -> list: @@ -102,12 +102,17 @@ def base_build_command(args: argparse.Namespace) -> list: return build_command -def run_command(args: list[str]) -> str: +def run_command( + args: list[str], + env: Dict[Text, Text] = os.environ, + print_output: bool = False, +) -> str: result = subprocess.run( args=args, text=True, capture_output=True, check=False, + env=env, ) # If the process failed, print its stdout and propagate the exception. if not result.returncode == 0: @@ -116,6 +121,10 @@ def run_command(args: list[str]) -> str: print('stderr: ' + result.stderr) result.check_returncode() + + if print_output: + print(result.stdout) + return result.stdout @@ -201,17 +210,19 @@ def matches_file_patterns( return False -def zip_build_outputs(modules_to_build: Set[Text], dist_dir: Text): +def zip_build_outputs( + modules_to_build: Set[Text], dist_dir: Text, target_release: Text +): src_top = os.environ.get('TOP', os.getcwd()) # Call dumpvars to get the necessary things. # TODO(lucafarsi): Don't call soong_ui 4 times for this, --dumpvars-mode can # do it but it requires parsing. - host_out_testcases = get_soong_var('HOST_OUT_TESTCASES') - target_out_testcases = get_soong_var('TARGET_OUT_TESTCASES') - product_out = get_soong_var('PRODUCT_OUT') - soong_host_out = get_soong_var('SOONG_HOST_OUT') - host_out = get_soong_var('HOST_OUT') + host_out_testcases = get_soong_var('HOST_OUT_TESTCASES', target_release) + target_out_testcases = get_soong_var('TARGET_OUT_TESTCASES', target_release) + product_out = get_soong_var('PRODUCT_OUT', target_release) + soong_host_out = get_soong_var('SOONG_HOST_OUT', target_release) + host_out = get_soong_var('HOST_OUT', target_release) # Call the class to package the outputs. # TODO(lucafarsi): Move this code into a replaceable class. @@ -267,12 +278,16 @@ def zip_build_outputs(modules_to_build: Set[Text], dist_dir: Text): zip_command.append('-o') zip_command.append(os.path.join(dist_dir, 'general-tests.zip')) - run_command(zip_command) + run_command(zip_command, print_output=True) + +def get_soong_var(var: str, target_release: str) -> str: + new_env = os.environ.copy() + new_env['TARGET_RELEASE'] = target_release -def get_soong_var(var: str) -> str: value = run_command( - ['./build/soong/soong_ui.bash', '--dumpvar-mode', '--abs', var] + ['./build/soong/soong_ui.bash', '--dumpvar-mode', '--abs', var], + env=new_env, ).strip() if not value: raise RuntimeError('Necessary soong variable ' + var + ' not found.') |