#9 Add examples for the %autorel macro
Merged 4 years ago by nphilipp. Opened 4 years ago by nphilipp.
fedora-infra/ nphilipp/rpmautospec master--autorel-macro-docs  into  master

@@ -0,0 +1,40 @@ 

+ # RPM Macro Examples

+ 

+ These files demonstrate how the `%autorel` macro looks like and can be used in a local environment

+ or the build system.

+ 

+ ## The Macro Itself

+ 

+ The `%autorel` macro takes a couple of parameters to allow the user to specify different portions of

+ the release field, as described in the [Versioning

+ Guidelines](https://docs.fedoraproject.org/en-US/packaging-guidelines/Versioning/#_more_complex_versioning):

+ 

+ * `-h`, "hotfix": Designates a hotfix release, i.e. enables bumping the `minorbump` portion in order

+   to not overrun EVRs in later Fedora versions.

+ * `-p`, "prerelease": Designates a pre-release, i.e. the left-most digit of `pkgrel` will be `0`.

+ * `-e <extraver>`: Allows specifying the `extraver` portion of the release.

+ * `-s <snapinfo>`: Allows specifying the `snapinfo` portion of the release.

+ 

+ ## Local Use Case

+ 

+ The file `macros.autorel` would make the macro available if placed into `/usr/lib/rpm/macros.d`. It

+ also contains default values so a user can run plain RPM commands on the spec file.

+ 

+ To try it out, run:

+ 

+     rpm --load macros.autorel --specfile test-autorel.spec

+ 

+ ## Build System Use Case

+ 

+ The file `autorel-function-hdr.txt` contains the definition block as it would be pasted on top of

+ the spec file during the buildSRPMFromSCM Koji task. At the top, it contains the results of the

+ release value as calculated by `rpmautospec.release`, for the different use cases and with RPM

+ macros as placeholders for portions of the release field which the algorithm doesn't (need to) know

+ about. This is followed by the `%autorel` macro as it is defined at build time, overriding anything

+ from `macros.autorel` above to ensure repeatable builds of the resulting SRPM.

+ 

+ To test, concatenate the header blurb and any of the `test-autorel*.spec` files and run rpm on the

+ resulting spec file, like this:

+ 

+     cat autorel-function-hdr.txt test-autorel.spec > foo.spec

+     rpm --specfile foo.spec

@@ -0,0 +1,48 @@ 

+ ## START: Set by rpmautospec

+ %define _autorel_normal_cadence 2%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}

+ %define _autorel_hotfix_cadence 1%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}.1

+ %define _autorel_prerel_cadence 0.2%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}

+ %define _autorel_prerel_hotfix_cadence 0.1%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}.1

+ ## END: Set by rpmautospec

+ 

+ ## START: Automatic release macro

+ %define autorel(e:s:hp) %{lua:

+   has_extraver = rpm.expand("%{-e}") ~= ""

+   has_snapinfo = rpm.expand("%{-s}") ~= ""

+   is_prerelease = rpm.expand("%{-p}") ~= ""

+   is_hotfix = rpm.expand("%{-h}") ~= ""

+ 

+   if has_extraver

+   then

+     rpm.define("_autorel_extraver .%{-e*}")

+   else

+     rpm.define("_autorel_extraver %{nil}")

+   end

+ 

+   if has_snapinfo

+   then

+     rpm.define("_autorel_snapinfo .%{-s*}")

+   else

+     rpm.define("_autorel_snapinfo %{nil}")

+   end

+     

+   if is_prerelease

+   then

+     if is_hotfix

+     then

+       option = "prerel_hotfix_cadence"

+     else

+       option = "prerel_cadence"

+     end

+   else

+     if is_hotfix

+     then

+       option = "hotfix_cadence"

+     else

+       option = "normal_cadence"

+     end

+   end

+ 

+   print(rpm.expand("%_autorel_" .. option))

+ }

+ ## END: Automatic release macro

@@ -0,0 +1,42 @@ 

+ ## Defaults, to have something in place for plain rpmbuild etc.

+ %_autorel_normal_cadence 1%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}

+ %_autorel_hotfix_cadence 1%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}.1

+ %_autorel_prerel_cadence 0.1%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}

+ %_autorel_prerel_hotfix_cadence 0.1%{?_autorel_extraver}%{?_autorel_snapinfo}%{?dist}.1

+ 

+ # The macro itself

+ %autorel(e:s:hp) %{lua:

+   has_extraver = rpm.expand("%{-e}") ~= ""

+   has_snapinfo = rpm.expand("%{-s}") ~= ""

+   is_prerelease = rpm.expand("%{-p}") ~= ""

+   is_hotfix = rpm.expand("%{-h}") ~= ""

+   if has_extraver

+   then

+     rpm.define("_autorel_extraver .%{-e*}")

+   else

+     rpm.define("_autorel_extraver %{nil}")

+   end

+   if has_snapinfo

+   then

+     rpm.define("_autorel_snapinfo .%{-s*}")

+   else

+     rpm.define("_autorel_snapinfo %{nil}")

+   end

+   if is_prerelease

+   then

+     if is_hotfix

+     then

+       option = "prerel_hotfix_cadence"

+     else

+       option = "prerel_cadence"

+     end

+   else

+     if is_hotfix

+     then

+       option = "hotfix_cadence"

+     else

+       option = "normal_cadence"

+     end

+   end

+   print(rpm.expand("%_autorel_" .. option))

+ }

@@ -0,0 +1,10 @@ 

+ Summary:    test-autorel-extraver-snapshot

+ Name:       test-autorel-extraver-snapshot

+ Version:    1.0

+ Release:    %autorel -e pre1 -s 20200317git1234abcd

+ License:    CC0

+ 

+ %description

+ A dummy package testing the %%autorel macro. This package is for testing with

+ <extraver> and <snapinfo> parts, when upstream uses unsortable versions like

+ "1.0pre1" and we package a snapshot after it.

@@ -0,0 +1,9 @@ 

+ Summary:    test-autorel-extraver

+ Name:       test-autorel-extraver

+ Version:    1.0

+ Release:    %autorel -e pre1

+ License:    CC0

+ 

+ %description

+ A dummy package testing the %%autorel macro. This package is for testing with

+ an <extraver> part, when upstream uses unsortable versions like "1.0pre1".

@@ -0,0 +1,9 @@ 

+ Summary:    test-autorel-hotfix

+ Name:       test-autorel-hotfix

+ Version:    1.0

+ Release:    %autorel -h

+ License:    CC0

+ 

+ %description

+ A dummy package testing the %%autorel macro. This package is for testing the release cadence for

+ hotfixes, bumping in the right-most, least significant place of the release field.

@@ -0,0 +1,46 @@ 

+ # This spec file uses different Release fields for the sub packages. Don't do

+ # this in your packages.

+ 

+ Summary:    test-autorel

+ Name:       test-autorel

+ Version:    1.0

+ Release:    %autorel

+ License:    CC0

+ 

+ %description

+ A dummy package testing the %%autorel macro. This package is for testing the

+ normal release cadence, bumping in the left-most, most significant place of

+ the release field.

+ 

+ %package snapshot

+ Summary:    test-autorel-snapshot

+ Release:    %autorel -s 20200317git1234abcd

+ 

+ %description snapshot

+ A dummy package testing the %%autorel macro. This package is for testing with

+ a <snapinfo> part, for a snapshot between versions from an upstream repository.

+ 

+ %package extraver

+ Summary:    test-autorel-extraver

+ Release:    %autorel -e update1

+ 

+ %description extraver

+ A dummy package testing the %%autorel macro. This package is for testing with

+ an <extraver> part, when upstream uses unsortable versions like "1.0update1".

+ 

+ %package hotfix

+ Summary:    test-autorel-hotfix

+ Release:    %autorel -h

+ 

+ %description hotfix

+ A dummy package testing the %%autorel macro. This package is for testing the release cadence for

+ hotfixes, bumping in the right-most, least significant place of the release field.

+ 

+ %package prerelease

+ Summary:    test-autorel-prerelease

+ Release:    %autorel -p -e pre1

+ 

+ %description prerelease

+ A dummy package testing the %%autorel macro. This package is for testing a

+ prerelease with an <extraver> part, when upstream uses unsortable versions

+ like "1.0pre1".

@@ -0,0 +1,10 @@ 

+ Summary:    test-autorel-prerelease

+ Name:       test-autorel-prerelease

+ Version:    1.0

+ Release:    %autorel -p -e pre1

+ License:    CC0

+ 

+ %description

+ A dummy package testing the %%autorel macro. This package is for testing a

+ prerelease with an <extraver> part, when upstream uses unsortable versions

+ like "1.0pre1".

@@ -0,0 +1,9 @@ 

+ Summary:    test-autorel-snapshot

+ Name:       test-autorel-snapshot

+ Version:    1.0

+ Release:    %autorel -s 20200317git1234abcd

+ License:    CC0

+ 

+ %description

+ A dummy package testing the %%autorel macro. This package is for testing with

+ a <snapinfo> part, for a snapshot between versions from an upstream repository.

@@ -0,0 +1,10 @@ 

+ Summary:    test-autorel

+ Name:       test-autorel

+ Version:    1.0

+ Release:    %autorel

+ License:    CC0

+ 

+ %description

+ A dummy package testing the %%autorel macro. This package is for testing the

+ normal release cadence, bumping in the left-most, most significant place of

+ the release field.

WIP: Add a couple smaller spec files for the different use cases.

Build succeeded.

rebased onto 54675858db5708944cf6cdbff89e0b92fe361a99

4 years ago

Build succeeded.

rebased onto a16ea0574336160cc7b8496faf1cfa7511851eeb

4 years ago

Build succeeded.

rebased onto 8cbca5bbd910ade7c33637001147b1c40e4fa3c6

4 years ago

rebased onto 0dd9adf9784109f43e6f9d44c41fc3bb556c3475

4 years ago

Build succeeded.

Two nit picks:
1) I kinda like when the values are aligned :]
2) I wonder if for each of these example, we should add a comment of what the output will/should look like (with assumptions of course)

rebased onto e395145

4 years ago

Build succeeded.

Tested locally with rpm --load... it works great :)

:thumbsup: for me

Pull-Request has been merged by nphilipp

4 years ago