versioner: remove parsing of platforms.

Leave the machinery to use a symbol database around so that we can
switch over to parsing libc.map.txt in the future.

Test: tools/versioner/run_tests.py
Change-Id: Ifa8899b698764e4aeb6aa8bb2cdb2d44a67b863f
This commit is contained in:
Josh Gao 2017-12-12 11:51:32 -08:00
parent e57a398977
commit c166113c2b
4 changed files with 4 additions and 103 deletions

View file

@ -1 +0,0 @@
../../../development/ndk/platforms

View file

@ -61,91 +61,3 @@ std::unordered_set<std::string> getSymbols(const std::string& filename) {
return result;
}
// The NDK platforms are built by copying the platform directories on top of
// each other to build each successive API version. Thus, we need to walk
// backwards to find each desired file.
static std::string readPlatformFile(const CompilationType& type, llvm::StringRef platform_dir,
const std::string& filename, bool required) {
int api_level = type.api_level;
std::ifstream stream;
while (api_level >= arch_min_api[type.arch]) {
std::string path = std::string(platform_dir) + "/android-" + std::to_string(api_level) +
"/arch-" + to_string(type.arch) + "/symbols/" + filename;
stream = std::ifstream(path);
if (stream) {
return std::string(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>());
}
--api_level;
}
if (required) {
errx(1, "failed to find platform file '%s' for %s", filename.c_str(), to_string(type).c_str());
}
return std::string();
}
static std::map<std::string, NdkSymbolType> parsePlatform(const CompilationType& type,
const std::string& platform_dir) {
std::map<std::string, NdkSymbolType> result;
std::map<std::string, bool /*required*/> wanted_files = {
{ "libc.so.functions.txt", true },
{ "libc.so.variables.txt", false },
{ "libdl.so.functions.txt", false },
{ "libm.so.functions.txt", false },
{ "libm.so.variables.txt", false },
};
for (const auto& pair : wanted_files) {
llvm::StringRef file = pair.first;
bool required = pair.second;
NdkSymbolType symbol_type;
if (file.endswith(".functions.txt")) {
symbol_type = NdkSymbolType::function;
} else if (file.endswith(".variables.txt")) {
symbol_type = NdkSymbolType::variable;
} else {
errx(1, "internal error: unexpected platform filename '%s'\n", file.str().c_str());
}
std::string platform_file = readPlatformFile(type, platform_dir, file, required);
if (platform_file.empty()) {
continue;
}
llvm::SmallVector<llvm::StringRef, 0> symbols;
llvm::StringRef(platform_file).split(symbols, "\n");
for (llvm::StringRef symbol_name : symbols) {
if (symbol_name.empty()) {
continue;
}
if (result.count(symbol_name) != 0) {
if (strict) {
printf("duplicated symbol '%s' in '%s'\n", symbol_name.str().c_str(), file.str().c_str());
}
}
result[symbol_name] = symbol_type;
}
}
return result;
}
NdkSymbolDatabase parsePlatforms(const std::set<CompilationType>& types,
const std::string& platform_dir) {
std::map<std::string, std::map<CompilationType, NdkSymbolType>> result;
for (const CompilationType& type : types) {
std::map<std::string, NdkSymbolType> symbols = parsePlatform(type, platform_dir);
for (const auto& it : symbols) {
result[it.first][type] = it.second;
}
}
return result;
}

View file

@ -32,5 +32,3 @@ enum class NdkSymbolType {
};
using NdkSymbolDatabase = std::map<std::string, std::map<CompilationType, NdkSymbolType>>;
NdkSymbolDatabase parsePlatforms(const std::set<CompilationType>& types,
const std::string& platform_dir);

View file

@ -33,6 +33,7 @@
#include <iostream>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <sstream>
#include <string>
@ -614,9 +615,6 @@ int main(int argc, char** argv) {
std::string versioner_dir = to_string(top) + "/bionic/tools/versioner";
location.header_path = versioner_dir + "/current";
location.dependency_dir = versioner_dir + "/dependencies";
if (platform_dir.empty()) {
platform_dir = versioner_dir + "/platforms";
}
} else {
if (!android::base::Realpath(argv[optind], &location.header_path)) {
err(1, "failed to get realpath for path '%s'", argv[optind]);
@ -653,16 +651,10 @@ int main(int argc, char** argv) {
}
std::set<CompilationType> compilation_types;
NdkSymbolDatabase symbol_database;
std::optional<NdkSymbolDatabase> symbol_database;
compilation_types = generateCompilationTypes(selected_architectures, selected_levels);
// Do this before compiling so that we can early exit if the platforms don't match what we
// expect.
if (!platform_dir.empty()) {
symbol_database = parsePlatforms(compilation_types, platform_dir);
}
auto start = std::chrono::high_resolution_clock::now();
std::unique_ptr<HeaderDatabase> declaration_database =
compileHeaders(compilation_types, location);
@ -682,8 +674,8 @@ int main(int argc, char** argv) {
failed = true;
}
if (!platform_dir.empty()) {
if (!checkVersions(compilation_types, declaration_database.get(), symbol_database)) {
if (symbol_database) {
if (!checkVersions(compilation_types, declaration_database.get(), *symbol_database)) {
printf("versioner: version check failed\n");
failed = true;
}