Merge "Exclude version blocks by patterns" into main am: 2f5228f1dc
Original change: https://android-review.googlesource.com/c/platform/development/+/2745605 Change-Id: Ie744d567fdc221c83909d14bf19cc69e98f6b6eb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -72,8 +72,10 @@ static llvm::cl::opt<std::string> version_script(
|
||||
llvm::cl::cat(header_linker_category));
|
||||
|
||||
static llvm::cl::list<std::string> excluded_symbol_versions(
|
||||
"exclude-symbol-version", llvm::cl::Optional,
|
||||
llvm::cl::cat(header_linker_category));
|
||||
"exclude-symbol-version",
|
||||
llvm::cl::desc("Specify the glob patterns of the version blocks to be "
|
||||
"excluded."),
|
||||
llvm::cl::Optional, llvm::cl::cat(header_linker_category));
|
||||
|
||||
static llvm::cl::list<std::string> excluded_symbol_tags(
|
||||
"exclude-symbol-tag", llvm::cl::Optional,
|
||||
|
||||
@@ -14,13 +14,12 @@
|
||||
|
||||
#include "repr/symbol/exported_symbol_set.h"
|
||||
|
||||
#include <cxxabi.h>
|
||||
|
||||
#include "repr/ir_representation.h"
|
||||
#include "utils/stl_utils.h"
|
||||
#include "utils/string_utils.h"
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
|
||||
namespace header_checker {
|
||||
namespace repr {
|
||||
@@ -31,24 +30,6 @@ static inline bool IsCppSymbol(const std::string &name) {
|
||||
}
|
||||
|
||||
|
||||
static inline bool HasMatchingGlobPattern(
|
||||
const ExportedSymbolSet::GlobPatternSet &patterns, const char *text) {
|
||||
for (auto &&pattern : patterns) {
|
||||
if (fnmatch(pattern.c_str(), text, 0) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static inline bool HasMatchingGlobPattern(
|
||||
const ExportedSymbolSet::GlobPatternSet &patterns,
|
||||
const std::string &text) {
|
||||
return HasMatchingGlobPattern(patterns, text.c_str());
|
||||
}
|
||||
|
||||
|
||||
void ExportedSymbolSet::AddFunction(const std::string &name,
|
||||
ElfSymbolIR::ElfSymbolBinding binding) {
|
||||
funcs_.emplace(name, ElfFunctionIR(name, binding));
|
||||
@@ -70,7 +51,7 @@ bool ExportedSymbolSet::HasSymbol(const std::string &name) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HasMatchingGlobPattern(glob_patterns_, name)) {
|
||||
if (utils::HasMatchingGlobPattern(glob_patterns_, name.c_str())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -86,8 +67,8 @@ bool ExportedSymbolSet::HasSymbol(const std::string &name) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HasMatchingGlobPattern(demangled_cpp_glob_patterns_,
|
||||
demangled_name_c_str.get())) {
|
||||
if (utils::HasMatchingGlobPattern(demangled_cpp_glob_patterns_,
|
||||
demangled_name_c_str.get())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#define EXPORTED_SYMBOL_SET_
|
||||
|
||||
#include "repr/ir_representation.h"
|
||||
#include <utils/string_utils.h>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
@@ -31,8 +32,8 @@ class ExportedSymbolSet {
|
||||
public:
|
||||
using FunctionMap = std::map<std::string, ElfFunctionIR, std::less<>>;
|
||||
using VarMap = std::map<std::string, ElfObjectIR, std::less<>>;
|
||||
using NameSet = std::set<std::string, std::less<>>;
|
||||
using GlobPatternSet = std::set<std::string, std::less<>>;
|
||||
using NameSet = utils::StringSet;
|
||||
using GlobPatternSet = utils::StringSet;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
@@ -277,8 +277,8 @@ std::unique_ptr<ExportedSymbolSet> VersionScriptParser::Parse(
|
||||
}
|
||||
|
||||
std::string version(utils::Trim(line.substr(0, lparen_pos - 1)));
|
||||
bool exclude_symbol_version = (excluded_symbol_versions_.find(version) !=
|
||||
excluded_symbol_versions_.end());
|
||||
bool exclude_symbol_version = utils::HasMatchingGlobPattern(
|
||||
excluded_symbol_versions_, version.c_str());
|
||||
|
||||
if (!ParseVersionBlock(exclude_symbol_version)) {
|
||||
return nullptr;
|
||||
|
||||
@@ -116,8 +116,8 @@ class VersionScriptParser {
|
||||
std::string introduced_arch_tag_;
|
||||
utils::ApiLevel api_level_;
|
||||
|
||||
std::set<std::string, std::less<>> excluded_symbol_versions_;
|
||||
std::set<std::string, std::less<>> excluded_symbol_tags_;
|
||||
utils::StringSet excluded_symbol_versions_;
|
||||
utils::StringSet excluded_symbol_tags_;
|
||||
|
||||
std::istream *stream_;
|
||||
int line_no_;
|
||||
|
||||
@@ -94,10 +94,9 @@ TEST(VersionScriptParserTest, ExcludeSymbolVersions) {
|
||||
EXPECT_NE(vars.end(), vars.find("bar2"));
|
||||
}
|
||||
|
||||
// excluded_symbol_versions = {"LIBEX_PRIVATE"}
|
||||
{
|
||||
VersionScriptParser parser;
|
||||
parser.AddExcludedSymbolVersion("LIBEX_PRIVATE");
|
||||
parser.AddExcludedSymbolVersion("*_PRIVATE");
|
||||
|
||||
std::istringstream stream(testdata);
|
||||
std::unique_ptr<ExportedSymbolSet> result(parser.Parse(stream));
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "utils/string_utils.h"
|
||||
|
||||
#include <llvm/ADT/Optional.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <llvm/ADT/Optional.h>
|
||||
|
||||
|
||||
namespace header_checker {
|
||||
namespace utils {
|
||||
@@ -104,5 +106,15 @@ bool IsGlobPattern(std::string_view s) {
|
||||
}
|
||||
|
||||
|
||||
bool HasMatchingGlobPattern(const StringSet &patterns, const char *text) {
|
||||
for (auto &&pattern : patterns) {
|
||||
if (fnmatch(pattern.c_str(), text, 0) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace utils
|
||||
} // namespace header_checker
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <llvm/ADT/Optional.h>
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -25,6 +26,9 @@ namespace header_checker {
|
||||
namespace utils {
|
||||
|
||||
|
||||
// This comparison function allows finding elements by string_view.
|
||||
using StringSet = std::set<std::string, std::less<>>;
|
||||
|
||||
std::string_view Trim(std::string_view s);
|
||||
|
||||
bool StartsWith(std::string_view s, std::string_view prefix);
|
||||
@@ -40,6 +44,8 @@ bool ParseBool(const std::string &s);
|
||||
|
||||
bool IsGlobPattern(std::string_view s);
|
||||
|
||||
bool HasMatchingGlobPattern(const StringSet &patterns, const char *text);
|
||||
|
||||
|
||||
} // namespace utils
|
||||
} // namespace header_checker
|
||||
|
||||
@@ -562,7 +562,7 @@ TEST_MODULES = [
|
||||
'integration/version_script_example/prebuilts/' +
|
||||
'libversion_script_example.so'
|
||||
),
|
||||
'--exclude-symbol-version', 'LIBVERSION_SCRIPT_EXAMPLE_PRIVATE',
|
||||
'--exclude-symbol-version', '*_PRIVATE',
|
||||
],
|
||||
has_reference_dump=True,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user