aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_defs/pkg/rpm.bzl
diff options
context:
space:
mode:
authorGravatar mmikitka <matt@mikitka.net>2018-03-12 10:49:22 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-12 10:51:57 -0700
commitc626a933473576a8593317021fbec12100dd5677 (patch)
treeb037a972b48313bd60f2e211860c59418755ab4f /tools/build_defs/pkg/rpm.bzl
parent5f8c94a8828d47347ea706d6f947c572d3f6a866 (diff)
Added release and release_file parameters to pkg_rpm
1. Added the "rpm_nvra" output which follows the recommended package naming convention of *Name-Version-Release.Arch.rpm* (NVRA). See http://ftp.rpm.org/max-rpm/ch-rpm-file-format.html 2. Expose "release" and "release_file" parameters to support the NVRA naming convention 3. Remove the mandatory constraint on version parameters (version or version_file): I want to auto-generate my SPEC file outside of the pkg_rpm rule, and I don't want pkg_rpm altering the file. Closes #4732. PiperOrigin-RevId: 188744806
Diffstat (limited to 'tools/build_defs/pkg/rpm.bzl')
-rw-r--r--tools/build_defs/pkg/rpm.bzl62
1 files changed, 53 insertions, 9 deletions
diff --git a/tools/build_defs/pkg/rpm.bzl b/tools/build_defs/pkg/rpm.bzl
index 948889bb82..51d8a246c8 100644
--- a/tools/build_defs/pkg/rpm.bzl
+++ b/tools/build_defs/pkg/rpm.bzl
@@ -23,7 +23,7 @@ def _pkg_rpm_impl(ctx):
files = []
args = ["--name=" + ctx.label.name]
- # Version can be specified by a file or inlined
+ # Version can be specified by a file or inlined.
if ctx.attr.version_file:
if ctx.attr.version:
fail("Both version and version_file attributes were specified")
@@ -31,8 +31,15 @@ def _pkg_rpm_impl(ctx):
files += [ctx.file.version_file]
elif ctx.attr.version:
args += ["--version=" + ctx.attr.version]
- else:
- fail("Neither version_file nor version attribute was specified")
+
+ # Release can be specified by a file or inlined.
+ if ctx.attr.release_file:
+ if ctx.attr.release:
+ fail("Both release and release_file attributes were specified")
+ args += ["--release=@" + ctx.file.release_file.path]
+ files += [ctx.file.release_file]
+ elif ctx.attr.release:
+ args += ["--release=" + ctx.attr.release]
if ctx.attr.architecture:
args += ["--arch=" + ctx.attr.architecture]
@@ -86,6 +93,32 @@ def _pkg_rpm_impl(ctx):
inputs = [ctx.outputs.rpm],
outputs = [ctx.outputs.out])
+ # Link the RPM to the RPM-recommended output name.
+ if "rpm_nvra" in dir(ctx.outputs):
+ ctx.actions.run(
+ executable = "ln",
+ arguments = [
+ "-s",
+ ctx.outputs.rpm.basename,
+ ctx.outputs.rpm_nvra.path,
+ ],
+ inputs = [ctx.outputs.rpm],
+ outputs = [ctx.outputs.rpm_nvra])
+
+def _pkg_rpm_outputs(version, release):
+ outputs = {
+ "out": "%{name}.rpm",
+ "rpm": "%{name}-%{architecture}.rpm",
+ }
+
+ # The "rpm_nvra" output follows the recommended package naming convention of
+ # Name-Version-Release.Arch.rpm
+ # See http://ftp.rpm.org/max-rpm/ch-rpm-file-format.html
+ if version and release:
+ outputs["rpm_nvra"] = "%{name}-%{version}-%{release}.%{architecture}.rpm"
+
+ return outputs
+
# Define the rule.
pkg_rpm = rule(
attrs = {
@@ -108,6 +141,8 @@ pkg_rpm = rule(
mandatory = True,
allow_files = True,
),
+ "release_file": attr.label(allow_files=True, single_file=True),
+ "release": attr.string(),
# Implicit dependencies.
"_make_rpm": attr.label(
@@ -118,10 +153,7 @@ pkg_rpm = rule(
),
},
executable = False,
- outputs = {
- "out": "%{name}.rpm",
- "rpm": "%{name}-%{architecture}.rpm",
- },
+ outputs = _pkg_rpm_outputs,
implementation = _pkg_rpm_impl,
)
@@ -130,10 +162,16 @@ pkg_rpm = rule(
This runs rpmbuild (and requires it to be installed beforehand) to generate
an RPM package based on the spec_file and data attributes.
+Two outputs are guaranteed to be produced: "%{name}.rpm", and
+"%{name}-%{architecture}.rpm". If the "version" and "release" arguments are
+non-empty, a third output will be produced, following the RPM-recommended
+N-V-R.A format (Name-Version-Release.Architecture.rpm).
+
Args:
spec_file: The RPM spec file to use. If the version or version_file
- attributes are provided, the Version in the spec will be overwritten.
- Any Sources listed in the spec file must be provided as data dependencies.
+ attributes are provided, the Version in the spec will be overwritten,
+ and likewise behaviour with release and release_file. Any Sources listed
+ in the spec file must be provided as data dependencies.
The base names of data dependencies can be replaced with the actual location
using "{basename}" syntax.
version: The version of the package to generate. This will overwrite any
@@ -142,6 +180,12 @@ Args:
version_file: A file containing the version of the package to generate. This
will overwrite any Version provided in the spec file. Only specify one of
version and version_file.
+ release: The release of the package to generate. This will overwrite any
+ release provided in the spec file. Only specify one of release and
+ release_file.
+ release_file: A file containing the release of the package to generate. This
+ will overwrite any release provided in the spec file. Only specify one of
+ release and release_file.
changelog: A changelog file to include. This will not be written to the spec
file, which should only list changes to the packaging, not the software itself.
data: List all files to be included in the package here.