From f7b64e77505d9549b37dfe9c498af583b2e5052d Mon Sep 17 00:00:00 2001 From: zhangxingrong Date: Fri, 5 Jul 2024 14:36:06 +0800 Subject: [PATCH] add some upstream patchs --- 0004-Fix-parsing-flags-and-add-test.patch | 121 ++++++++++++++++++ ...tions-in-tests-for-C99-compatibility.patch | 39 ++++++ ...ssing-algorithm-include-for-std-find.patch | 78 +++++++++++ Bear.spec | 11 +- 4 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 0004-Fix-parsing-flags-and-add-test.patch create mode 100644 0005-Avoid-implicit-function-declarations-in-tests-for-C99-compatibility.patch create mode 100644 0006-Add-missing-algorithm-include-for-std-find.patch diff --git a/0004-Fix-parsing-flags-and-add-test.patch b/0004-Fix-parsing-flags-and-add-test.patch new file mode 100644 index 0000000..243f3cc --- /dev/null +++ b/0004-Fix-parsing-flags-and-add-test.patch @@ -0,0 +1,121 @@ +From 18a7efd63942a5fefc6d5f61f769df1b299c3b11 Mon Sep 17 00:00:00 2001 +From: Maria Kozlovtseva +Date: Mon, 3 Apr 2023 20:28:56 +0300 +Subject: [PATCH] Fix parsing flags and add test + +--- + source/citnames/source/semantic/Parsers.cc | 60 +++++++++++----------- + source/citnames/test/ParserTest.cc | 21 ++++++++ + 2 files changed, 51 insertions(+), 30 deletions(-) + +diff --git a/source/citnames/source/semantic/Parsers.cc b/source/citnames/source/semantic/Parsers.cc +index d535149b..50425a85 100644 +--- a/source/citnames/source/semantic/Parsers.cc ++++ b/source/citnames/source/semantic/Parsers.cc +@@ -200,19 +200,21 @@ namespace cs::semantic { + if (auto result = check_equal(key, *candidate); result) { + return result; + } +- // check if the argument is allowed to stick to the flag +- if (auto result = check_partial(key, *candidate); result) { +- return result; +- } + } +- // partial match is less likely to be a few steps away from the lower bound, +- // therefore search the whole flag list again. +- for (const auto &candidate : flags_) { +- if (auto result = check_partial(key, candidate); result) { +- return result; ++ ++ std::optional candidate_longest = std::nullopt; ++ for (const auto &[candidate, info] : flags_) { ++ if (const auto& extra = split_extra(candidate, key); extra) { ++ const size_t prefix_length = key.size() - extra.value().size(); ++ if (!candidate_longest || (prefix_length > candidate_longest.value().size())) { ++ candidate_longest = std::make_optional(std::string(candidate)); ++ } + } + } +- return std::nullopt; ++ ++ return (candidate_longest.has_value()) ++ ? check_partial(key, *(flags_.find(candidate_longest.value()))) ++ : std::nullopt; + } + + std::optional +@@ -228,26 +230,24 @@ namespace cs::semantic { + std::optional + FlagParser::check_partial(const std::string_view &key, const FlagsByName::value_type &candidate) { + const auto &flag_definition = candidate.second; +- if (const auto &extra = split_extra(candidate.first, key); extra) { +- const auto flag_matching = classify_flag_matching(extra.value()); +- switch (flag_matching) { +- case FlagMatch::GLUED: +- if (is_glue_allowed(flag_definition.match)) { +- const size_t decrease = is_prefix_match(flag_definition.match) ? 0 : 1; +- const size_t count = count_of_arguments(flag_definition.match) - decrease; +- return std::make_optional(std::make_tuple(count, flag_definition.type)); +- } +- break; +- case FlagMatch::GLUED_WITH_EQ: +- if (is_glue_with_equal_allowed(flag_definition.match)) { +- const size_t count = count_of_arguments(flag_definition.match) - 1; +- return std::make_optional(std::make_tuple(count, flag_definition.type)); +- } +- break; +- default: +- // This should not happen here. Exact match is already filtered out. +- return std::nullopt; +- } ++ const auto flag_matching = classify_flag_matching(key.substr(candidate.first.size())); ++ switch (flag_matching) { ++ case FlagMatch::GLUED: ++ if (is_glue_allowed(flag_definition.match)) { ++ const size_t decrease = is_prefix_match(flag_definition.match) ? 0 : 1; ++ const size_t count = count_of_arguments(flag_definition.match) - decrease; ++ return std::make_optional(std::make_tuple(count, flag_definition.type)); ++ } ++ break; ++ case FlagMatch::GLUED_WITH_EQ: ++ if (is_glue_with_equal_allowed(flag_definition.match)) { ++ const size_t count = count_of_arguments(flag_definition.match) - 1; ++ return std::make_optional(std::make_tuple(count, flag_definition.type)); ++ } ++ break; ++ default: ++ // This should not happen here. Exact match is already filtered out. ++ __builtin_unreachable(); + } + return std::nullopt; + } +diff --git a/source/citnames/test/ParserTest.cc b/source/citnames/test/ParserTest.cc +index 6f6cd07e..dd6b85a3 100644 +--- a/source/citnames/test/ParserTest.cc ++++ b/source/citnames/test/ParserTest.cc +@@ -320,4 +320,25 @@ namespace { + EXPECT_TRUE(flags.is_err()); + } + } ++ ++ TEST(Parser, parse_flags_with_several_suitable_prefixes) { ++ const FlagsByName flags_by_name = { ++ {"-l", {MatchInstruction::PREFIX, CompilerFlagType::LINKER}}, ++ {"-language", {MatchInstruction::EXACTLY_WITH_1_OPT_SEP, CompilerFlagType::OTHER}}, ++ {"-linker", {MatchInstruction::PREFIX_WITH_2_OPTS, CompilerFlagType::OTHER}}, ++ }; ++ const auto sut = Repeat(FlagParser(flags_by_name)); ++ ++ { ++ const Arguments input = {"compiler", "-lin", "-language", "s", "-linkeriasds", "opt1", "opt2"}; ++ const auto flags = parse(sut, input); ++ EXPECT_TRUE(flags.is_ok()); ++ const CompilerFlags expected = { ++ CompilerFlag{slice(input, 1), CompilerFlagType::LINKER}, ++ CompilerFlag{slice(input, 2, 4), CompilerFlagType::OTHER}, ++ CompilerFlag{slice(input, 4, 7), CompilerFlagType::OTHER}, ++ }; ++ EXPECT_EQ(expected, flags.unwrap()); ++ } ++ } + } diff --git a/0005-Avoid-implicit-function-declarations-in-tests-for-C99-compatibility.patch b/0005-Avoid-implicit-function-declarations-in-tests-for-C99-compatibility.patch new file mode 100644 index 0000000..195cccf --- /dev/null +++ b/0005-Avoid-implicit-function-declarations-in-tests-for-C99-compatibility.patch @@ -0,0 +1,39 @@ +From 472cbed312444cdcef9102e924c79070ea1d3ab2 Mon Sep 17 00:00:00 2001 +From: Florian Weimer +Date: Sat, 15 Apr 2023 19:37:41 +0200 +Subject: [PATCH] Avoid implicit function declarations in tests, for C99 + compatibility + +Include for printf and define _GNU_SOURCE for execvpe. + +Future compilers will not support implicit function declartions by +default, causing these tests to fail to build. +--- + test/cases/intercept/preload/errno_reset.c | 1 + + test/cases/intercept/preload/posix/execvpe/success.c | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/test/cases/intercept/preload/errno_reset.c b/test/cases/intercept/preload/errno_reset.c +index c9c82bf6..82821f3e 100644 +--- a/test/cases/intercept/preload/errno_reset.c ++++ b/test/cases/intercept/preload/errno_reset.c +@@ -5,6 +5,7 @@ + #include + #include + #include ++#include + + int main() + { +diff --git a/test/cases/intercept/preload/posix/execvpe/success.c b/test/cases/intercept/preload/posix/execvpe/success.c +index 0b4b66d0..9017be6c 100644 +--- a/test/cases/intercept/preload/posix/execvpe/success.c ++++ b/test/cases/intercept/preload/posix/execvpe/success.c +@@ -8,6 +8,7 @@ + #include "config.h" + + #if defined HAVE_UNISTD_H ++#define _GNU_SOURCE + #include + #endif + diff --git a/0006-Add-missing-algorithm-include-for-std-find.patch b/0006-Add-missing-algorithm-include-for-std-find.patch new file mode 100644 index 0000000..701c1f6 --- /dev/null +++ b/0006-Add-missing-algorithm-include-for-std-find.patch @@ -0,0 +1,78 @@ +From 44c0e84f1a270ff062b6cbf128de5b97efeadb3f Mon Sep 17 00:00:00 2001 +From: Sam James +Date: Wed, 7 Jun 2023 18:13:11 +0100 +Subject: [PATCH] Add missing include for std::find + +GCC 14 drops some transitive includes within libstdc++. + +Explicitly include for std::find. +--- + source/citnames/source/semantic/ToolAny.cc | 2 ++ + source/citnames/source/semantic/ToolExtendingWrapper.cc | 2 ++ + source/libflags/source/Flags.cc | 1 + + source/libsys/source/Guard.cc | 1 + + source/libsys/source/Process.cc | 1 + + 5 files changed, 7 insertions(+) + +diff --git a/source/citnames/source/semantic/ToolAny.cc b/source/citnames/source/semantic/ToolAny.cc +index 1cccfee5..7c742cec 100644 +--- a/source/citnames/source/semantic/ToolAny.cc ++++ b/source/citnames/source/semantic/ToolAny.cc +@@ -19,6 +19,8 @@ + + #include "ToolAny.h" + ++#include ++ + namespace cs::semantic { + + ToolAny::ToolAny(ToolAny::ToolPtrs &&tools, std::list &&to_exclude) noexcept +diff --git a/source/citnames/source/semantic/ToolExtendingWrapper.cc b/source/citnames/source/semantic/ToolExtendingWrapper.cc +index e05cab68..293137c4 100644 +--- a/source/citnames/source/semantic/ToolExtendingWrapper.cc ++++ b/source/citnames/source/semantic/ToolExtendingWrapper.cc +@@ -19,6 +19,8 @@ + + #include "ToolExtendingWrapper.h" + ++#include ++ + namespace cs::semantic { + + ToolExtendingWrapper::ToolExtendingWrapper(CompilerWrapper &&compilers_to_recognize) noexcept +diff --git a/source/libflags/source/Flags.cc b/source/libflags/source/Flags.cc +index da46873a..2cf53585 100644 +--- a/source/libflags/source/Flags.cc ++++ b/source/libflags/source/Flags.cc +@@ -19,6 +19,7 @@ + + #include "libflags/Flags.h" + ++#include + #include + #include + #include +diff --git a/source/libsys/source/Guard.cc b/source/libsys/source/Guard.cc +index b4e06499..7378fdc1 100644 +--- a/source/libsys/source/Guard.cc ++++ b/source/libsys/source/Guard.cc +@@ -20,6 +20,7 @@ + #include "Guard.h" + #include "libsys/Environment.h" + ++#include + #include + #include + +diff --git a/source/libsys/source/Process.cc b/source/libsys/source/Process.cc +index 59fecd82..15a93f9e 100644 +--- a/source/libsys/source/Process.cc ++++ b/source/libsys/source/Process.cc +@@ -22,6 +22,7 @@ + #include "libsys/Errors.h" + #include "Guard.h" + ++#include + #include + #include + #include diff --git a/Bear.spec b/Bear.spec index 3fc2cb7..a468642 100644 --- a/Bear.spec +++ b/Bear.spec @@ -11,7 +11,7 @@ %bcond_with tests Name: Bear Version: 3.0.20 -Release: 4 +Release: 5 Summary: Tool to generate compilation database for clang tooling License: GPL-3.0-or-later URL: https://github.com/rizsotto/Bear @@ -47,6 +47,9 @@ BuildRequires: findutils Patch1: 0001-change-external-project-to-local-package.patch Patch2: 0002-Rebuild-when-add-option-failed.patch Patch3: 0003-Bugfix-skip-rebuild-without-new-options-and-preprocess.patch +Patch4: 0004-Fix-parsing-flags-and-add-test.patch +Patch5: 0005-Avoid-implicit-function-declarations-in-tests-for-C99-compatibility.patch +Patch6: 0006-Add-missing-algorithm-include-for-std-find.patch %description Bear is a tool to generate compilation database for clang tooling. @@ -96,6 +99,12 @@ popd %{_libdir}/bear/ %changelog +* Fri Jul 5 2024 zhangxingrong - 3.0.20-5 +- Type:Add some upstream patches +- ID:NA +- SUG:NA +- DESC: Fix parsing flags and add test;Avoid implicit function declarations in tests, for C99 compatibility;Add missing include for std::find + * Fri Jan 6 2023 yangtao - 3.0.20-4 - Type:SPEC - ID:NA -- Gitee