diff options
author | mmikitka <matt@mikitka.net> | 2018-03-12 10:49:22 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-12 10:51:57 -0700 |
commit | c626a933473576a8593317021fbec12100dd5677 (patch) | |
tree | b037a972b48313bd60f2e211860c59418755ab4f /tools | |
parent | 5f8c94a8828d47347ea706d6f947c572d3f6a866 (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')
-rw-r--r-- | tools/build_defs/pkg/make_rpm.py | 9 | ||||
-rw-r--r-- | tools/build_defs/pkg/make_rpm_test.py | 2 | ||||
-rw-r--r-- | tools/build_defs/pkg/rpm.bzl | 62 |
3 files changed, 61 insertions, 12 deletions
diff --git a/tools/build_defs/pkg/make_rpm.py b/tools/build_defs/pkg/make_rpm.py index fd4caeee62..12c19863b8 100644 --- a/tools/build_defs/pkg/make_rpm.py +++ b/tools/build_defs/pkg/make_rpm.py @@ -32,6 +32,8 @@ from third_party.py import gflags gflags.DEFINE_string('name', '', 'The name of the software being packaged.') gflags.DEFINE_string('version', '', 'The version of the software being packaged.') +gflags.DEFINE_string('release', '', + 'The release of the software being packaged.') gflags.DEFINE_string('arch', '', 'The CPU architecture of the software being packaged.') @@ -160,9 +162,10 @@ class RpmBuilder(object): TEMP_DIR = 'TMP' DIRS = [SOURCE_DIR, BUILD_DIR, TEMP_DIR] - def __init__(self, name, version, arch): + def __init__(self, name, version, release, arch): self.name = name self.version = GetFlagValue(version) + self.release = GetFlagValue(release) self.arch = arch self.files = [] self.rpmbuild_path = FindRpmbuild() @@ -193,6 +196,8 @@ class RpmBuilder(object): replacements = {} if self.version: replacements['Version:'] = self.version + if self.release: + replacements['Release:'] = self.release CopyAndRewrite(spec_origin, self.spec_file, replacements) def CallRpmBuild(self, dirname): @@ -247,7 +252,7 @@ class RpmBuilder(object): def main(argv=()): try: - builder = RpmBuilder(FLAGS.name, FLAGS.version, FLAGS.arch) + builder = RpmBuilder(FLAGS.name, FLAGS.version, FLAGS.release, FLAGS.arch) builder.AddFiles(argv[1:]) return builder.Build(FLAGS.spec_file, FLAGS.out_file) except NoRpmbuildFound: diff --git a/tools/build_defs/pkg/make_rpm_test.py b/tools/build_defs/pkg/make_rpm_test.py index c384735949..53d2c8aa43 100644 --- a/tools/build_defs/pkg/make_rpm_test.py +++ b/tools/build_defs/pkg/make_rpm_test.py @@ -121,7 +121,7 @@ class MakeRpmTest(unittest.TestCase): with PrependPath([outer]): # Create the builder and exercise it. - builder = make_rpm.RpmBuilder('test', '1.0', 'x86') + builder = make_rpm.RpmBuilder('test', '1.0', '0', 'x86') # Create spec_file, test files. WriteFile('test.spec', 'Name: test', 'Version: 0.1', 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. |