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
diff --git a/tools/versioner/platforms b/tools/versioner/platforms
deleted file mode 120000
index bcb7da8..0000000
--- a/tools/versioner/platforms
+++ /dev/null
@@ -1 +0,0 @@
-../../../development/ndk/platforms
\ No newline at end of file
diff --git a/tools/versioner/src/SymbolDatabase.cpp b/tools/versioner/src/SymbolDatabase.cpp
index 8521f4d..5b8ed5a 100644
--- a/tools/versioner/src/SymbolDatabase.cpp
+++ b/tools/versioner/src/SymbolDatabase.cpp
@@ -61,91 +61,3 @@
 
   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;
-}
diff --git a/tools/versioner/src/SymbolDatabase.h b/tools/versioner/src/SymbolDatabase.h
index 09948f5..c5b89d7 100644
--- a/tools/versioner/src/SymbolDatabase.h
+++ b/tools/versioner/src/SymbolDatabase.h
@@ -32,5 +32,3 @@
 };
 
 using NdkSymbolDatabase = std::map<std::string, std::map<CompilationType, NdkSymbolType>>;
-NdkSymbolDatabase parsePlatforms(const std::set<CompilationType>& types,
-                                 const std::string& platform_dir);
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
index a082f07..efb39bd 100644
--- a/tools/versioner/src/versioner.cpp
+++ b/tools/versioner/src/versioner.cpp
@@ -33,6 +33,7 @@
 #include <iostream>
 #include <map>
 #include <memory>
+#include <optional>
 #include <set>
 #include <sstream>
 #include <string>
@@ -614,9 +615,6 @@
     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 @@
   }
 
   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 @@
       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;
       }