From fd8f56da72f8230edbbd74a51f159743bbd9371b Mon Sep 17 00:00:00 2001 From: Alexander Lanin Date: Wed, 16 Sep 2026 16:18:28 +0200 Subject: [PATCH] refactor: use execpath in genrule commands --- docs.bzl | 10 ++++++++-- src/extensions/score_metamodel/docs/BUILD | 5 ++++- src/tests/docs_bzl/scenarios/data_files_runfiles/BUILD | 7 +++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs.bzl b/docs.bzl index fbf84aa50..dd07da615 100644 --- a/docs.bzl +++ b/docs.bzl @@ -711,7 +711,10 @@ def docs( name = "metrics_json", srcs = [":needs_json"], outs = ["metrics.json"], - cmd = "cp $(location :needs_json)/metrics.json $@", + # Copy metrics.json out of the directory produced by :needs_json. + # $(execpath ...) expands to that input directory's path for this build + # action, and $@ is the path of the metrics.json output created here. + cmd = "cp $(execpath :needs_json)/metrics.json $@", visibility = ["//visibility:public"], tags = ["manual"], ) @@ -722,7 +725,10 @@ def docs( name = "needs_json_file", srcs = [":needs_json"], outs = ["needs.json"], - cmd = "cp $(location :needs_json)/needs.json $@", + # Copy needs.json out of the directory produced by :needs_json. + # $(execpath ...) gives this build action the input directory's path; + # $@ is the path of the needs.json output created here. + cmd = "cp $(execpath :needs_json)/needs.json $@", visibility = ["//visibility:public"], tags = ["manual"], ) diff --git a/src/extensions/score_metamodel/docs/BUILD b/src/extensions/score_metamodel/docs/BUILD index f1e75b7af..7632873a5 100644 --- a/src/extensions/score_metamodel/docs/BUILD +++ b/src/extensions/score_metamodel/docs/BUILD @@ -24,7 +24,10 @@ genrule( "generated/index.rst", "generated/metamodel_classes.mmd", ], - cmd = "$(location :generate_metamodel_rst_bin) --rst-output $(location generated/index.rst) --mmd-output $(location generated/metamodel_classes.mmd) $(location //src/extensions/score_metamodel:metamodel_yaml)", + # Run the generator on the YAML input and tell it where to write the RST + # and Mermaid files. Bazel expands each $(execpath ...) to the named tool + # or file's path in this build action, so the command can find them. + cmd = "$(execpath :generate_metamodel_rst_bin) --rst-output $(execpath generated/index.rst) --mmd-output $(execpath generated/metamodel_classes.mmd) $(execpath //src/extensions/score_metamodel:metamodel_yaml)", tools = [":generate_metamodel_rst_bin"], visibility = ["//visibility:private"], ) diff --git a/src/tests/docs_bzl/scenarios/data_files_runfiles/BUILD b/src/tests/docs_bzl/scenarios/data_files_runfiles/BUILD index e9e5d12f4..b8f0e4cd4 100644 --- a/src/tests/docs_bzl/scenarios/data_files_runfiles/BUILD +++ b/src/tests/docs_bzl/scenarios/data_files_runfiles/BUILD @@ -32,14 +32,17 @@ genrule( # The RST and Mermaid file are both declared sources, but only the RST # should be registered as a Sphinx document. The Mermaid file is a # companion asset that must remain readable next to the original RST. - cmd = """cat > $(location generated/index.rst) <<'EOF' + # The shell writes the text below, up to each EOF marker, into the + # generated RST and Mermaid files. $(execpath ...) expands to each declared + # output's path in this build action, so the files land where Bazel expects. + cmd = """cat > $(execpath generated/index.rst) <<'EOF' Generated Data Page =================== .. mermaid:: generated_data.mmd :name: generated-data-diagram EOF -cat > $(location generated/generated_data.mmd) <<'EOF' +cat > $(execpath generated/generated_data.mmd) <<'EOF' classDiagram class GeneratedData EOF""",