Accept multiple --config options

redhat-rpm-config now adds --config to CFLAGS when the macro
%toolchain is set to clang.  Some packages end up adding CFLAGS
twice to their compiler commands, so we need to patch clang to
allow multiple --config options so that these packages won't
fail to compile.
This commit is contained in:
Tom Stellard 2020-06-16 23:21:43 +00:00
parent 43b5ca7f2b
commit e2a664c75a
2 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,64 @@
From d970ab63e22eb5918774953da6b99ac27e5832a0 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar@redhat.com>
Date: Tue, 16 Jun 2020 11:20:20 -0700
Subject: [PATCH] Driver: Accept multiple --config options if filenames are the
same
Summary:
We're trying to use the --config options to pass distro specific
options for Fedora via the CFLAGS variable. However, some projects
end up using the CFLAGS variable multiple times in their command line,
which leads to an error when --config is used.
This patch resolves this issue by allowing more than one --config option
on the command line as long as the file names are the same.
Reviewers: sepavloff, hfinkel
Reviewed By: sepavloff
Subscribers: cfe-commits, llvm-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D81424
---
clang/lib/Driver/Driver.cpp | 8 ++++++--
clang/test/Driver/config-file.c | 5 +++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 3add665..a8442d2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -833,8 +833,12 @@ bool Driver::loadConfigFile() {
std::vector<std::string> ConfigFiles =
CLOptions->getAllArgValues(options::OPT_config);
if (ConfigFiles.size() > 1) {
- Diag(diag::err_drv_duplicate_config);
- return true;
+ if (!std::all_of(
+ ConfigFiles.begin(), ConfigFiles.end(),
+ [ConfigFiles](std::string s) { return s == ConfigFiles[0]; })) {
+ Diag(diag::err_drv_duplicate_config);
+ return true;
+ }
}
if (!ConfigFiles.empty()) {
diff --git a/clang/test/Driver/config-file.c b/clang/test/Driver/config-file.c
index 04127d4..fde7260 100644
--- a/clang/test/Driver/config-file.c
+++ b/clang/test/Driver/config-file.c
@@ -71,3 +71,8 @@
// RUN: %clang --config-system-dir=%S/Inputs/config --config-user-dir=%S/Inputs/config2 --config config-4 -S %s -o /dev/null -v 2>&1 | FileCheck %s -check-prefix CHECK-PRECEDENCE
// CHECK-PRECEDENCE: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg
// CHECK-PRECEDENCE: -Wall
+
+
+//--- Duplicate --config options are allowed if the value is the same
+// RUN: %clang --config-system-dir=%S/Inputs/config --config-user-dir=%S/Inputs/config2 --config config-4 --config config-4 -S %s -o /dev/null -v 2>&1 | FileCheck %s -check-prefix CHECK-SAME-CONFIG
+// CHECK-SAME-CONFIG: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg
--
1.8.3.1

View File

@ -4,7 +4,7 @@
%global min_ver 0
%global patch_ver 0
#%%global rc_ver 6
%global baserelease 4
%global baserelease 5
%global clang_tools_binaries \
%{_bindir}/clang-apply-replacements \
@ -102,6 +102,7 @@ Patch14: 0001-clang-fix-undefined-behaviour-in-RawComment-getForma.patch
# Not Upstream
Patch15: 0001-clang-Don-t-install-static-libraries.patch
Patch16: 0001-Driver-Accept-multiple-config-options-if-filenames-a.patch
BuildRequires: gcc
BuildRequires: gcc-c++
@ -253,6 +254,7 @@ pathfix.py -i %{__python3} -pn \
%patch13 -p2 -b .unwind-all
%patch14 -p2 -b .clangd
%patch15 -p2 -b .no-install-static
%patch16 -p2 -b .config-multiple
mv ../%{clang_tools_srcdir} tools/extra
@ -480,6 +482,9 @@ LD_LIBRARY_PATH=%{buildroot}%{_libdir} ninja check-all -C _build || \
%endif
%changelog
* Mon Jun 08 2020 Tom Stellard <tstellar@redhat.com> - 10.0.0-5
- Accept multiple --config options
* Wed Jun 3 2020 Dan Čermák <dan.cermak@cgc-instruments.com> - 10.0.0-4
- Add symlink to %%{_libdir}/clang/%%{maj_ver} for persistent access to the resource directory accross minor version bumps