Implement the Cross-Version ABI diff configuration

Enable the Cross-Version ABI diff configuration so developers can
specify different flags for current and previous version ABI Check. The
-target-version flag were added to determine the config section to be
selected. The details of this configuration logic could be found in
go/cross-version-abi-diff-configuration.

Test: preform abi diff with config.json
Bug: 239792343
Change-Id: I8fdad2d18096cfa7866183ecc2d7826682c85eb6
This commit is contained in:
Mu-Le Lee
2022-08-10 15:11:17 +00:00
parent c2ebbbfec5
commit 2ce72d8673
4 changed files with 120 additions and 74 deletions

View File

@@ -30,6 +30,7 @@ using header_checker::repr::CompatibilityStatusIR;
using header_checker::repr::DiffPolicyOptions;
using header_checker::repr::TextFormatIR;
using header_checker::utils::ConfigFile;
using header_checker::utils::ConfigSection;
static llvm::cl::OptionCategory header_checker_category(
@@ -129,6 +130,15 @@ static llvm::cl::opt<bool> allow_adding_removing_weak_symbols(
llvm::cl::init(false), llvm::cl::Optional,
llvm::cl::cat(header_checker_category));
static llvm::cl::opt<std::string> target_version(
"target-version",
llvm::cl::desc(
"Load the flags for <target version> and <lib name> from config.json in "
"the old dump's parent directory."
),
llvm::cl::init("current"), llvm::cl::Optional,
llvm::cl::cat(header_checker_category));
static std::set<std::string> LoadIgnoredSymbols(std::string &symbol_list_path) {
std::ifstream symbol_ifstream(symbol_list_path);
std::set<std::string> ignored_symbols;
@@ -150,33 +160,40 @@ static std::string GetConfigFilePath(const std::string &dump_file_path) {
return std::string(config_file_path);
}
static void UpdateFlags(const ConfigSection &section) {
for (auto &&p : section) {
auto &&key = p.first;
bool value_bool = p.second;
if (key == "allow_adding_removing_weak_symbols") {
allow_adding_removing_weak_symbols = value_bool;
} else if (key == "advice_only") {
advice_only = value_bool;
} else if (key == "elf_unreferenced_symbol_errors") {
elf_unreferenced_symbol_errors = value_bool;
} else if (key == "check_all_apis") {
check_all_apis = value_bool;
} else if (key == "allow_extensions") {
allow_extensions = value_bool;
} else if (key == "allow_unreferenced_elf_symbol_changes") {
allow_unreferenced_elf_symbol_changes = value_bool;
} else if (key == "allow_unreferenced_changes") {
allow_unreferenced_changes = value_bool;
} else if (key == "consider_opaque_types_different") {
consider_opaque_types_different = value_bool;
}
}
}
static void ReadConfigFile(const std::string &config_file_path) {
ConfigFile cfg;
if (!cfg.Load(config_file_path)) {
::exit(1);
}
if (cfg.HasSection("global")) {
for (auto &&p : cfg.GetSection("global")) {
auto &&key = p.first;
bool value_bool = p.second;
if (key == "allow_adding_removing_weak_symbols") {
allow_adding_removing_weak_symbols = value_bool;
} else if (key == "advice_only") {
advice_only = value_bool;
} else if (key == "elf_unreferenced_symbol_errors") {
elf_unreferenced_symbol_errors = value_bool;
} else if (key == "check_all_apis") {
check_all_apis = value_bool;
} else if (key == "allow_extensions") {
allow_extensions = value_bool;
} else if (key == "allow_unreferenced_elf_symbol_changes") {
allow_unreferenced_elf_symbol_changes = value_bool;
} else if (key == "allow_unreferenced_changes") {
allow_unreferenced_changes = value_bool;
} else if (key == "consider_opaque_types_different") {
consider_opaque_types_different = value_bool;
}
}
if (cfg.HasGlobalSection()) {
UpdateFlags(cfg.GetGlobalSection());
}
if (cfg.HasSection(lib_name, target_version)) {
UpdateFlags(cfg.GetSection(lib_name, target_version));
}
}