From a82cc6579f83e170722577764df8afae61cbc32b Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Wed, 29 Nov 2023 13:24:26 -0800 Subject: [PATCH] Don't use symlinks in genrules A change is being made to sbox so that symlinks aren't resolved before being copied into the sandbox. This requires that the targets of the symlinks are also added to the sandbox. In this case we can depend directly on the file that the symlink is pointing to instead of the symlink itself. Bug: 307824623 Test: m art-run-test-2263-method-trace-jit-expected-stdout with aosp/2850015 Change-Id: Ifd6e8f9a95bff5c91779a1751342ea9b78f54607 --- test/2263-method-trace-jit/Android.bp | 4 +-- test/utils/regen-test-files | 52 +++++++++++++++++++-------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/test/2263-method-trace-jit/Android.bp b/test/2263-method-trace-jit/Android.bp index 798d6dae02..06cabeb9c1 100644 --- a/test/2263-method-trace-jit/Android.bp +++ b/test/2263-method-trace-jit/Android.bp @@ -27,7 +27,7 @@ java_test { genrule { name: "art-run-test-2263-method-trace-jit-expected-stdout", out: ["art-run-test-2263-method-trace-jit-expected-stdout.txt"], - srcs: ["expected-stdout.txt"], + srcs: [":art-run-test-988-method-trace-expected-stdout"], cmd: "cp -f $(in) $(out)", } @@ -35,6 +35,6 @@ genrule { genrule { name: "art-run-test-2263-method-trace-jit-expected-stderr", out: ["art-run-test-2263-method-trace-jit-expected-stderr.txt"], - srcs: ["expected-stderr.txt"], + srcs: [":art-run-test-988-method-trace-expected-stderr"], cmd: "cp -f $(in) $(out)", } diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files index 3d2586bf64..31a35b1d99 100755 --- a/test/utils/regen-test-files +++ b/test/utils/regen-test-files @@ -567,23 +567,45 @@ class Generator: ":{run_test_module_name}-expected-stderr", ],{test_suites}{include_src} }} + """)) - // Test's expected standard output. - genrule {{ - name: "{run_test_module_name}-expected-stdout", - out: ["{run_test_module_name}-expected-stdout.txt"], - srcs: ["expected-stdout.txt"], - cmd: "cp -f $(in) $(out)", - }} + def add_expected_output_genrule(type_str): + type_str_long = "standard output" if type_str == "stdout" else "standard error" + in_file = os.path.join(run_test_path, f"expected-{type_str}.txt") + if os.path.islink(in_file): + # Genrules are sandboxed, so if we just added the symlink to the srcs list, it would + # be a dangling symlink in the sandbox. Instead, if we see a symlink, depend on the + # genrule from the test that the symlink is pointing to instead of the symlink itself. + link_target = os.readlink(in_file) + basename = os.path.basename(in_file) + match = re.fullmatch('\.\./([a-zA-Z0-9_-]+)/' + re.escape(basename), link_target) + if not match: + sys.exit(f"Error: expected symlink to be '../something/{basename}', got {link_target}") + f.write(textwrap.dedent(f"""\ + + // Test's expected {type_str_long}. + genrule {{ + name: "{run_test_module_name}-expected-{type_str}", + out: ["{run_test_module_name}-expected-{type_str}.txt"], + srcs: [":{ART_RUN_TEST_MODULE_NAME_PREFIX}{match.group(1)}-expected-{type_str}"], + cmd: "cp -f $(in) $(out)", + }} + """)) + else: + f.write(textwrap.dedent(f"""\ + + // Test's expected {type_str_long}. + genrule {{ + name: "{run_test_module_name}-expected-{type_str}", + out: ["{run_test_module_name}-expected-{type_str}.txt"], + srcs: ["expected-{type_str}.txt"], + cmd: "cp -f $(in) $(out)", + }} + """)) + + add_expected_output_genrule("stdout") + add_expected_output_genrule("stderr") - // Test's expected standard error. - genrule {{ - name: "{run_test_module_name}-expected-stderr", - out: ["{run_test_module_name}-expected-stderr.txt"], - srcs: ["expected-stderr.txt"], - cmd: "cp -f $(in) $(out)", - }} - """)) def regen_test_mapping_file(self, art_run_tests): """Regenerate ART's `TEST_MAPPING`."""