Merge "Exclude version blocks by patterns" into main
This commit is contained in:
@@ -72,8 +72,10 @@ static llvm::cl::opt<std::string> version_script(
|
|||||||
llvm::cl::cat(header_linker_category));
|
llvm::cl::cat(header_linker_category));
|
||||||
|
|
||||||
static llvm::cl::list<std::string> excluded_symbol_versions(
|
static llvm::cl::list<std::string> excluded_symbol_versions(
|
||||||
"exclude-symbol-version", llvm::cl::Optional,
|
"exclude-symbol-version",
|
||||||
llvm::cl::cat(header_linker_category));
|
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(
|
static llvm::cl::list<std::string> excluded_symbol_tags(
|
||||||
"exclude-symbol-tag", llvm::cl::Optional,
|
"exclude-symbol-tag", llvm::cl::Optional,
|
||||||
|
|||||||
@@ -14,13 +14,12 @@
|
|||||||
|
|
||||||
#include "repr/symbol/exported_symbol_set.h"
|
#include "repr/symbol/exported_symbol_set.h"
|
||||||
|
|
||||||
|
#include <cxxabi.h>
|
||||||
|
|
||||||
#include "repr/ir_representation.h"
|
#include "repr/ir_representation.h"
|
||||||
#include "utils/stl_utils.h"
|
#include "utils/stl_utils.h"
|
||||||
#include "utils/string_utils.h"
|
#include "utils/string_utils.h"
|
||||||
|
|
||||||
#include <fnmatch.h>
|
|
||||||
#include <cxxabi.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace header_checker {
|
namespace header_checker {
|
||||||
namespace repr {
|
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,
|
void ExportedSymbolSet::AddFunction(const std::string &name,
|
||||||
ElfSymbolIR::ElfSymbolBinding binding) {
|
ElfSymbolIR::ElfSymbolBinding binding) {
|
||||||
funcs_.emplace(name, ElfFunctionIR(name, binding));
|
funcs_.emplace(name, ElfFunctionIR(name, binding));
|
||||||
@@ -70,7 +51,7 @@ bool ExportedSymbolSet::HasSymbol(const std::string &name) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasMatchingGlobPattern(glob_patterns_, name)) {
|
if (utils::HasMatchingGlobPattern(glob_patterns_, name.c_str())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,8 +67,8 @@ bool ExportedSymbolSet::HasSymbol(const std::string &name) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasMatchingGlobPattern(demangled_cpp_glob_patterns_,
|
if (utils::HasMatchingGlobPattern(demangled_cpp_glob_patterns_,
|
||||||
demangled_name_c_str.get())) {
|
demangled_name_c_str.get())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#define EXPORTED_SYMBOL_SET_
|
#define EXPORTED_SYMBOL_SET_
|
||||||
|
|
||||||
#include "repr/ir_representation.h"
|
#include "repr/ir_representation.h"
|
||||||
|
#include <utils/string_utils.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -31,8 +32,8 @@ class ExportedSymbolSet {
|
|||||||
public:
|
public:
|
||||||
using FunctionMap = std::map<std::string, ElfFunctionIR, std::less<>>;
|
using FunctionMap = std::map<std::string, ElfFunctionIR, std::less<>>;
|
||||||
using VarMap = std::map<std::string, ElfObjectIR, std::less<>>;
|
using VarMap = std::map<std::string, ElfObjectIR, std::less<>>;
|
||||||
using NameSet = std::set<std::string, std::less<>>;
|
using NameSet = utils::StringSet;
|
||||||
using GlobPatternSet = std::set<std::string, std::less<>>;
|
using GlobPatternSet = utils::StringSet;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -277,8 +277,8 @@ std::unique_ptr<ExportedSymbolSet> VersionScriptParser::Parse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string version(utils::Trim(line.substr(0, lparen_pos - 1)));
|
std::string version(utils::Trim(line.substr(0, lparen_pos - 1)));
|
||||||
bool exclude_symbol_version = (excluded_symbol_versions_.find(version) !=
|
bool exclude_symbol_version = utils::HasMatchingGlobPattern(
|
||||||
excluded_symbol_versions_.end());
|
excluded_symbol_versions_, version.c_str());
|
||||||
|
|
||||||
if (!ParseVersionBlock(exclude_symbol_version)) {
|
if (!ParseVersionBlock(exclude_symbol_version)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ class VersionScriptParser {
|
|||||||
std::string introduced_arch_tag_;
|
std::string introduced_arch_tag_;
|
||||||
utils::ApiLevel api_level_;
|
utils::ApiLevel api_level_;
|
||||||
|
|
||||||
std::set<std::string, std::less<>> excluded_symbol_versions_;
|
utils::StringSet excluded_symbol_versions_;
|
||||||
std::set<std::string, std::less<>> excluded_symbol_tags_;
|
utils::StringSet excluded_symbol_tags_;
|
||||||
|
|
||||||
std::istream *stream_;
|
std::istream *stream_;
|
||||||
int line_no_;
|
int line_no_;
|
||||||
|
|||||||
@@ -94,10 +94,9 @@ TEST(VersionScriptParserTest, ExcludeSymbolVersions) {
|
|||||||
EXPECT_NE(vars.end(), vars.find("bar2"));
|
EXPECT_NE(vars.end(), vars.find("bar2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// excluded_symbol_versions = {"LIBEX_PRIVATE"}
|
|
||||||
{
|
{
|
||||||
VersionScriptParser parser;
|
VersionScriptParser parser;
|
||||||
parser.AddExcludedSymbolVersion("LIBEX_PRIVATE");
|
parser.AddExcludedSymbolVersion("*_PRIVATE");
|
||||||
|
|
||||||
std::istringstream stream(testdata);
|
std::istringstream stream(testdata);
|
||||||
std::unique_ptr<ExportedSymbolSet> result(parser.Parse(stream));
|
std::unique_ptr<ExportedSymbolSet> result(parser.Parse(stream));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "utils/string_utils.h"
|
#include "utils/string_utils.h"
|
||||||
|
|
||||||
#include <llvm/ADT/Optional.h>
|
#include <fnmatch.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <llvm/ADT/Optional.h>
|
||||||
|
|
||||||
|
|
||||||
namespace header_checker {
|
namespace header_checker {
|
||||||
namespace utils {
|
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 utils
|
||||||
} // namespace header_checker
|
} // namespace header_checker
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <llvm/ADT/Optional.h>
|
#include <llvm/ADT/Optional.h>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -25,6 +26,9 @@ namespace header_checker {
|
|||||||
namespace utils {
|
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);
|
std::string_view Trim(std::string_view s);
|
||||||
|
|
||||||
bool StartsWith(std::string_view s, std::string_view prefix);
|
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 IsGlobPattern(std::string_view s);
|
||||||
|
|
||||||
|
bool HasMatchingGlobPattern(const StringSet &patterns, const char *text);
|
||||||
|
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
} // namespace header_checker
|
} // namespace header_checker
|
||||||
|
|||||||
@@ -562,7 +562,7 @@ TEST_MODULES = [
|
|||||||
'integration/version_script_example/prebuilts/' +
|
'integration/version_script_example/prebuilts/' +
|
||||||
'libversion_script_example.so'
|
'libversion_script_example.so'
|
||||||
),
|
),
|
||||||
'--exclude-symbol-version', 'LIBVERSION_SCRIPT_EXAMPLE_PRIVATE',
|
'--exclude-symbol-version', '*_PRIVATE',
|
||||||
],
|
],
|
||||||
has_reference_dump=True,
|
has_reference_dump=True,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user