Skip to content

Commit 8c7c2cf

Browse files
authored
Overridable debuginfo type (#945)
This change enables the override of the auto-detected `/etc/os-release`-based `debuginfo_type` attribute of the `build_repo_for_rpmbuild_toolchain` repository rule and allows the auto-detection by means of a new `default` option. This also enables the use of` none` as an override option. This change also includes a regeneration of the documentation, which seems to have trailed recent code changes. But there are no documentation changes related to this change as `build_repo_for_rpmbuild_toolchain` repository rule is not documented (yet).
2 parents 4e6e82c + 5ba40b3 commit 8c7c2cf

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

docs/latest.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ load("@rules_pkg//pkg/private/deb:deb.bzl", "pkg_deb")
9595
pkg_deb(<a href="#pkg_deb-name">name</a>, <a href="#pkg_deb-data">data</a>, <a href="#pkg_deb-out">out</a>, <a href="#pkg_deb-architecture">architecture</a>, <a href="#pkg_deb-architecture_file">architecture_file</a>, <a href="#pkg_deb-breaks">breaks</a>, <a href="#pkg_deb-built_using">built_using</a>,
9696
<a href="#pkg_deb-built_using_file">built_using_file</a>, <a href="#pkg_deb-changelog">changelog</a>, <a href="#pkg_deb-conffiles">conffiles</a>, <a href="#pkg_deb-conffiles_file">conffiles_file</a>, <a href="#pkg_deb-config">config</a>, <a href="#pkg_deb-conflicts">conflicts</a>, <a href="#pkg_deb-depends">depends</a>,
9797
<a href="#pkg_deb-depends_file">depends_file</a>, <a href="#pkg_deb-description">description</a>, <a href="#pkg_deb-description_file">description_file</a>, <a href="#pkg_deb-distribution">distribution</a>, <a href="#pkg_deb-enhances">enhances</a>, <a href="#pkg_deb-homepage">homepage</a>, <a href="#pkg_deb-license">license</a>,
98-
<a href="#pkg_deb-maintainer">maintainer</a>, <a href="#pkg_deb-package">package</a>, <a href="#pkg_deb-package_file_name">package_file_name</a>, <a href="#pkg_deb-package_variables">package_variables</a>, <a href="#pkg_deb-postinst">postinst</a>, <a href="#pkg_deb-postrm">postrm</a>, <a href="#pkg_deb-predepends">predepends</a>,
99-
<a href="#pkg_deb-preinst">preinst</a>, <a href="#pkg_deb-prerm">prerm</a>, <a href="#pkg_deb-priority">priority</a>, <a href="#pkg_deb-provides">provides</a>, <a href="#pkg_deb-recommends">recommends</a>, <a href="#pkg_deb-replaces">replaces</a>, <a href="#pkg_deb-section">section</a>, <a href="#pkg_deb-suggests">suggests</a>, <a href="#pkg_deb-templates">templates</a>,
100-
<a href="#pkg_deb-triggers">triggers</a>, <a href="#pkg_deb-urgency">urgency</a>, <a href="#pkg_deb-version">version</a>, <a href="#pkg_deb-version_file">version_file</a>)
98+
<a href="#pkg_deb-maintainer">maintainer</a>, <a href="#pkg_deb-md5sums">md5sums</a>, <a href="#pkg_deb-package">package</a>, <a href="#pkg_deb-package_file_name">package_file_name</a>, <a href="#pkg_deb-package_variables">package_variables</a>, <a href="#pkg_deb-postinst">postinst</a>, <a href="#pkg_deb-postrm">postrm</a>,
99+
<a href="#pkg_deb-predepends">predepends</a>, <a href="#pkg_deb-preinst">preinst</a>, <a href="#pkg_deb-prerm">prerm</a>, <a href="#pkg_deb-priority">priority</a>, <a href="#pkg_deb-provides">provides</a>, <a href="#pkg_deb-recommends">recommends</a>, <a href="#pkg_deb-replaces">replaces</a>, <a href="#pkg_deb-section">section</a>, <a href="#pkg_deb-suggests">suggests</a>,
100+
<a href="#pkg_deb-templates">templates</a>, <a href="#pkg_deb-triggers">triggers</a>, <a href="#pkg_deb-urgency">urgency</a>, <a href="#pkg_deb-version">version</a>, <a href="#pkg_deb-version_file">version_file</a>)
101101
</pre>
102102

103103
Create a Debian package.
@@ -138,6 +138,7 @@ include both. If you need downstream rule to specifically depend on only the .de
138138
| <a id="pkg_deb-homepage"></a>homepage | The homepage of the project. | String | optional | `""` |
139139
| <a id="pkg_deb-license"></a>license | The license of the project. | String | optional | `""` |
140140
| <a id="pkg_deb-maintainer"></a>maintainer | The maintainer of the package. | String | required | |
141+
| <a id="pkg_deb-md5sums"></a>md5sums | A file listing md5 checksums of files in the data archive. This file is optional. See https://manpages.debian.org/bookworm/dpkg-dev/deb-md5sums.5.en.html. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
141142
| <a id="pkg_deb-package"></a>package | The name of the package | String | required | |
142143
| <a id="pkg_deb-package_file_name"></a>package_file_name | See [Common Attributes](#package_file_name). Default: "{package}-{version}-{architecture}.deb | String | optional | `""` |
143144
| <a id="pkg_deb-package_variables"></a>package_variables | See [Common Attributes](#package_variables) | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
@@ -234,7 +235,7 @@ find_system_rpmbuild(name="rules_pkg_rpmbuild")
234235
<pre>
235236
load("@rules_pkg//pkg:rpm_pfg.bzl", "pkg_rpm")
236237

237-
pkg_rpm(<a href="#pkg_rpm-name">name</a>, <a href="#pkg_rpm-srcs">srcs</a>, <a href="#pkg_rpm-architecture">architecture</a>, <a href="#pkg_rpm-binary_payload_compression">binary_payload_compression</a>, <a href="#pkg_rpm-changelog">changelog</a>, <a href="#pkg_rpm-conflicts">conflicts</a>, <a href="#pkg_rpm-debug">debug</a>,
238+
pkg_rpm(<a href="#pkg_rpm-name">name</a>, <a href="#pkg_rpm-srcs">srcs</a>, <a href="#pkg_rpm-data">data</a>, <a href="#pkg_rpm-architecture">architecture</a>, <a href="#pkg_rpm-binary_payload_compression">binary_payload_compression</a>, <a href="#pkg_rpm-changelog">changelog</a>, <a href="#pkg_rpm-conflicts">conflicts</a>, <a href="#pkg_rpm-debug">debug</a>,
238239
<a href="#pkg_rpm-debuginfo">debuginfo</a>, <a href="#pkg_rpm-defines">defines</a>, <a href="#pkg_rpm-description">description</a>, <a href="#pkg_rpm-description_file">description_file</a>, <a href="#pkg_rpm-epoch">epoch</a>, <a href="#pkg_rpm-group">group</a>, <a href="#pkg_rpm-license">license</a>, <a href="#pkg_rpm-obsoletes">obsoletes</a>,
239240
<a href="#pkg_rpm-package_file_name">package_file_name</a>, <a href="#pkg_rpm-package_name">package_name</a>, <a href="#pkg_rpm-package_variables">package_variables</a>, <a href="#pkg_rpm-post_scriptlet">post_scriptlet</a>, <a href="#pkg_rpm-post_scriptlet_file">post_scriptlet_file</a>,
240241
<a href="#pkg_rpm-posttrans_scriptlet">posttrans_scriptlet</a>, <a href="#pkg_rpm-posttrans_scriptlet_file">posttrans_scriptlet_file</a>, <a href="#pkg_rpm-postun_scriptlet">postun_scriptlet</a>, <a href="#pkg_rpm-postun_scriptlet_file">postun_scriptlet_file</a>,
@@ -287,6 +288,7 @@ include both. If you need downstream rule to specifically depend on only the .rp
287288
| :------------- | :------------- | :------------- | :------------- | :------------- |
288289
| <a id="pkg_rpm-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
289290
| <a id="pkg_rpm-srcs"></a>srcs | Mapping groups to include in this RPM.<br><br>These are typically brought into life as `pkg_filegroup`s. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
291+
| <a id="pkg_rpm-data"></a>data | Extra files that are needed by rpmbuild or find-debuginfo | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
290292
| <a id="pkg_rpm-architecture"></a>architecture | Package architecture.<br><br>This currently sets the `BuildArch` tag, which influences the output architecture of the package.<br><br>Typically, `BuildArch` only needs to be set when the package is known to be cross-platform (e.g. written in an interpreted language), or, less common, when it is known that the application is only valid for specific architectures.<br><br>When no attribute is provided, this will default to your host's architecture. This is usually what you want. | String | optional | `""` |
291293
| <a id="pkg_rpm-binary_payload_compression"></a>binary_payload_compression | Compression mode used for this RPM<br><br>Must be a form that `rpmbuild(8)` knows how to process, which will depend on the version of `rpmbuild` in use. The value corresponds to the `%_binary_payload` macro and is set on the `rpmbuild(8)` command line if provided.<br><br>Some examples of valid values (which may not be supported on your system) can be found [here](https://git.io/JU9Wg). On CentOS systems (also likely Red Hat and Fedora), you can find some supported values by looking for `%_binary_payload` in `/usr/lib/rpm/macros`. Other systems have similar files and configurations.<br><br>If not provided, the compression mode will be computed by `rpmbuild` itself. Defaults may vary per distribution or build of `rpm`; consult the relevant documentation for more details.<br><br>WARNING: Bazel is currently not aware of action threading requirements for non-test actions. Using threaded compression may result in overcommitting your system. | String | optional | `""` |
292294
| <a id="pkg_rpm-changelog"></a>changelog | - | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
@@ -345,8 +347,8 @@ pkg_tar(<a href="#pkg_tar-name">name</a>, <a href="#pkg_tar-deps">deps</a>, <a h
345347
<a href="#pkg_tar-allow_duplicates_with_different_content">allow_duplicates_with_different_content</a>, <a href="#pkg_tar-compression_level">compression_level</a>, <a href="#pkg_tar-compressor">compressor</a>, <a href="#pkg_tar-compressor_args">compressor_args</a>,
346348
<a href="#pkg_tar-create_parents">create_parents</a>, <a href="#pkg_tar-empty_dirs">empty_dirs</a>, <a href="#pkg_tar-empty_files">empty_files</a>, <a href="#pkg_tar-extension">extension</a>, <a href="#pkg_tar-files">files</a>, <a href="#pkg_tar-include_runfiles">include_runfiles</a>, <a href="#pkg_tar-mode">mode</a>, <a href="#pkg_tar-modes">modes</a>,
347349
<a href="#pkg_tar-mtime">mtime</a>, <a href="#pkg_tar-owner">owner</a>, <a href="#pkg_tar-ownername">ownername</a>, <a href="#pkg_tar-ownernames">ownernames</a>, <a href="#pkg_tar-owners">owners</a>, <a href="#pkg_tar-package_dir">package_dir</a>, <a href="#pkg_tar-package_dir_file">package_dir_file</a>,
348-
<a href="#pkg_tar-package_file_name">package_file_name</a>, <a href="#pkg_tar-package_variables">package_variables</a>, <a href="#pkg_tar-portable_mtime">portable_mtime</a>, <a href="#pkg_tar-private_stamp_detect">private_stamp_detect</a>, <a href="#pkg_tar-remap_paths">remap_paths</a>,
349-
<a href="#pkg_tar-stamp">stamp</a>, <a href="#pkg_tar-strip_prefix">strip_prefix</a>, <a href="#pkg_tar-symlinks">symlinks</a>)
350+
<a href="#pkg_tar-package_file_name">package_file_name</a>, <a href="#pkg_tar-package_variables">package_variables</a>, <a href="#pkg_tar-portable_mtime">portable_mtime</a>, <a href="#pkg_tar-preserve_mode">preserve_mode</a>,
351+
<a href="#pkg_tar-private_stamp_detect">private_stamp_detect</a>, <a href="#pkg_tar-remap_paths">remap_paths</a>, <a href="#pkg_tar-stamp">stamp</a>, <a href="#pkg_tar-strip_prefix">strip_prefix</a>, <a href="#pkg_tar-symlinks">symlinks</a>)
350352
</pre>
351353

352354

@@ -383,6 +385,7 @@ pkg_tar(<a href="#pkg_tar-name">name</a>, <a href="#pkg_tar-deps">deps</a>, <a h
383385
| <a id="pkg_tar-package_file_name"></a>package_file_name | See [Common Attributes](#package_file_name) | String | optional | `""` |
384386
| <a id="pkg_tar-package_variables"></a>package_variables | See [Common Attributes](#package_variables) | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
385387
| <a id="pkg_tar-portable_mtime"></a>portable_mtime | - | Boolean | optional | `True` |
388+
| <a id="pkg_tar-preserve_mode"></a>preserve_mode | If true, will add file to archive with preserved file permissions. | Boolean | optional | `False` |
386389
| <a id="pkg_tar-private_stamp_detect"></a>private_stamp_detect | - | Boolean | optional | `False` |
387390
| <a id="pkg_tar-remap_paths"></a>remap_paths | - | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
388391
| <a id="pkg_tar-stamp"></a>stamp | Enable file time stamping. Possible values: <li>stamp = 1: Use the time of the build as the modification time of each file in the archive. <li>stamp = 0: Use an "epoch" time for the modification time of each file. This gives good build result caching. <li>stamp = -1: Control the chosen modification time using the --[no]stamp flag. <div class="since"><i>Since 0.5.0</i></div> | Integer | optional | `0` |

pkg/rpm_pfg.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ find_system_rpmbuild(name="rules_pkg_rpmbuild")
2525
```
2626
"""
2727

28-
load(
29-
"@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl",
30-
"DEBUGINFO_TYPE_FEDORA",
31-
"DEBUGINFO_TYPE_NONE",
32-
)
3328
load(
3429
"//pkg:providers.bzl",
3530
"PackageDirsInfo",
@@ -39,6 +34,11 @@ load(
3934
"PackageVariablesInfo",
4035
)
4136
load("//pkg/private:util.bzl", "setup_output_files", "substitute_package_variables")
37+
load(
38+
"//toolchains/rpm:rpmbuild_configure.bzl",
39+
"DEBUGINFO_TYPE_FEDORA",
40+
"DEBUGINFO_TYPE_NONE",
41+
)
4242

4343
rpm_filetype = [".rpm"]
4444

toolchains/rpm/rpmbuild_configure.bzl

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def _parse_release_info(release_info):
5757

5858
return os_name, os_version
5959

60+
DEBUGINFO_TYPE_AUTODETECT = "default"
61+
62+
# The below are also defined in `pkg/make_rpm.py`
6063
DEBUGINFO_TYPE_NONE = "none"
6164
DEBUGINFO_TYPE_CENTOS = "centos"
6265
DEBUGINFO_TYPE_FEDORA = "fedora"
@@ -67,11 +70,25 @@ DEBUGINFO_TYPE_BY_OS_RELEASE = {
6770
"fedora": DEBUGINFO_TYPE_FEDORA,
6871
}
6972

73+
DEBUGINFO_VALID_VALUES = [
74+
DEBUGINFO_TYPE_FEDORA,
75+
DEBUGINFO_TYPE_CENTOS,
76+
DEBUGINFO_TYPE_NONE,
77+
DEBUGINFO_TYPE_AUTODETECT,
78+
]
79+
7080
def _build_repo_for_rpmbuild_toolchain_impl(rctx):
71-
debuginfo_type = DEBUGINFO_TYPE_NONE
72-
if rctx.path(RELEASE_PATH).exists:
73-
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
74-
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
81+
if rctx.attr.debuginfo_type not in DEBUGINFO_VALID_VALUES:
82+
fail("debuginfo_type must be one of", DEBUGINFO_VALID_VALUES)
83+
84+
debuginfo_type = rctx.attr.debuginfo_type
85+
if debuginfo_type == DEBUGINFO_TYPE_AUTODETECT:
86+
if rctx.path(RELEASE_PATH).exists:
87+
rctx.watch(RELEASE_PATH)
88+
os_name, _ = _parse_release_info(rctx.read(RELEASE_PATH))
89+
debuginfo_type = DEBUGINFO_TYPE_BY_OS_RELEASE.get(os_name, debuginfo_type)
90+
else:
91+
debuginfo_type = DEBUGINFO_TYPE_NONE
7592

7693
rpmbuild_path = rctx.which("rpmbuild")
7794
if rctx.attr.verbose:
@@ -80,9 +97,6 @@ def _build_repo_for_rpmbuild_toolchain_impl(rctx):
8097
else:
8198
print("No system rpmbuild found.") # buildifier: disable=print
8299

83-
if rctx.attr.debuginfo_type not in ["centos7", "fedora40", "none"]:
84-
fail("debuginfo_type must be one of centos7, fedora40, or none")
85-
86100
version = "unknown"
87101
if rpmbuild_path:
88102
res = rctx.execute([rpmbuild_path, "--version"])
@@ -112,9 +126,9 @@ build_repo_for_rpmbuild_toolchain = repository_rule(
112126
doc = """
113127
The underlying debuginfo configuration for the system rpmbuild.
114128
115-
One of `centos`, `fedora`, and `none`
129+
One of `centos`, `fedora`, `none`, and `default` (which looks up `/etc/os-release`)
116130
""",
117-
default = "none",
131+
default = DEBUGINFO_TYPE_AUTODETECT,
118132
),
119133
},
120134
)

0 commit comments

Comments
 (0)