-
Notifications
You must be signed in to change notification settings - Fork 867
bazel: build and package man pages as runfiles #9766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||||||
| # SPDX-License-Identifier: BSD-3-Clause | ||||||||||
| # Copyright (c) 2026, The OpenROAD Authors | ||||||||||
|
|
||||||||||
| """Bazel rule to generate man pages (cat/ and html/) from module READMEs. | ||||||||||
|
|
||||||||||
| Runs the existing docs Makefile to produce cat/ and html/ outputs. | ||||||||||
| Requires pandoc, nroff, and python3 (>= 3.10) on the system. | ||||||||||
| """ | ||||||||||
|
|
||||||||||
| def _man_pages_impl(ctx): | ||||||||||
| cat_dir = ctx.actions.declare_directory("cat") | ||||||||||
| html_dir = ctx.actions.declare_directory("html") | ||||||||||
|
|
||||||||||
| command = """ | ||||||||||
| set -euo pipefail | ||||||||||
|
|
||||||||||
| # Ensure homebrew tools (pandoc, python3 >= 3.10) are available on macOS | ||||||||||
| if [ -d /opt/homebrew/bin ]; then | ||||||||||
| export PATH="/opt/homebrew/bin:$PATH" | ||||||||||
| elif [ -d /usr/local/bin ]; then | ||||||||||
| export PATH="/usr/local/bin:$PATH" | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| cd docs | ||||||||||
|
|
||||||||||
| # Symlink module READMEs into md/man2/ | ||||||||||
| bash src/scripts/link_readmes.sh 2>/dev/null || true | ||||||||||
|
|
||||||||||
| # Run preprocessing | ||||||||||
| python3 src/scripts/md_roff_compat.py | ||||||||||
|
|
||||||||||
| # Generate cat and html pages via Makefile | ||||||||||
| make -f Makefile cat web | ||||||||||
|
|
||||||||||
| cd .. | ||||||||||
|
|
||||||||||
| # Copy outputs to declared Bazel directories | ||||||||||
| cp -r docs/cat/* {cat_out}/ | ||||||||||
| cp -r docs/html/* {html_out}/ | ||||||||||
|
Comment on lines
+38
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the
Suggested change
|
||||||||||
| """.format( | ||||||||||
| cat_out = cat_dir.path, | ||||||||||
| html_out = html_dir.path, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| ctx.actions.run_shell( | ||||||||||
| outputs = [cat_dir, html_dir], | ||||||||||
| inputs = ctx.files.docs_srcs + ctx.files.scripts + ctx.files.readmes + ctx.files.messages, | ||||||||||
| command = command, | ||||||||||
| mnemonic = "ManPages", | ||||||||||
| progress_message = "Generating man pages (cat + html)", | ||||||||||
| use_default_shell_env = True, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| return [DefaultInfo( | ||||||||||
| files = depset([cat_dir, html_dir]), | ||||||||||
| runfiles = ctx.runfiles(files = [cat_dir, html_dir]), | ||||||||||
| )] | ||||||||||
|
|
||||||||||
| man_pages = rule( | ||||||||||
| implementation = _man_pages_impl, | ||||||||||
| attrs = { | ||||||||||
| "docs_srcs": attr.label_list( | ||||||||||
| doc = "All source files under docs/ needed by the Makefile.", | ||||||||||
| allow_files = True, | ||||||||||
| ), | ||||||||||
| "messages": attr.label_list( | ||||||||||
| doc = "Module messages.txt files needed for man3 page generation.", | ||||||||||
| allow_files = [".txt"], | ||||||||||
| ), | ||||||||||
| "readmes": attr.label_list( | ||||||||||
| doc = "Module README.md files (src/*/README.md).", | ||||||||||
| allow_files = [".md"], | ||||||||||
| ), | ||||||||||
| "scripts": attr.label_list( | ||||||||||
| doc = "Python/shell scripts for man page generation.", | ||||||||||
| allow_files = True, | ||||||||||
| ), | ||||||||||
| }, | ||||||||||
| ) | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright (c) 2026, The OpenROAD Authors | ||
|
|
||
| load("//bazel:man_pages.bzl", "man_pages") | ||
|
|
||
| man_pages( | ||
| name = "man_pages", | ||
|
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This target is defined but never consumed by the Useful? React with 👍 / 👎.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This matches my experience, man in the application doesn't find anything |
||
| docs_srcs = [ | ||
| "Makefile", | ||
| ] + glob(["md/**/*.md"]), | ||
| messages = [ | ||
| "//src/ant:messages_txt", | ||
| "//src/cts:messages_txt", | ||
| "//src/dbSta:messages_txt", | ||
| "//src/dft:messages_txt", | ||
| "//src/dpl:messages_txt", | ||
| "//src/drt:messages_txt", | ||
| "//src/dst:messages_txt", | ||
| "//src/fin:messages_txt", | ||
| "//src/gpl:messages_txt", | ||
| "//src/grt:messages_txt", | ||
| "//src/ifp:messages_txt", | ||
| "//src/mpl:messages_txt", | ||
| "//src/odb:messages_txt", | ||
| "//src/pad:messages_txt", | ||
| "//src/par:messages_txt", | ||
| "//src/pdn:messages_txt", | ||
| "//src/ppl:messages_txt", | ||
| "//src/psm:messages_txt", | ||
| "//src/rcx:messages_txt", | ||
| "//src/rmp:messages_txt", | ||
| "//src/rsz:messages_txt", | ||
| "//src/stt:messages_txt", | ||
| "//src/tap:messages_txt", | ||
| "//src/upf:messages_txt", | ||
| "//src/utl:messages_txt", | ||
| ], | ||
| readmes = [ | ||
| "//src/ant:README.md", | ||
| "//src/cts:README.md", | ||
| "//src/dft:README.md", | ||
| "//src/dpl:README.md", | ||
| "//src/drt:README.md", | ||
| "//src/fin:README.md", | ||
| "//src/gpl:README.md", | ||
| "//src/grt:README.md", | ||
| "//src/gui:README.md", | ||
| "//src/ifp:README.md", | ||
| "//src/mpl:README.md", | ||
| "//src/odb:README.md", | ||
| "//src/pad:README.md", | ||
| "//src/par:README.md", | ||
| "//src/pdn:README.md", | ||
| "//src/ppl:README.md", | ||
| "//src/psm:README.md", | ||
| "//src/rcx:README.md", | ||
| "//src/rmp:README.md", | ||
| "//src/rsz:README.md", | ||
| "//src/stt:README.md", | ||
| "//src/tap:README.md", | ||
| "//src/upf:README.md", | ||
| "//src/utl:README.md", | ||
| ], | ||
| scripts = [ | ||
| "//docs/src/scripts:link_readmes.sh", | ||
| "//docs/src/scripts:md_roff_compat.py", | ||
| "//docs/src/scripts:manpage.py", | ||
| "//docs/src/scripts:extract_utils.py", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -710,6 +710,13 @@ std::string OpenRoad::getDocsPath() const | |
| return ""; | ||
| } | ||
|
|
||
| // Check Bazel runfiles layout first | ||
| const std::filesystem::path runfiles_docs | ||
| = std::filesystem::path(exe + ".runfiles") / "_main" / "docs"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (std::filesystem::exists(runfiles_docs)) { | ||
| return runfiles_docs; | ||
| } | ||
|
|
||
| std::filesystem::path path(exe); | ||
|
|
||
| // remove binary name | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Masking errors with
|| trueand redirecting stderr to/dev/nullcan lead to silent failures during the documentation generation process. If the script fails, the resulting man pages might be incomplete or incorrect. It is better to allow the script to fail the build so that issues can be identified and fixed.