Skip to content

Commit

Permalink
Don't use symlinks in genrules
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Colecf authored and Treehugger Robot committed Nov 30, 2023
1 parent d77d7be commit a82cc65
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
4 changes: 2 additions & 2 deletions test/2263-method-trace-jit/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ 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)",
}

// Test's expected standard error.
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)",
}
52 changes: 37 additions & 15 deletions test/utils/regen-test-files
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""
Expand Down

0 comments on commit a82cc65

Please sign in to comment.