Skip to content

bazel: take the doc build's Python from the toolchain, not the host - #11348

Merged
maliberty merged 2 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:bazel-hermetic-python-docs
Sep 7, 2026
Merged

bazel: take the doc build's Python from the toolchain, not the host#11348
maliberty merged 2 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:bazel-hermetic-python-docs

Conversation

@maliberty

Copy link
Copy Markdown
Member

//docs:man_pages shells out to docs/Makefile, whose preprocess step ran python3 off PATH. The action's environment is not the invoking shell's, so a newer interpreter earlier on the user's PATH does not necessarily reach it, and md_roff_compat.py needs Python >= 3.7 ('from future import annotations'). On distributions that still ship 3.6 as /usr/bin/python3 -- RHEL 8, for instance -- the build fails with "SyntaxError: future feature annotations is not defined".

Resolve @rules_python//python:toolchain_type in the man_pages rule and hand the interpreter to make as PYTHON, declaring the runtime's files as action inputs; the Makefile keeps python3 as its default so a non-Bazel make -C docs is unchanged. The same toolchain lookup already backs tcl_encode_or and the messages_txt genrules.

//:dup_id_test was the one remaining host-python user in the Bazel graph; give it the interpreter through PYTHON3_ROOTPATH for the same reason.

Fixes #11290

//docs:man_pages shells out to docs/Makefile, whose preprocess step ran
`python3` off PATH. The action's environment is not the invoking shell's,
so a newer interpreter earlier on the user's PATH does not necessarily
reach it, and md_roff_compat.py needs Python >= 3.7 ('from __future__
import annotations'). On distributions that still ship 3.6 as
/usr/bin/python3 -- RHEL 8, for instance -- the build fails with
"SyntaxError: future feature annotations is not defined".

Resolve @rules_python//python:toolchain_type in the man_pages rule and
hand the interpreter to make as PYTHON, declaring the runtime's files as
action inputs; the Makefile keeps `python3` as its default so a non-Bazel
`make -C docs` is unchanged. The same toolchain lookup already backs
tcl_encode_or and the messages_txt genrules.

//:dup_id_test was the one remaining host-python user in the Bazel graph;
give it the interpreter through PYTHON3_ROOTPATH for the same reason.

Fixes The-OpenROAD-Project#11290

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
@maliberty maliberty self-assigned this Sep 7, 2026
@github-actions github-actions Bot added the size/S label Sep 7, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the build and test scripts to use the Python interpreter resolved by the Bazel toolchain instead of relying on the host's Python installation, ensuring compatibility on systems with older host Python versions. Feedback was provided to resolve two issues: first, in etc/find_dup_ids.sh, hardcoding the _main workspace name and prepending the runfiles directory can break if the workspace is renamed or if PYTHON3_ROOTPATH is already absolute; second, in bazel/man_pages.bzl, py3_runtime.files can be None under certain toolchain configurations, which would cause a runtime error when constructing the depset if not checked.

Comment thread etc/find_dup_ids.sh
Comment thread bazel/man_pages.bzl
@maliberty

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-07T15:26:24.547804Z 2a671ac Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

PYTHON3_ROOTPATH is $(PYTHON3_ROOTPATH), which current_py_toolchain sets
from the runtime's short_path for a hermetic toolchain but from the
absolute interpreter_path for a platform one. Prefixing the runfiles
directory turned the second form into a nonexistent path.

Resolve it against the working directory instead, which for a test is the
runfiles root that short_path is relative to, and which realpath leaves an
absolute path alone in. That also drops the hardcoded _main repo name.

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 55fc2d287c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@oharboe

oharboe commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

😌

@maliberty
maliberty marked this pull request as ready for review September 7, 2026 15:22
@maliberty
maliberty requested a review from a team as a code owner September 7, 2026 15:22
@maliberty
maliberty merged commit 7683e0f into The-OpenROAD-Project:master Sep 7, 2026
20 checks passed
@maliberty
maliberty deleted the bazel-hermetic-python-docs branch September 7, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bazel: Build not hermetic with respect to python version

2 participants