#211 macros: add new distribution-specific macros for package configurations
Closed 5 months ago by amitshah. Opened 5 months ago by amitshah.
rpms/ amitshah/redhat-rpm-config distro-macros  into  rawhide

file added
+50
@@ -0,0 +1,50 @@ 

+ # Distribution-specific macros

+ 

+ # Name of the vendor or distribution. Typically used to identify where

+ # the binary comes from in --help or --version messages of programs.

+ # Examples: gdb.spec, clang.spec

+ 

+ %distro_vendor %{lua:

+ local vendor = 'Fedora'

+ if macros.rhel then

+ 	vendor = 'Red Hat'

+ end

+ if macros.amzn then

+ 	vendor = 'Amazon Linux'

+ end

+ return vendor

+ }

+ 

+ %distro_name %{lua:

+ local name = 'Fedora'

+ if macros.rhel then

+ 	name = 'Red Hat Enterprise Linux'

+ end

+ if macros.amzn then

+ 	name = 'Amazon Linux'

+ end

+ return name

+ }

+ 

+ # URLs used to output upstream / source of distribution.

+ # Example: gstreamer1-plugins-base.spec

+ %distro_url %{lua:

+ local url = 'https://download.fedoraproject.org'

+ if macros.rhel then

+ 	url = 'https://redhat.com'

+ end

+ if macros.amzn then

+ 	url = 'https://aws.amazon.com/linux'

+ end

+ return url

+ }

+ 

+ # Bugzilla / bug reporting URLs shown to users.

+ # Examples: gcc.spec

+ %distro_url_bugs %{lua:

+ local url_bugs = 'https://bugzilla.redhat.com'

+ if macros.amzn then

+ 	url_bugs = 'https://github.com/amazonlinux'

+ end

+ return url_bugs

+ }

file modified
+3 -1
@@ -9,7 +9,7 @@ 

  Summary: Red Hat specific rpm configuration files

  Name: redhat-rpm-config

  Version: %{baserelease}

- Release: 1%{?dist}

+ Release: 2%{?dist}

  # No version specified.

  License: GPL+

  URL: https://src.fedoraproject.org/rpms/redhat-rpm-config
@@ -48,6 +48,7 @@ 

  Source153: macros.forge

  Source155: macros.ldconfig

  Source156: macros.vpath

+ Source157: macros.distro

  

  # Build policy scripts

  # this comes from https://github.com/rpm-software-management/rpm/pull/344
@@ -205,6 +206,7 @@ 

  %{_rpmconfigdir}/macros.d/macros.forge

  %{_rpmconfigdir}/macros.d/macros.ldconfig

  %{_rpmconfigdir}/macros.d/macros.vpath

+ %{_rpmconfigdir}/macros.d/macros.distro

  %dir %{_rpmluadir}/fedora

  %dir %{_rpmluadir}/fedora/srpm

  %dir %{_rpmluadir}/fedora/rpm

Define macros for commonly-used strings/urls to distinguish
distributions. Spec files have lots of "%{?fedora:}" and "%{?rhel}"
conditionals which can be defined in one place.

Amazon Linux is a new downstream distribution of Fedora that will add
its own definitions as well, so consolidate all of these in a new macros
file.

The macros here have been tested with local builds of clang and gdb.
Once this change is merged, I will submit updates to a few packages.

As examples, this is how clang.spec and gdb.spec will look after this
change:

clang.spec:

@@ -358,7 +360,7 @@ CFLAGS="$CFLAGS -Wno-address -Wno-nonnull -Wno-maybe-uninitialized"
        \
        -DCLANG_BUILD_EXAMPLES:BOOL=OFF \
        -DBUILD_SHARED_LIBS=OFF \
-       -DCLANG_REPOSITORY_STRING="%{?fedora:Fedora}%{?rhel:Red Hat} %{version}-%{release}" \
+       -DCLANG_REPOSITORY_STRING="%{distro_vendor} %{version}-%{release}" \
 %ifarch %{arm}
        -DCLANG_DEFAULT_LINKER=lld \
 %endif

gdb.spec:

-# Change the version that gets printed at GDB startup, so it is RH specific.
+# Change the version that gets printed at GDB startup, so it is distro-specific.
 cat > gdb/version.in << _FOO
-%if 0%{!?rhel:1}
-Fedora %{version}-%{release}
-%else # !0%{!?rhel:1}
-Red Hat Enterprise Linux %{version}-%{release}
-%endif # !0%{!?rhel:1}
+%{distro_name} %{version}-%{release}
 _FOO

 # Remove the info and other generated files added by the FSF release

Signed-off-by: Amit Shah amitshah@fedoraproject.org

On the surface this seems reasonable but I am not sure it's a good idea that redhat-rpm-config try to detect the distribution. Instead the values to be used should simply be directly listed in macros.dist, and that file should differ between distributions and versions as it does now.

Maybe we could add macros that expand to values from /etc/os-release (perhaps with memoization)? As far as I can see, this file is part of our buildroots.

That makes sense too.

I could move all of this in the fedora-release package, and have the macros be part of that one source spec file, and output both os-release and macros.dist from there.

Something like:

diff --git a/fedora-release.spec b/fedora-release.spec
index cde523c..a2fb748 100644
--- a/fedora-release.spec
+++ b/fedora-release.spec
@@ -889,8 +889,28 @@ ln -s fedora-release %{buildroot}%{_sysconfdir}/system-release
   %global prerelease \ Prerelease
 %endif

+# -------------------------------------------------------------------------
+# Definitions for /etc/os-release and for macros in macros.dist.  These
+# macros are useful for spec files where distribution-specific identifiers
+# are used to customize packages.
+
+# Name of vendor / name of distribution. Typically used to identify where
+# the binary comes from in --help or --version messages of programs.
+# Examples: gdb.spec, clang.spec
+%global dist_vendor Fedora
+%global dist_name   Fedora Linux
+
+# URLs used to output upstream / source of distribution.
+# Example: gstreamer1-plugins-base.spec
+%global dist_home_url https://fedoraproject.org/
+
+# Bugzilla / bug reporting URLs shown to users.
+# Examples: gcc.spec
+%global dist_bug_report_url https://bugzilla.redhat.com/
+# -------------------------------------------------------------------------
+
 cat << EOF >> os-release
-NAME="Fedora Linux"
+NAME="%{dist_name}"
 VERSION="%{dist_version} (%{release_name}%{?prerelease})"
 ID=fedora
 VERSION_ID=%{dist_version}
@@ -900,10 +920,10 @@ PRETTY_NAME="Fedora Linux %{dist_version} (%{release_name}%{?prerelease})"
 ANSI_COLOR="0;38;2;60;110;180"
 LOGO=fedora-logo-icon
 CPE_NAME="cpe:/o:fedoraproject:fedora:%{dist_version}"
-HOME_URL="https://fedoraproject.org/"
+HOME_URL="%{dist_home_url}"
 DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/%{doc_version}/system-administrators-guide/"
 SUPPORT_URL="https://ask.fedoraproject.org/"
-BUG_REPORT_URL="https://bugzilla.redhat.com/"
+BUG_REPORT_URL="%{dist_bug_report_url}"
 REDHAT_BUGZILLA_PRODUCT="Fedora"
 REDHAT_BUGZILLA_PRODUCT_VERSION=%{bug_version}
 REDHAT_SUPPORT_PRODUCT="Fedora"
@@ -1185,6 +1205,10 @@ cat >> %{buildroot}%{_rpmconfigdir}/macros.d/macros.dist << EOF
 %%fc%{dist_version}                1
 %%dist                %%{!?distprefix0:%%{?distprefix}}%%{expand:%%{lua:for i=0,9999 do print("%%{?distprefix" .. i .."}") end}}.fc%%{fedora}%%{?with_bootstrap:%{__bootstrap}}
 %endif
+%%dist_vendor         %{dist_vendor}
+%%dist_name           %{dist_name}
+%%dist_home_url       %{dist_home_url}
+%%dist_bug_report_url %{dist_bug_report_url}
 EOF

 # Install licenses

Both the approaches make sense for slightly different reasons; and I'm not partial to any. Let me know if the 2nd one works better, and I'll submit a PR for that.

PR against fedora-release submitted at https://src.fedoraproject.org/rpms/fedora-release/pull-request/223 to show what the alternative looks like from the comment above.

FWIW, I'm in favor of the fedora-release approach. I've reviewed the MR and it looks sane to me.

I assume that once that lands, there will be a doc update with the new macros?

@sgallagh which documentation were you thinking of? It could fit in the packaging guide (https://docs.fedoraproject.org/en-US/packaging-guidelines/RPMMacros/) - but I wasn't sure if that's the right place.

It seems like the consensus is for the other PR. I'll close this one once the other one is merged. How many +1s are expected?

Honestly it's not uncommon for macros like this to not carry documentation, besides perhaps comments in he macro files. (Not saying that's a good thing, but there's often not a particularly good place to put it.)

In this case, I don't think the packaging committee would complain about a pull request against https://docs.fedoraproject.org/en-US/packaging-guidelines/DistTag/, which has information on many related macros.

I'll submit one there, sure.

Pull-Request has been closed by amitshah

5 months ago
Metadata