feat: add stamp support for pkg_rpm Release tag (#1039)

* feat: add stamp support for pkg_rpm Release tag

Allow `{VARIABLE_NAME}` placeholders in the `release` attribute of
`pkg_rpm`. When `stamp = 1` (or `stamp = -1` with `--stamp`), workspace
status variables from volatile-status.txt are substituted at build time.

- Add `get_status_vars()` to `pkg/private/build_info.py`
- Add `--volatile_status_file` and `--stable_status_file` args to
  `make_rpm.py`; apply substitution in `RpmBuilder.__init__` via the
  new `stamp_vars` parameter
- Add `stamp` and `private_stamp_detect` attrs to the `pkg_rpm` rule;
  rename the rule to `_pkg_rpm_rule` and expose a `pkg_rpm` macro that
  injects `private_stamp_detect` via `select()`, matching the pattern
  used by `pkg_tar` and `pkg_zip`
- Avoid embedding template placeholders in the output filename when stamp
  is active

Fixes #1038

* clean up uses of str.strip() in build_info.py

We don't need to call it multiple times on the same line value, we can
just call it once and save it.

* Address PR #1039 review feedback

- Add docstring to get_status_vars() in build_info.py
- Use get_stamp_detect() from util.bzl instead of inline select()
  to match the pattern from PR #1035
- Expand release attr docstring to document stamp variable substitution
- Add stamped RPM example to examples/rpm/system_rpmbuild_pfg
8 files changed
tree: a1632e45169f6876cb981b2556e9470bd458f576
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. contrib/
  5. distro/
  6. doc_build/
  7. docs/
  8. examples/
  9. pkg/
  10. providers/
  11. tests/
  12. toolchains/
  13. .bazelignore
  14. .bazelrc
  15. .gitignore
  16. .pre-commit-config.yaml
  17. .typos.toml
  18. AUTHORS
  19. BUILD
  20. CHANGELOG.md
  21. CODEOWNERS
  22. CONTRIBUTING.md
  23. CONTRIBUTORS
  24. deps.bzl
  25. developers.md
  26. LICENSE
  27. mappings.bzl
  28. MODULE.bazel
  29. patching.md
  30. pkg.bzl
  31. README.md
  32. version.bzl
  33. WORKSPACE
  34. WORKSPACE.bzlmod
README.md

Bazel package building

Bazel rules for building tar, zip, deb, and rpm for packages.

For the latest version, see Releases (with WORKSPACE setup) / Documentation

Use rules-pkg-discuss@googlegroups.com for discussion.

CI: Build status

Basic rules

Package building rules

  • pkg - Rules for building packages of various types.
  • examples - Cookbook examples for using the rules.

As of Bazel 4.x, Bazel uses this rule set for packaging its distribution. Bazel still contains a limited version of pkg_tar but its feature set is frozen. Any new capabilities will be added here.

WORKSPACE setup

Sample, but see releases for the current release.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_pkg",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
        "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
    ],
    sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.

load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")

find_system_rpmbuild(
    name = "rules_pkg_rpmbuild",
    verbose = False,
)

MODULE.bazel setup

bazel_dep(name = "rules_pkg", version = "0.0.10")

To use pkg_rpm(), you must provide a copy of rpmbuild. You can use the system installed rpmbuild with this stanza.

find_rpm = use_extension("//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild_bzlmod")
use_repo(find_rpm, "rules_pkg_rpmbuild")
register_toolchains("@rules_pkg_rpmbuild//:all")

For developers

We hold an engineering status meeting on the first Monday of every month at 10am USA East coast time. Add to calendar / meeting notes