From d6f71146ac16b375e95478d56ec0c505eefe90da Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Thu, 8 Nov 2018 18:52:17 +0100 Subject: [PATCH 1/6] forge: keep distprefixes lowercase, even for not primary ones --- forge.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge.lua b/forge.lua index af71c87..04a543d 100644 --- a/forge.lua +++ b/forge.lua @@ -224,7 +224,7 @@ local function forgemeta(suffix, verbose, informative, silent) end if (rpm.expand(distprefix) ~= "") then if not ismain then - distprefix = string.gsub(distprefix, "^%.", ".S") + distprefix = string.gsub(distprefix, "^%.", ".s") end fedora.safeset ("distprefix" .. suffix, distprefix, verbose) end From 7b6ec4668c2c8b4b52694619caf4909d8ecda382 Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Sun, 11 Nov 2018 17:41:48 +0100 Subject: [PATCH 2/6] forge: fix handling of / in refs as showcased by github.com/dnstap/golang-dnstap --- forge.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/forge.lua b/forge.lua index 04a543d..bcfe01f 100644 --- a/forge.lua +++ b/forge.lua @@ -143,6 +143,8 @@ local function forgemeta(suffix, verbose, informative, silent) elseif (fileref ~= "%{?commit" .. suffix .. "}") and string.match(rpm.expand(fileref), "^v[%d]") then fileref = string.gsub(rpm.expand(fileref), "^v", "") + elseif (string.match(rpm.expand(fileref), "/")) then + fileref = string.gsub(rpm.expand(fileref), "/", "-") end fedora.safeset("fileref" .. suffix, fileref, verbose) elseif (forge == "code.googlesource.com") then @@ -201,7 +203,7 @@ local function forgemeta(suffix, verbose, informative, silent) distprefix = string.gsub(distprefix, "[%p%s]+", ".") distprefix = string.gsub(distprefix, "^" .. string.lower(rpm.expand("%{?repo}")) .. "%.?", "") local v = string.gsub(rpm.expand("%{version}"), "[%p%s]+", ".") - for _, p in ipairs({'','v','v.','version','version.'}) do + for _, p in ipairs({'','v','v.','version','version.','tags.v', 'tags.v.'}) do distprefix = getversionsuffix(distprefix, p .. v) end distprefix = string.gsub(distprefix, "^%.", "") From 353f8b9faff797c6068a037aaef18c5394c531c7 Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Thu, 8 Nov 2018 19:18:36 +0100 Subject: [PATCH 3/6] common: add a setcurrent helper --- common.lua | 21 +++++++++++++++++---- forge.lua | 4 ++-- macros.forge | 4 ++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/common.lua b/common.lua index 77ebf69..92924c6 100644 --- a/common.lua +++ b/common.lua @@ -2,7 +2,7 @@ -- Set a spec variable -- Echo the result if verbose -local function explicitset(rpmvar,value,verbose) +local function explicitset(rpmvar, value, verbose) local value = value if (value == nil) or (value == "") then value = "%{nil}" @@ -15,7 +15,7 @@ end -- Unset a spec variable if it is defined -- Echo the result if verbose -local function explicitunset(rpmvar,verbose) +local function explicitunset(rpmvar, verbose) if (rpm.expand("%{" .. rpmvar .. "}") ~= "%{" .. rpmvar .. "}") then rpm.define(rpmvar .. " %{nil}") if verbose then @@ -26,7 +26,7 @@ end -- Set a spec variable, if not already set -- Echo the result if verbose -local function safeset(rpmvar,value,verbose) +local function safeset(rpmvar, value, verbose) if (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then explicitset(rpmvar,value,verbose) end @@ -34,7 +34,7 @@ end -- Alias a list of rpm variables to the same variables suffixed with 0 (and vice versa) -- Echo the result if verbose -local function zalias(rpmvars,verbose) +local function zalias(rpmvars, verbose) for _, sfx in ipairs({{"","0"},{"0",""}}) do for _, rpmvar in ipairs(rpmvars) do local toalias = "%{?" .. rpmvar .. sfx[1] .. "}" @@ -45,6 +45,18 @@ local function zalias(rpmvars,verbose) end end +-- Takes a list of rpm variable roots and a suffix and alias current to +-- if it resolves to something not empty +local function setcurrent(rpmvars, suffix, verbose) + for _, rpmvar in ipairs(rpmvars) do + if (rpm.expand("%{?" .. rpmvar .. suffix .. "}") ~= "") then + explicitset( "current" .. rpmvar, "%{" .. rpmvar .. suffix .. "}", verbose) + else + explicitunset("current" .. rpmvar, verbose) + end + end +end + -- Echo the list of rpm variables, with suffix, if set local function echovars(rpmvars, suffix) for _, rpmvar in ipairs(rpmvars) do @@ -106,6 +118,7 @@ return { explicitunset = explicitunset, safeset = safeset, zalias = zalias, + setcurrent = setcurrent, echovars = echovars, getsuffixed = getsuffixed, getsuffixes = getsuffixes, diff --git a/forge.lua b/forge.lua index bcfe01f..950e345 100644 --- a/forge.lua +++ b/forge.lua @@ -66,7 +66,7 @@ end -- The forgemeta macro main processing function -- See the documentation in the macros.forge file for argument description -- Also called directly by gometa -local function forgemeta(suffix, verbose, informative, silent) +local function meta(suffix, verbose, informative, silent) local fedora = require "fedora.common" local ismain = (suffix == "") or (suffix == "0") if ismain then @@ -250,6 +250,6 @@ local function forgemeta(suffix, verbose, informative, silent) end return { - forgemeta = forgemeta, + meta = meta, } diff --git a/macros.forge b/macros.forge index b11ecec..167d2ed 100644 --- a/macros.forge +++ b/macros.forge @@ -53,10 +53,10 @@ local silent = rpm.expand("%{-s}") ~= "" local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") if processall then for _,s in pairs(fedora.getsuffixes("forgeurl")) do - forge.forgemeta(s,verbose,informative,silent) + forge.meta(s,verbose,informative,silent) end else - forge.forgemeta(rpm.expand("%{-z*}"),verbose,informative,silent) + forge.meta(rpm.expand("%{-z*}"),verbose,informative,silent) end } From 5335ee546b5d358ffd93d39f86351976f927ee41 Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Thu, 8 Nov 2018 19:12:25 +0100 Subject: [PATCH 4/6] common: add a writevars helper --- common.lua | 16 ++++++++++++++++ macros.fedora-misc | 30 ++++++++++++++++++++++++++++++ macros.forge | 12 ------------ redhat-rpm-config.spec | 2 ++ 4 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 macros.fedora-misc diff --git a/common.lua b/common.lua index 92924c6..1191c1f 100644 --- a/common.lua +++ b/common.lua @@ -113,6 +113,21 @@ local function getbestsuffix(rpmvar, value) return best end +-- https://github.com/rpm-software-management/rpm/issues/581 +-- Writes the content of a list of rpm variables to a macro spec file. +-- The target file must contain the corresponding anchors. +-- For example writevars("myfile", {"foo","bar"}) will replace: +-- @@FOO@@ with the rpm evaluation of %{foo} and +-- @@BAR@@ with the rpm evaluation of %{bar} +-- in myfile +local function writevars(macrofile,rpmvars) + for _, rpmvar in ipairs(rpmvars) do + print("sed -i 's\029" .. string.upper("@@" .. rpmvar .. "@@") .. + "\029" .. rpm.expand( "%{" .. rpmvar .. "}" ) .. + "\029g' " .. macrofile .. "\n") + end +end + return { explicitset = explicitset, explicitunset = explicitunset, @@ -123,4 +138,5 @@ return { getsuffixed = getsuffixed, getsuffixes = getsuffixes, getbestsuffix = getbestsuffix, + writevars = writevars, } diff --git a/macros.fedora-misc b/macros.fedora-misc new file mode 100644 index 0000000..ca54197 --- /dev/null +++ b/macros.fedora-misc @@ -0,0 +1,30 @@ +# Some miscellaneous Fedora-related macros + +# List files matching inclusion globs, excluding files matching exclusion blogs +# Parameters: +# -i "" include shell globs (also takes all other macro arguments) +# -x "" exclude shell globs +%listfiles(i:x:) %{expand: +while IFS= read -r -d $'\\n' finc ; do + printf "%s\\n" %{?-x*} \\ + | xargs -i realpath --relative-base=. '{}' \\ + | grep "${finc}" >/dev/null || echo "${finc}" +done <<< $(printf "%s\\n" %{?-i*} %* | xargs -i realpath --relative-base=. '{}' | sort -u) +} + +# https://github.com/rpm-software-management/rpm/issues/581 +# Write the contents of a list of rpm variables to a macro file. +# The target file must contain the corresponding anchors. +# For example %writevars -f myfile foo bar will replace: +# @@FOO@@ with the rpm evaluation of %{foo} and +# @@BAR@@ with the rpm evaluation of %{bar} +# in myfile +%writevars(f:) %{lua: +local fedora = require "fedora.common" +local macrofile = rpm.expand("%{-f*}") +local rpmvars = {} +for i = 1, rpm.expand("%#") do + table.insert(rpmvars, rpm.expand("%" .. i)) +end +fedora.writevars(macrofile,rpmvars) +} diff --git a/macros.forge b/macros.forge index 167d2ed..e1c3ed2 100644 --- a/macros.forge +++ b/macros.forge @@ -83,15 +83,3 @@ end %forgeautosetup(z:vNS:p:q) %{lua: print(rpm.expand("%autosetup %{-v} %{-N} %{?-S} %{?-p} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n")) } - -# List files matching inclusion globs, excluding files matching exclusion blogs -# Parameters: -# -i "" include shell globs (also takes all other macro arguments) -# -x "" exclude shell globs -%listfiles(i:x:) %{expand: -while IFS= read -r -d $'\\n' finc ; do - printf "%s\\n" %{?-x*} \\ - | xargs -i realpath --relative-base=. '{}' \\ - | grep "${finc}" >/dev/null || echo "${finc}" -done <<< $(printf "%s\\n" %{?-i*} %* | xargs -i realpath --relative-base=. '{}' | sort -u) -} diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index b9735f6..205cf5a 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -40,6 +40,7 @@ Source151: macros.kmp Source152: macros.vpath Source153: macros.forge Source154: macros.ldconfig +Source155: macros.fedora-misc # Build policy scripts # this comes from https://github.com/rpm-software-management/rpm/pull/344 @@ -177,6 +178,7 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua %{_rpmconfigdir}/macros.d/macros.forge %{_rpmconfigdir}/macros.d/macros.ldconfig %{_rpmconfigdir}/macros.d/macros.vpath +%{_rpmconfigdir}/macros.d/macros.fedora-misc %dir %{_rpmluadir}/fedora %dir %{_rpmluadir}/fedora/srpm %dir %{_rpmluadir}/fedora/rpm From 98ffd5040d05bbb706445e1a81f25c502137159a Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 17 Dec 2018 16:16:25 +0200 Subject: [PATCH 5/6] Silence the annoying warning from ldconfig brp-script (#1540971) --- brp-ldconfig | 5 ++++- redhat-rpm-config.spec | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/brp-ldconfig b/brp-ldconfig index 90d0f13..e169609 100755 --- a/brp-ldconfig +++ b/brp-ldconfig @@ -6,5 +6,8 @@ if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi -/sbin/ldconfig -N -r "$RPM_BUILD_ROOT" +# Create an empty config file for ldconfig to shut up a warning +config=$(mktemp -p "$RPM_BUILD_ROOT") +/sbin/ldconfig -f $(basename "$config") -N -r "$RPM_BUILD_ROOT" +rm -f "$config" # TODO: warn if it created new symlinks and guide people. diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index 205cf5a..c908540 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -6,7 +6,7 @@ Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config -Version: 125 +Version: 126 Release: 1%{?dist} # No version specified. License: GPL+ @@ -199,6 +199,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua %{_rpmconfigdir}/macros.d/macros.kmp %changelog +* Mon Dec 17 2018 Panu Matilainen - 126-1 +- Silence the annoying warning from ldconfig brp-script (#1540971) + * Thu Nov 15 2018 Miro HronĨok - 125-1 - Make automagic Python bytecompilation optional https://fedoraproject.org/wiki/Changes/No_more_automagic_Python_bytecompilation_phase_2 From e80fa1344a49662fec08d650debf793048c87429 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 20 Dec 2018 11:34:27 +0100 Subject: [PATCH 6/6] Build flags: Add support for extension builders (#1543394) --- buildflags.md | 41 +++++++++++++++++++++++++++++++++++++++++ macros | 16 ++++++++++++++++ redhat-rpm-config.spec | 5 ++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/buildflags.md b/buildflags.md index 06b41e6..541f562 100644 --- a/buildflags.md +++ b/buildflags.md @@ -332,3 +332,44 @@ linker flags: security exploits, redirecting execution). Therefore, it is preferable to turn of lazy binding, although it increases startup time. + +# Support for extension builders + +Some packages include extension builders that allow users to build +extension modules (which are usually written in C and C++) under the +control of a special-purpose build system. This is a common +functionality provided by scripting languages such as Python and Perl. +Traditionally, such extension builders captured the Fedora build flags +when these extension were built. However, these compiler flags are +adjusted for a specific Fedora release and toolchain version and +therefore do not work with a custom toolchain (e.g., different C/C++ +compilers), and users might want to build their own extension modules +with such toolchains. + +The macros `%{extension_cflags}`, `%{extension_cxxflags}`, +`%{extension_fflags}`, `%{extension_ldflags}` contain a subset of +flags that have been adjusted for compatibility with alternative +toolchains, while still preserving some of the compile-time security +hardening that the standard Fedora build flags provide. + +The current set of differences are: + +* No GCC plugins (such as annobin) are activated. +* No GCC spec files (`-specs=` arguments) are used. + +Additional flags may be removed in the future if they prove to be +incompatible with alternative toolchains. + +Extension builders should detect whether they are performing a regular +RPM build (e.g., by looking for an `RPM_OPT_FLAGS` variable). In this +case, they should use the *current* set of Fedora build flags (that +is, the output from `rpm --eval '%{build_cflags}'` and related +commands). Otherwise, when not performing an RPM build, they can +either use hard-coded extension builder flags (thus avoiding a +run-time dependency on `redhat-rpm-config`), or use the current +extension builder flags (with a run-time dependency on +`redhat-rpm-config`). + +As a result, extension modules built for Fedora will use the official +Fedora build flags, while users will still be able to build their own +extension modules with custom toolchains. diff --git a/macros b/macros index d87c0fc..5f083ce 100644 --- a/macros +++ b/macros @@ -57,6 +57,22 @@ FCFLAGS="${FCFLAGS:-%{build_fflags}}" ; export FCFLAGS ; \ LDFLAGS="${LDFLAGS:-%{build_ldflags}}" ; export LDFLAGS +# Internal-only. Do not use. Expand a variable and strip the flags +# not suitable to extension builders. +%__extension_strip_flags() %{lua: +local name = rpm.expand("%{1}") +local value = " " .. rpm.expand("%{build_" .. name .. "}") +local result = string.gsub(value, "%s+-specs=[^%s]+", " ") +print(result) +} + +# Variants of CFLAGS, CXXFLAGS, FFLAGS, LDFLAGS for use within +# extension builders. +%extension_cflags %{__extension_strip_flags cflags} +%extension_cxxflags %{__extension_strip_flags cxxflags} +%extension_fflags %{__extension_strip_flags fflags} +%extension_ldflags %{__extension_strip_flags ldflags} + # Deprecated names. For backwards compatibility only. %__global_cflags %{build_cflags} %__global_cxxflags %{build_cxxflags} diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index c908540..64b1674 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -6,7 +6,7 @@ Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config -Version: 126 +Version: 127 Release: 1%{?dist} # No version specified. License: GPL+ @@ -199,6 +199,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua %{_rpmconfigdir}/macros.d/macros.kmp %changelog +* Thu Dec 20 2018 Florian Weimer - 127-1 +- Build flags: Add support for extension builders (#1543394) + * Mon Dec 17 2018 Panu Matilainen - 126-1 - Silence the annoying warning from ldconfig brp-script (#1540971)