!145 Revert patches : Add support for selecting a clang as a tool AND Call %set_build_flags before %build, %check, and %install stages

From: @liyunfei33 
Reviewed-by: @openeuler-basic 
Signed-off-by: @openeuler-basic
This commit is contained in:
openeuler-ci-bot 2023-08-28 13:42:14 +00:00 committed by Gitee
commit 8777b2b345
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 4 additions and 174 deletions

View File

@ -1,129 +0,0 @@
From f7e2d84e2b89285ebea5869cebd785c563a11f7b Mon Sep 17 00:00:00 2001
From: liyunfei <liyunfei33@huawei.com>
Date: Wed, 16 Aug 2023 17:41:51 +0800
Subject: [PATCH] [Backport]Add support for selecting a clang as a toolchain
Reference: https://src.fedoraproject.org/rpms/redhat-rpm-config/c/7562b38ec5edac3da0e150fcbe57cabbcd7b7f9e?branch=rawhide
Originally-by: Igor Raits <ignatenkobrain@fedoraproject.org>
---
generic-hardened-clang.cfg | 1 +
macros | 57 +++++++++++++++++++++++++++++++++++---
rpmrc | 4 +--
3 files changed, 56 insertions(+), 6 deletions(-)
create mode 100644 generic-hardened-clang.cfg
diff --git a/generic-hardened-clang.cfg b/generic-hardened-clang.cfg
new file mode 100644
index 0000000..b570eb5
--- /dev/null
+++ b/generic-hardened-clang.cfg
@@ -0,0 +1 @@
+-fPIE
diff --git a/macros b/macros
index 65d1365..47a20f5 100755
--- a/macros
+++ b/macros
@@ -23,6 +23,46 @@
%_build_id_links none
+# GCC toolchain
+%__cc_gcc gcc
+%__cxx_gcc g++
+%__cpp_gcc gcc -E
+
+# Clang toolchain
+%__cc_clang clang
+%__cxx_clang clang++
+%__cpp_clang clang-cpp
+
+# Default to the GCC toolchain
+#
+# It is enough to override `toolchain` macro and all relevant macro for C/C++
+# compilers will be switched. Either in the spec or in the command-line.
+#
+# %global toolchain clang
+#
+# or:
+#
+# rpmbuild -D "toolchain clang" …
+#
+# Inside a spec file it is also possible to determine which toolchain is in use
+# by testing the same macro. For example:
+#
+# %if "%{toolchain}" == "gcc"
+# BuildRequires: gcc
+# %endif
+#
+# or:
+#
+# %if "%{toolchain}" == "clang"
+# BuildRequires: clang compiler-rt
+# %endif
+#
+%toolchain gcc
+
+%__cc %{expand:%%{__cc_%{toolchain}}}
+%__cxx %{expand:%%{__cxx_%{toolchain}}}
+%__cpp %{expand:%%{__cpp_%{toolchain}}}
+
#==============================================================================
# ---- compiler flags.
@@ -36,7 +76,10 @@
CXXFLAGS="${CXXFLAGS:-%{build_cxxflags}}" ; export CXXFLAGS ; \
FFLAGS="${FFLAGS:-%{build_fflags}}" ; export FFLAGS ; \
FCFLAGS="${FCFLAGS:-%{build_fflags}}" ; export FCFLAGS ; \
- LDFLAGS="${LDFLAGS:-%{build_ldflags}}" ; export LDFLAGS
+ LDFLAGS="${LDFLAGS:-%{build_ldflags}}" ; export LDFLAGS ; \
+ CC=%{__cc}; export CC ; \
+ CXX=%{__cxx}; export CXX ; \
+ CCC="${CCC:-%{__cxx}}" ; export CCC
#For backwards compatibility only.
%__global_cflags %{build_cflags}
@@ -162,8 +205,10 @@
# secure options for rpmbuild
#
# #hardened options
-%_hardening_cflags -specs=/usr/lib/rpm/generic-hardened-cc1
-%_hardening_ldflags -Wl,-z,now -specs=/usr/lib/rpm/generic-hardened-ld
+%_hardening_gcc_cflags -specs=/usr/lib/rpm/generic-hardened-cc1
+%_hardening_clang_cflags --config /usr/lib/rpm/generic-hardened-clang.cfg
+%_hardening_cflags %{expand:%%{_hardening_%{toolchain}_cflags}} -fstack-protector-strong
+%_hardening_ldflags -Wl,-z,now %[ "%{toolchain}" == "gcc" ? "-specs=/usr/lib/rpm/generic-hardened-ld" : "" ]
# Use "%undefine _hardened_build" to disable.
%_hardened_build 1
%_hardened_cflags %{?_hardened_build:%{_hardening_cflags}}
@@ -195,7 +240,11 @@
#%_ld_as_needed 1
%_ld_as_needed_flags %{?_ld_as_needed:-Wl,--as-needed}
-%__global_compiler_flags -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches %{_hardened_cflags}
+%_general_options -O2 -fexceptions -g -grecord-gcc-switches -pipe
+%_warning_options -Wall -Werror=format-security
+%_preprocessor_defines -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
+
+%__global_compiler_flags %{_general_options} %{_warning_options} %{_preprocessor_defines} %{_hardened_cflags}
# Automatically trim changelog entries after 2 years
%_changelog_trimtime %{lua:print(os.time() - 2 * 365 * 86400)}
diff --git a/rpmrc b/rpmrc
index 8ba756d..f0859a6 100755
--- a/rpmrc
+++ b/rpmrc
@@ -5,8 +5,8 @@ optflags: athlon %{__global_compiler_flags} -m32 -march=athlon -fasynchronous-un
optflags: ia64 %{__global_compiler_flags}
optflags: x86_64 %{__global_compiler_flags} -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection
-optflags: aarch64 %{__global_compiler_flags} -fasynchronous-unwind-tables -fstack-clash-protection
-optflags: riscv64 %{__global_compiler_flags} -fasynchronous-unwind-tables -fstack-clash-protection
+optflags: aarch64 %{__global_compiler_flags} -fasynchronous-unwind-tables %[ "%{toolchain}" == "gcc" ? "-fstack-clash-protection" : "" ]
+optflags: riscv64 %{__global_compiler_flags} -fasynchronous-unwind-tables %[ "%{toolchain}" == "gcc" ? "-fstack-clash-protection" : "" ]
buildarchtranslate: athlon: i686
buildarchtranslate: geode: i686
--
2.27.0

View File

@ -1,42 +0,0 @@
From f5e80fa103926a1eaaae7bc062673eb10ff9370d Mon Sep 17 00:00:00 2001
From: liyunfei <liyunfei33@huawei.com>
Date: Thu, 17 Aug 2023 19:44:14 +0800
Subject: [PATCH] [Backport] Call %set_build_flags before %build, %check, and
%install stages
https://fedoraproject.org/wiki/Changes/SetBuildFlagsBuildCheck
Originally by: tstellar
---
macros | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/macros b/macros
index 47a20f5..f4468cd 100755
--- a/macros
+++ b/macros
@@ -81,6 +81,13 @@
CXX=%{__cxx}; export CXX ; \
CCC="${CCC:-%{__cxx}}" ; export CCC
+# Automatically use set_build_flags macro for build, check, and
+# install phases.
+# Use "%undefine _auto_set_build_flags" to disable"
+%_auto_set_build_flags 1
+%__spec_build_pre %{___build_pre} %{?_auto_set_build_flags:%{set_build_flags}}
+%__spec_check_pre %{___build_pre} %{?_auto_set_build_flags:%{set_build_flags}}
+
#For backwards compatibility only.
%__global_cflags %{build_cflags}
%__global_cxxflags %{build_cxxflags}
@@ -141,6 +148,7 @@
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"\
mkdir -p `dirname "$RPM_BUILD_ROOT"`\
mkdir "$RPM_BUILD_ROOT"\
+ %{?_auto_set_build_flags:%{set_build_flags}}\
%{nil}
# ---- Expanded at end of %install scriptlet.
--
2.27.0

View File

@ -3,7 +3,7 @@
Name: %{vendor}-rpm-config
Version: 30
Release: 42
Release: 43
License: GPL+
Summary: specific rpm configuration files
URL: https://gitee.com/openeuler/openEuler-rpm-config
@ -31,8 +31,6 @@ Patch17: Feature-support-EBS-sign-for-IMA-digest-list.patch
Patch18: fix-brp-ldconfig-riscv-default-library-directory.patch
Patch19: add-pyproject-macros.patch
Patch20: add-pytest-and-tox-macros.patch
Patch21: Backport-Add-support-for-selecting-a-clang-as-a-tool.patch
Patch22: Backport-Call-set_build_flags-before-build-check-and.patch
Provides: python-rpm-macros = %{?epoch:%{epoch}:}%{version}-%{release}
Provides: python2-rpm-macros = %{?epoch:%{epoch}:}%{version}-%{release}
@ -144,6 +142,9 @@ sed -i "s/__vendor/%{vendor}/g" `grep "__vendor" -rl %{buildroot}%{_rpmconfigdir
%{rpmvdir}/find-requires.ksyms
%changelog
* Mon Aug 28 2023 liyunfei <liyunfei33@huawei.com> - 30-43
- Revert backport toolchain selecting and %%auto_set_build_flags patches
* Thu Aug 17 2023 liyunfei <liyunfei33@huawei.com> - 30-42
- Backport Call %%set_build_flags before %%build, %%check, and %%install stages