Skip to content

refactor: route Bazel docs inputs through the CLI - #836

Merged
AlexanderLanin merged 8 commits into
eclipse-score:mainfrom
etas-contrib:refactor/sourcelinks-metamodel-env-vars
Sep 17, 2026
Merged

AlexanderLanin merged 8 commits into
eclipse-score:mainfrom
etas-contrib:refactor/sourcelinks-metamodel-env-vars

Conversation

@AlexanderLanin

@AlexanderLanin AlexanderLanin commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

  • route Bazel-provided documentation inputs through cli.py
  • resolve runfiles-relative paths before forwarding them as Sphinx defines
  • remove duplicate manifest and source-link path resolution from extensions
  • keep the Sphinx configuration boundary consistent for metamodel, sourcelinks, known-good data, and mounts
  • prepare the external-needs migration by centralizing its runfiles path construction without changing the current interface

The larger external_needs_source label-resolution migration remains outside this change.

Review note

The commits are intentionally ordered as incremental refactor steps. Please review them commit by commit, in order, rather than only as one combined diff.

…in the Needs build action

The sandboxed Needs build action received these three Bazel-generated
files as pre-formatted `--define=...` strings baked into
`SPHINX_EXTRA_OPTS`, while the interactive `bazel run` targets already
passed the metamodel and mounts manifest as plain environment
variables consumed by cli.py. Declare them as typed label attributes
on `sphinx_docs` instead, so the action can declare them as sandbox
inputs and expose their execroot paths through the same env vars
(`SCORE_SOURCELINKS`, `MOUNTS_MANIFEST`, `SCORE_METAMODEL_YAML`)
already used elsewhere, removing the duplicated per-caller
`$(location ...)` string formatting.
…nly in cli.py

Extensions read these Bazel-provided paths through two parallel
channels: a direct os.environ lookup and the app.config value cli.py
populates via --define. The env-var path bypassed cli.py's runfiles
resolution entirely, so it only worked by coincidence for values that
happened to already be cwd-relative.

Make cli.py the single place that resolves SCORE_SOURCELINKS (like it
already did for SCORE_METAMODEL_YAML, now shared through
_resolve_runfiles_relative_path) into a --define, and drop the
now-redundant direct env reads in score_source_code_linker,
score_mounts, and score_cross_module_compatibility. mounts_manifest's
env fallback was already dead code, since cli.py has unconditionally
defined it for every invocation; sourcelinks_json's was not, so
docs.bzl's interactive SCORE_SOURCELINKS now passes an rlocationpath
like its metamodel/mounts siblings, resolved correctly by cli.py
instead of read as a bare path by the extension.
cli.py is only ever invoked via `bazel run` or as the sandboxed Needs
action's executable (see src/docs_cli/README.md); ExecutionEnvironment.DIRECT
exists solely so DocsCliConfig/sphinx_arguments stay unit-testable without a
real runfiles tree. Assert this invariant right after building the config so
it's readable in the file instead of only discoverable by tracing callers.
app was optional and score_sourcelinks_json was read via getattr with a
fallback, but the only production caller (setup_combined_linker) always
passes a real app, and add_config_value guarantees the config value exists
before any event handler can call this function. Make app mandatory and
read the config value directly; update the one test that relied on the
app=None branch to pass an explicit fake config instead.
xml_parser.py read env.optional_path("KNOWN_GOOD_JSON") directly, bypassing
the app.config.KNOWN_GOOD_JSON value score_source_code_linker already
registers and cli.py already emits via --define. That define carried an
unresolved value, since cli.py never ran it through the runfiles resolution
used for SCORE_METAMODEL_YAML/SCORE_SOURCELINKS; it only worked because
docs.bzl passed $(location ...), which happens to be cwd-relative under
bazel run.

Resolve KNOWN_GOOD_JSON through the shared _resolve_runfiles_relative_path
helper like its siblings, switch docs.bzl to $(rlocationpath ...), and
thread the resolved path through xml_parser.py's call chain
(build_test_needs_from_files -> read_test_xml_file ->
get_metadata_from_test_path) instead of reading the env var deep inside a
plain parsing function that has no Sphinx app access.
@github-actions

Copy link
Copy Markdown
Contributor

Documentation preview for this pull request is available at:
pr-836: https://eclipse-score.github.io/docs-as-code/pr-836/

@a-zw a-zw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. It should ease the reasoning about the different invocations.

Comment thread src/docs_cli/cli.py
Comment on lines +209 to +210
# The sandboxed Needs action and ``bazel run`` both set this env var;
# only the extension reads ``app.config.score_sourcelinks_json``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me what "sandboxed Needs action" and "the extension" is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will improve in next PR

@AlexanderLanin
AlexanderLanin merged commit 8465de5 into eclipse-score:main Sep 17, 2026
20 checks passed
@AlexanderLanin
AlexanderLanin deleted the refactor/sourcelinks-metamodel-env-vars branch September 17, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants