Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | dfb74c5 | 2016-10-24 12:53:17 -0700 | [diff] [blame] | 2 | * Copyright (C) 2016 The Android Open Source Project |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
Elliott Hughes | dfb74c5 | 2016-10-24 12:53:17 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <dirent.h> |
| 18 | #include <err.h> |
| 19 | #include <limits.h> |
| 20 | #include <stdio.h> |
Josh Gao | d2ab9ff | 2017-07-28 12:53:36 -0700 | [diff] [blame] | 21 | #include <stdlib.h> |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 22 | #include <sys/stat.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <unistd.h> |
| 25 | |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 26 | #if defined(__linux__) |
| 27 | #include <sched.h> |
| 28 | #endif |
| 29 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 30 | #include <atomic> |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 31 | #include <chrono> |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 32 | #include <functional> |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 33 | #include <iostream> |
| 34 | #include <map> |
| 35 | #include <memory> |
| 36 | #include <set> |
| 37 | #include <sstream> |
| 38 | #include <string> |
| 39 | #include <thread> |
| 40 | #include <unordered_map> |
| 41 | #include <vector> |
| 42 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 43 | #include <llvm/ADT/StringRef.h> |
| 44 | |
Josh Gao | b50b8c8 | 2017-04-27 17:22:52 -0700 | [diff] [blame] | 45 | #include <android-base/file.h> |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 46 | #include <android-base/macros.h> |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 47 | #include <android-base/parseint.h> |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 48 | #include <android-base/strings.h> |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 49 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 50 | #include "Arch.h" |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 51 | #include "DeclarationDatabase.h" |
Josh Gao | b5c4963 | 2016-11-08 22:21:31 -0800 | [diff] [blame] | 52 | #include "Driver.h" |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 53 | #include "Preprocessor.h" |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 54 | #include "SymbolDatabase.h" |
| 55 | #include "Utils.h" |
Josh Gao | 78b8a14 | 2016-11-09 01:00:41 -0800 | [diff] [blame] | 56 | #include "VFS.h" |
| 57 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 58 | #include "versioner.h" |
| 59 | |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 60 | using namespace std::chrono_literals; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 61 | using namespace std::string_literals; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 62 | |
Josh Gao | acc3d80 | 2016-11-09 18:22:44 -0800 | [diff] [blame] | 63 | bool strict; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 64 | bool verbose; |
Josh Gao | acc3d80 | 2016-11-09 18:22:44 -0800 | [diff] [blame] | 65 | bool add_include; |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 66 | |
| 67 | static int getCpuCount(); |
| 68 | static int max_thread_count = getCpuCount(); |
| 69 | |
| 70 | static int getCpuCount() { |
| 71 | #if defined(__linux__) |
| 72 | cpu_set_t cpu_set; |
| 73 | int rc = sched_getaffinity(getpid(), sizeof(cpu_set), &cpu_set); |
| 74 | if (rc != 0) { |
| 75 | err(1, "sched_getaffinity failed"); |
| 76 | } |
| 77 | return CPU_COUNT(&cpu_set); |
| 78 | #else |
| 79 | return 1; |
| 80 | #endif |
| 81 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 82 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 83 | namespace { |
| 84 | struct HeaderLocationInformation { |
| 85 | std::string header_dir; |
| 86 | std::string dependency_dir; |
| 87 | // Absolute paths to ignore all children -- including subdirectories -- of. |
| 88 | std::unordered_set<std::string> ignored_directories; |
| 89 | }; |
| 90 | } |
| 91 | |
| 92 | static CompilationRequirements collectRequirements(const Arch& arch, |
| 93 | const HeaderLocationInformation& location) { |
| 94 | std::vector<std::string> headers = |
| 95 | collectHeaders(location.header_dir, location.ignored_directories); |
| 96 | std::vector<std::string> dependencies = { location.header_dir }; |
| 97 | if (!location.dependency_dir.empty()) { |
Yi Kong | ff6c8de | 2017-04-20 09:08:11 -0700 | [diff] [blame] | 98 | auto collect_children = [&dependencies](const std::string& dir_path) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 99 | DIR* dir = opendir(dir_path.c_str()); |
| 100 | if (!dir) { |
| 101 | err(1, "failed to open dependency directory '%s'", dir_path.c_str()); |
| 102 | } |
| 103 | |
| 104 | struct dirent* dent; |
| 105 | while ((dent = readdir(dir))) { |
| 106 | if (dent->d_name[0] == '.') { |
| 107 | continue; |
| 108 | } |
| 109 | |
| 110 | // TODO: Resolve symlinks. |
| 111 | std::string dependency = dir_path + "/" + dent->d_name; |
| 112 | |
| 113 | struct stat st; |
| 114 | if (stat(dependency.c_str(), &st) != 0) { |
| 115 | err(1, "failed to stat dependency '%s'", dependency.c_str()); |
| 116 | } |
| 117 | |
| 118 | if (!S_ISDIR(st.st_mode)) { |
| 119 | errx(1, "'%s' is not a directory", dependency.c_str()); |
| 120 | } |
| 121 | |
| 122 | dependencies.push_back(dependency); |
| 123 | } |
| 124 | |
| 125 | closedir(dir); |
| 126 | }; |
| 127 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 128 | collect_children(location.dependency_dir + "/common"); |
| 129 | collect_children(location.dependency_dir + "/" + to_string(arch)); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | auto new_end = std::remove_if(headers.begin(), headers.end(), [&arch](llvm::StringRef header) { |
| 133 | for (const auto& it : header_blacklist) { |
| 134 | if (it.second.find(arch) == it.second.end()) { |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | if (header.endswith("/" + it.first)) { |
| 139 | return true; |
| 140 | } |
| 141 | } |
| 142 | return false; |
| 143 | }); |
| 144 | |
| 145 | headers.erase(new_end, headers.end()); |
| 146 | |
| 147 | CompilationRequirements result = { .headers = headers, .dependencies = dependencies }; |
| 148 | return result; |
| 149 | } |
| 150 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 151 | static std::set<CompilationType> generateCompilationTypes(const std::set<Arch> selected_architectures, |
| 152 | const std::set<int>& selected_levels) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 153 | std::set<CompilationType> result; |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 154 | for (const auto& arch : selected_architectures) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 155 | int min_api = arch_min_api[arch]; |
| 156 | for (int api_level : selected_levels) { |
| 157 | if (api_level < min_api) { |
| 158 | continue; |
| 159 | } |
Josh Gao | a77b3a9 | 2016-08-15 16:39:27 -0700 | [diff] [blame] | 160 | |
| 161 | for (int file_offset_bits : { 32, 64 }) { |
| 162 | CompilationType type = { |
| 163 | .arch = arch, .api_level = api_level, .file_offset_bits = file_offset_bits |
| 164 | }; |
| 165 | result.insert(type); |
| 166 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | return result; |
| 170 | } |
| 171 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 172 | static std::unique_ptr<HeaderDatabase> compileHeaders(const std::set<CompilationType>& types, |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 173 | const HeaderLocationInformation& location) { |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 174 | if (types.empty()) { |
| 175 | errx(1, "compileHeaders received no CompilationTypes"); |
| 176 | } |
| 177 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 178 | auto vfs = createCommonVFS(location.header_dir, location.dependency_dir, add_include); |
Josh Gao | 78b8a14 | 2016-11-09 01:00:41 -0800 | [diff] [blame] | 179 | |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 180 | size_t thread_count = max_thread_count; |
| 181 | std::vector<std::thread> threads; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 182 | |
| 183 | std::map<CompilationType, HeaderDatabase> header_databases; |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 184 | std::unordered_map<Arch, CompilationRequirements> requirements; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 185 | |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 186 | auto result = std::make_unique<HeaderDatabase>(); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 187 | for (const auto& type : types) { |
| 188 | if (requirements.count(type.arch) == 0) { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 189 | requirements[type.arch] = collectRequirements(type.arch, location); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Josh Gao | 78b8a14 | 2016-11-09 01:00:41 -0800 | [diff] [blame] | 193 | initializeTargetCC1FlagCache(vfs, types, requirements); |
Josh Gao | b5c4963 | 2016-11-08 22:21:31 -0800 | [diff] [blame] | 194 | |
| 195 | std::vector<std::pair<CompilationType, const std::string&>> jobs; |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 196 | std::atomic<size_t> job_index(0); |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 197 | for (CompilationType type : types) { |
| 198 | CompilationRequirements& req = requirements[type.arch]; |
| 199 | for (const std::string& header : req.headers) { |
Josh Gao | b5c4963 | 2016-11-08 22:21:31 -0800 | [diff] [blame] | 200 | jobs.emplace_back(type, header); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 201 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Josh Gao | d2ab9ff | 2017-07-28 12:53:36 -0700 | [diff] [blame] | 204 | // Dup an empty file to stdin, so that we can use `clang -include a.h -` instead of `clang a.h`, |
| 205 | // since some warnings don't get generated in files that are compiled directly. |
| 206 | FILE* empty_file = tmpfile(); |
| 207 | if (!empty_file) { |
| 208 | err(1, "failed to create temporary file"); |
| 209 | } |
| 210 | |
| 211 | int empty_file_fd = fileno(empty_file); |
| 212 | if (empty_file_fd == -1) { |
| 213 | errx(1, "fileno failed on tmpfile"); |
| 214 | } |
| 215 | |
| 216 | dup2(empty_file_fd, STDIN_FILENO); |
| 217 | fclose(empty_file); |
| 218 | |
Josh Gao | b5c4963 | 2016-11-08 22:21:31 -0800 | [diff] [blame] | 219 | thread_count = std::min(thread_count, jobs.size()); |
| 220 | |
| 221 | if (thread_count == 1) { |
| 222 | for (const auto& job : jobs) { |
Josh Gao | 78b8a14 | 2016-11-09 01:00:41 -0800 | [diff] [blame] | 223 | compileHeader(vfs, result.get(), job.first, job.second); |
Josh Gao | b5c4963 | 2016-11-08 22:21:31 -0800 | [diff] [blame] | 224 | } |
| 225 | } else { |
| 226 | // Spawn threads. |
| 227 | for (size_t i = 0; i < thread_count; ++i) { |
Yi Kong | ff6c8de | 2017-04-20 09:08:11 -0700 | [diff] [blame] | 228 | threads.emplace_back([&jobs, &job_index, &result, vfs]() { |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 229 | while (true) { |
| 230 | size_t idx = job_index++; |
| 231 | if (idx >= jobs.size()) { |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | const auto& job = jobs[idx]; |
Josh Gao | 78b8a14 | 2016-11-09 01:00:41 -0800 | [diff] [blame] | 236 | compileHeader(vfs, result.get(), job.first, job.second); |
Josh Gao | b5c4963 | 2016-11-08 22:21:31 -0800 | [diff] [blame] | 237 | } |
| 238 | }); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Josh Gao | b5c4963 | 2016-11-08 22:21:31 -0800 | [diff] [blame] | 241 | // Reap them. |
| 242 | for (auto& thread : threads) { |
| 243 | thread.join(); |
| 244 | } |
| 245 | threads.clear(); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 248 | return result; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Josh Gao | 1a176de | 2016-11-04 13:15:11 -0700 | [diff] [blame] | 251 | static std::set<CompilationType> getCompilationTypes(const Declaration* decl) { |
| 252 | std::set<CompilationType> result; |
| 253 | for (const auto& it : decl->availability) { |
| 254 | result.insert(it.first); |
| 255 | } |
| 256 | return result; |
| 257 | } |
| 258 | |
| 259 | template<typename T> |
| 260 | static std::vector<T> Intersection(const std::set<T>& a, const std::set<T>& b) { |
| 261 | std::vector<T> intersection; |
| 262 | std::set_intersection(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(intersection)); |
| 263 | return intersection; |
| 264 | } |
| 265 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 266 | // Perform a sanity check on a symbol's declarations, enforcing the following invariants: |
| 267 | // 1. At most one inline definition of the function exists. |
| 268 | // 2. All of the availability declarations for a symbol are compatible. |
| 269 | // If a function is declared as an inline before a certain version, the inline definition |
| 270 | // should have no version tag. |
| 271 | // 3. Each availability type must only be present globally or on a per-arch basis. |
| 272 | // (e.g. __INTRODUCED_IN_ARM(9) __INTRODUCED_IN_X86(10) __DEPRECATED_IN(11) is fine, |
| 273 | // but not __INTRODUCED_IN(9) __INTRODUCED_IN_X86(10)) |
| 274 | static bool checkSymbol(const Symbol& symbol) { |
| 275 | std::string cwd = getWorkingDir() + "/"; |
| 276 | |
Josh Gao | 1a176de | 2016-11-04 13:15:11 -0700 | [diff] [blame] | 277 | std::unordered_map<const Declaration*, std::set<CompilationType>> inline_definitions; |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 278 | for (const auto& decl_it : symbol.declarations) { |
| 279 | const Declaration* decl = &decl_it.second; |
| 280 | if (decl->is_definition) { |
Josh Gao | 1a176de | 2016-11-04 13:15:11 -0700 | [diff] [blame] | 281 | std::set<CompilationType> compilation_types = getCompilationTypes(decl); |
| 282 | for (const auto& inline_def_it : inline_definitions) { |
| 283 | auto intersection = Intersection(compilation_types, inline_def_it.second); |
| 284 | if (!intersection.empty()) { |
| 285 | fprintf(stderr, "versioner: conflicting inline definitions:\n"); |
| 286 | fprintf(stderr, " declarations visible in: %s\n", Join(intersection, ", ").c_str()); |
| 287 | decl->dump(cwd, stderr, 4); |
| 288 | inline_def_it.first->dump(cwd, stderr, 4); |
| 289 | return false; |
| 290 | } |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Josh Gao | 1a176de | 2016-11-04 13:15:11 -0700 | [diff] [blame] | 293 | inline_definitions[decl] = std::move(compilation_types); |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | DeclarationAvailability availability; |
| 297 | if (!decl->calculateAvailability(&availability)) { |
| 298 | fprintf(stderr, "versioner: failed to calculate availability for declaration:\n"); |
Josh Gao | 566735d | 2016-08-02 15:07:32 -0700 | [diff] [blame] | 299 | decl->dump(cwd, stderr, 2); |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
| 303 | if (decl->is_definition && !availability.empty()) { |
| 304 | fprintf(stderr, "versioner: inline definition has non-empty versioning information:\n"); |
Josh Gao | 566735d | 2016-08-02 15:07:32 -0700 | [diff] [blame] | 305 | decl->dump(cwd, stderr, 2); |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 306 | return false; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | DeclarationAvailability availability; |
| 311 | if (!symbol.calculateAvailability(&availability)) { |
| 312 | fprintf(stderr, "versioner: inconsistent availability for symbol '%s'\n", symbol.name.c_str()); |
| 313 | symbol.dump(cwd); |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | // TODO: Check invariant #3. |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | static bool sanityCheck(const HeaderDatabase* database) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 322 | bool error = false; |
Josh Gao | 958f3b3 | 2016-06-03 13:44:00 -0700 | [diff] [blame] | 323 | std::string cwd = getWorkingDir() + "/"; |
| 324 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 325 | for (const auto& symbol_it : database->symbols) { |
| 326 | if (!checkSymbol(symbol_it.second)) { |
| 327 | error = true; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | return !error; |
| 331 | } |
| 332 | |
| 333 | // Check that our symbol availability declarations match the actual NDK |
| 334 | // platform symbol availability. |
| 335 | static bool checkVersions(const std::set<CompilationType>& types, |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 336 | const HeaderDatabase* header_database, |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 337 | const NdkSymbolDatabase& symbol_database) { |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 338 | std::string cwd = getWorkingDir() + "/"; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 339 | bool failed = false; |
| 340 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 341 | std::map<Arch, std::set<CompilationType>> arch_types; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 342 | for (const CompilationType& type : types) { |
| 343 | arch_types[type.arch].insert(type); |
| 344 | } |
| 345 | |
Josh Gao | d67dbf0 | 2016-06-02 15:21:14 -0700 | [diff] [blame] | 346 | std::set<std::string> completely_unavailable; |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 347 | std::map<std::string, std::set<CompilationType>> missing_availability; |
| 348 | std::map<std::string, std::set<CompilationType>> extra_availability; |
Josh Gao | d67dbf0 | 2016-06-02 15:21:14 -0700 | [diff] [blame] | 349 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 350 | for (const auto& symbol_it : header_database->symbols) { |
| 351 | const auto& symbol_name = symbol_it.first; |
| 352 | DeclarationAvailability symbol_availability; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 353 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 354 | if (!symbol_it.second.calculateAvailability(&symbol_availability)) { |
| 355 | errx(1, "failed to calculate symbol availability"); |
| 356 | } |
| 357 | |
| 358 | const auto platform_availability_it = symbol_database.find(symbol_name); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 359 | if (platform_availability_it == symbol_database.end()) { |
Josh Gao | d67dbf0 | 2016-06-02 15:21:14 -0700 | [diff] [blame] | 360 | completely_unavailable.insert(symbol_name); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 361 | continue; |
| 362 | } |
| 363 | |
| 364 | const auto& platform_availability = platform_availability_it->second; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 365 | |
| 366 | for (const CompilationType& type : types) { |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 367 | bool should_be_available = true; |
| 368 | const auto& global_availability = symbol_availability.global_availability; |
| 369 | const auto& arch_availability = symbol_availability.arch_availability[type.arch]; |
| 370 | if (global_availability.introduced != 0 && global_availability.introduced > type.api_level) { |
| 371 | should_be_available = false; |
| 372 | } |
| 373 | |
| 374 | if (arch_availability.introduced != 0 && arch_availability.introduced > type.api_level) { |
| 375 | should_be_available = false; |
| 376 | } |
| 377 | |
| 378 | if (global_availability.obsoleted != 0 && global_availability.obsoleted <= type.api_level) { |
| 379 | should_be_available = false; |
| 380 | } |
| 381 | |
| 382 | if (arch_availability.obsoleted != 0 && arch_availability.obsoleted <= type.api_level) { |
| 383 | should_be_available = false; |
| 384 | } |
| 385 | |
| 386 | if (arch_availability.future) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 387 | continue; |
| 388 | } |
| 389 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 390 | // The function declaration might be (validly) missing for the given CompilationType. |
| 391 | if (!symbol_it.second.hasDeclaration(type)) { |
| 392 | should_be_available = false; |
| 393 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 394 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 395 | bool is_available = platform_availability.count(type); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 396 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 397 | if (should_be_available != is_available) { |
| 398 | if (is_available) { |
| 399 | extra_availability[symbol_name].insert(type); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 400 | } else { |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 401 | missing_availability[symbol_name].insert(type); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | } |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 405 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 406 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 407 | for (const auto& it : symbol_database) { |
| 408 | const std::string& symbol_name = it.first; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 409 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 410 | bool symbol_error = false; |
Josh Gao | 0a284f5 | 2016-12-15 13:56:00 -0800 | [diff] [blame] | 411 | if (auto missing_it = missing_availability.find(symbol_name); |
| 412 | missing_it != missing_availability.end()) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 413 | printf("%s: declaration marked available but symbol missing in [%s]\n", symbol_name.c_str(), |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 414 | Join(missing_it->second, ", ").c_str()); |
| 415 | symbol_error = true; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 416 | failed = true; |
| 417 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 418 | |
Josh Gao | acc3d80 | 2016-11-09 18:22:44 -0800 | [diff] [blame] | 419 | if (strict) { |
Josh Gao | 0a284f5 | 2016-12-15 13:56:00 -0800 | [diff] [blame] | 420 | if (auto extra_it = extra_availability.find(symbol_name); |
| 421 | extra_it != extra_availability.end()) { |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 422 | printf("%s: declaration marked unavailable but symbol available in [%s]\n", |
| 423 | symbol_name.c_str(), Join(extra_it->second, ", ").c_str()); |
| 424 | symbol_error = true; |
| 425 | failed = true; |
Josh Gao | 958f3b3 | 2016-06-03 13:44:00 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 429 | if (symbol_error) { |
Josh Gao | 0a284f5 | 2016-12-15 13:56:00 -0800 | [diff] [blame] | 430 | if (auto symbol_it = header_database->symbols.find(symbol_name); |
| 431 | symbol_it != header_database->symbols.end()) { |
| 432 | symbol_it->second.dump(cwd); |
| 433 | } else { |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 434 | errx(1, "failed to find symbol in header database"); |
| 435 | } |
Josh Gao | d67dbf0 | 2016-06-02 15:21:14 -0700 | [diff] [blame] | 436 | } |
Josh Gao | d67dbf0 | 2016-06-02 15:21:14 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 439 | // TODO: Verify that function/variable declarations are actually function/variable symbols. |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 440 | return !failed; |
| 441 | } |
| 442 | |
Josh Gao | 62aaf8f | 2016-06-02 14:27:21 -0700 | [diff] [blame] | 443 | static void usage(bool help = false) { |
| 444 | fprintf(stderr, "Usage: versioner [OPTION]... [HEADER_PATH] [DEPS_PATH]\n"); |
| 445 | if (!help) { |
| 446 | printf("Try 'versioner -h' for more information.\n"); |
| 447 | exit(1); |
| 448 | } else { |
| 449 | fprintf(stderr, "Version headers at HEADER_PATH, with DEPS_PATH/ARCH/* on the include path\n"); |
Josh Gao | 9b5af7a | 2016-06-02 14:29:13 -0700 | [diff] [blame] | 450 | fprintf(stderr, "Autodetects paths if HEADER_PATH and DEPS_PATH are not specified\n"); |
Josh Gao | 62aaf8f | 2016-06-02 14:27:21 -0700 | [diff] [blame] | 451 | fprintf(stderr, "\n"); |
| 452 | fprintf(stderr, "Target specification (defaults to all):\n"); |
| 453 | fprintf(stderr, " -a API_LEVEL\tbuild with specified API level (can be repeated)\n"); |
Josh Gao | 35aa213 | 2017-10-24 17:05:49 -0700 | [diff] [blame^] | 454 | fprintf(stderr, " \t\tdefaults to %s\n", Join(default_levels).c_str()); |
Josh Gao | 62aaf8f | 2016-06-02 14:27:21 -0700 | [diff] [blame] | 455 | fprintf(stderr, " -r ARCH\tbuild with specified architecture (can be repeated)\n"); |
| 456 | fprintf(stderr, " \t\tvalid architectures are %s\n", Join(supported_archs).c_str()); |
| 457 | fprintf(stderr, "\n"); |
| 458 | fprintf(stderr, "Validation:\n"); |
| 459 | fprintf(stderr, " -p PATH\tcompare against NDK platform at PATH\n"); |
Josh Gao | acc3d80 | 2016-11-09 18:22:44 -0800 | [diff] [blame] | 460 | fprintf(stderr, " -s\t\tenable strict warnings\n"); |
Josh Gao | 62aaf8f | 2016-06-02 14:27:21 -0700 | [diff] [blame] | 461 | fprintf(stderr, "\n"); |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 462 | fprintf(stderr, "Preprocessing:\n"); |
| 463 | fprintf(stderr, " -o PATH\tpreprocess header files and emit them at PATH\n"); |
Josh Gao | d744a9b | 2017-04-03 11:24:48 -0700 | [diff] [blame] | 464 | fprintf(stderr, " -f\t\tpreprocess header files even if validation fails\n"); |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 465 | fprintf(stderr, "\n"); |
Josh Gao | 62aaf8f | 2016-06-02 14:27:21 -0700 | [diff] [blame] | 466 | fprintf(stderr, "Miscellaneous:\n"); |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 467 | fprintf(stderr, " -F\t\tdo not ignore FORTIFY headers by default\n"); |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 468 | fprintf(stderr, " -d\t\tdump function availability\n"); |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 469 | fprintf(stderr, " -j THREADS\tmaximum number of threads to use\n"); |
Josh Gao | acc3d80 | 2016-11-09 18:22:44 -0800 | [diff] [blame] | 470 | fprintf(stderr, " -v\t\tenable verbose logging\n"); |
Josh Gao | 62aaf8f | 2016-06-02 14:27:21 -0700 | [diff] [blame] | 471 | fprintf(stderr, " -h\t\tdisplay this message\n"); |
| 472 | exit(0); |
| 473 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Andreas Gampe | d10d3ee | 2017-04-28 19:32:13 -0700 | [diff] [blame] | 476 | // versioner uses a prebuilt version of clang, which is not up-to-date wrt/ |
| 477 | // container annotations. So disable container overflow checking. b/37775238 |
| 478 | extern "C" const char* __asan_default_options() { |
| 479 | return "detect_container_overflow=0"; |
| 480 | } |
| 481 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 482 | int main(int argc, char** argv) { |
| 483 | std::string cwd = getWorkingDir() + "/"; |
| 484 | bool default_args = true; |
| 485 | std::string platform_dir; |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 486 | std::set<Arch> selected_architectures; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 487 | std::set<int> selected_levels; |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 488 | std::string preprocessor_output_path; |
| 489 | bool force = false; |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 490 | bool dump = false; |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 491 | bool ignore_fortify_headers = true; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 492 | |
| 493 | int c; |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 494 | while ((c = getopt(argc, argv, "a:r:p:so:fdj:vhFi")) != -1) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 495 | default_args = false; |
| 496 | switch (c) { |
| 497 | case 'a': { |
| 498 | char* end; |
| 499 | int api_level = strtol(optarg, &end, 10); |
| 500 | if (end == optarg || strlen(end) > 0) { |
| 501 | usage(); |
| 502 | } |
| 503 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 504 | selected_levels.insert(api_level); |
| 505 | break; |
| 506 | } |
| 507 | |
| 508 | case 'r': { |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 509 | Arch arch = arch_from_string(optarg); |
| 510 | selected_architectures.insert(arch); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 511 | break; |
| 512 | } |
| 513 | |
| 514 | case 'p': { |
| 515 | if (!platform_dir.empty()) { |
| 516 | usage(); |
| 517 | } |
| 518 | |
| 519 | platform_dir = optarg; |
| 520 | |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 521 | if (platform_dir.empty()) { |
| 522 | usage(); |
| 523 | } |
| 524 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 525 | struct stat st; |
| 526 | if (stat(platform_dir.c_str(), &st) != 0) { |
| 527 | err(1, "failed to stat platform directory '%s'", platform_dir.c_str()); |
| 528 | } |
| 529 | if (!S_ISDIR(st.st_mode)) { |
| 530 | errx(1, "'%s' is not a directory", optarg); |
| 531 | } |
| 532 | break; |
| 533 | } |
| 534 | |
Josh Gao | acc3d80 | 2016-11-09 18:22:44 -0800 | [diff] [blame] | 535 | case 's': |
| 536 | strict = true; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 537 | break; |
| 538 | |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 539 | case 'o': |
| 540 | if (!preprocessor_output_path.empty()) { |
| 541 | usage(); |
| 542 | } |
| 543 | preprocessor_output_path = optarg; |
| 544 | if (preprocessor_output_path.empty()) { |
| 545 | usage(); |
| 546 | } |
| 547 | break; |
| 548 | |
| 549 | case 'f': |
| 550 | force = true; |
| 551 | break; |
| 552 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 553 | case 'd': |
| 554 | dump = true; |
| 555 | break; |
| 556 | |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 557 | case 'j': |
| 558 | if (!android::base::ParseInt<int>(optarg, &max_thread_count, 1)) { |
| 559 | usage(); |
| 560 | } |
| 561 | break; |
| 562 | |
Josh Gao | acc3d80 | 2016-11-09 18:22:44 -0800 | [diff] [blame] | 563 | case 'v': |
| 564 | verbose = true; |
| 565 | break; |
| 566 | |
Josh Gao | 62aaf8f | 2016-06-02 14:27:21 -0700 | [diff] [blame] | 567 | case 'h': |
| 568 | usage(true); |
| 569 | break; |
| 570 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 571 | case 'i': |
| 572 | // Secret option for tests to -include <android/versioning.h>. |
| 573 | add_include = true; |
| 574 | break; |
| 575 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 576 | case 'F': |
| 577 | ignore_fortify_headers = false; |
| 578 | break; |
| 579 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 580 | default: |
| 581 | usage(); |
| 582 | break; |
| 583 | } |
| 584 | } |
| 585 | |
Josh Gao | 9b5af7a | 2016-06-02 14:29:13 -0700 | [diff] [blame] | 586 | if (argc - optind > 2 || optind > argc) { |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 587 | usage(); |
| 588 | } |
| 589 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 590 | HeaderLocationInformation location; |
Josh Gao | 9b5af7a | 2016-06-02 14:29:13 -0700 | [diff] [blame] | 591 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 592 | const char* top = getenv("ANDROID_BUILD_TOP"); |
| 593 | if (!top && (optind == argc || add_include)) { |
| 594 | fprintf(stderr, "versioner: failed to autodetect bionic paths. Is ANDROID_BUILD_TOP set?\n"); |
| 595 | usage(); |
| 596 | } |
| 597 | |
Josh Gao | 9b5af7a | 2016-06-02 14:29:13 -0700 | [diff] [blame] | 598 | if (optind == argc) { |
| 599 | // Neither HEADER_PATH nor DEPS_PATH were specified, so try to figure them out. |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 600 | std::string versioner_dir = to_string(top) + "/bionic/tools/versioner"; |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 601 | location.header_dir = versioner_dir + "/current"; |
| 602 | location.dependency_dir = versioner_dir + "/dependencies"; |
Josh Gao | 9b5af7a | 2016-06-02 14:29:13 -0700 | [diff] [blame] | 603 | if (platform_dir.empty()) { |
| 604 | platform_dir = versioner_dir + "/platforms"; |
| 605 | } |
| 606 | } else { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 607 | if (!android::base::Realpath(argv[optind], &location.header_dir)) { |
Josh Gao | b50b8c8 | 2017-04-27 17:22:52 -0700 | [diff] [blame] | 608 | err(1, "failed to get realpath for path '%s'", argv[optind]); |
| 609 | } |
Josh Gao | 9b5af7a | 2016-06-02 14:29:13 -0700 | [diff] [blame] | 610 | |
| 611 | if (argc - optind == 2) { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 612 | location.dependency_dir = argv[optind + 1]; |
Josh Gao | 9b5af7a | 2016-06-02 14:29:13 -0700 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 616 | // Every file that lives in bits/fortify is logically a part of a header outside of bits/fortify. |
| 617 | // This makes the files there impossible to build on their own. |
| 618 | if (ignore_fortify_headers) { |
| 619 | std::string fortify_path = location.header_dir; |
| 620 | if (!android::base::EndsWith(location.header_dir, "/")) { |
| 621 | fortify_path += '/'; |
| 622 | } |
| 623 | fortify_path += "bits/fortify"; |
| 624 | location.ignored_directories.insert(std::move(fortify_path)); |
| 625 | } |
| 626 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 627 | if (selected_levels.empty()) { |
Josh Gao | 35aa213 | 2017-10-24 17:05:49 -0700 | [diff] [blame^] | 628 | selected_levels = default_levels; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | if (selected_architectures.empty()) { |
| 632 | selected_architectures = supported_archs; |
| 633 | } |
| 634 | |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 635 | |
| 636 | struct stat st; |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 637 | if (const char *dir = location.header_dir.c_str(); stat(dir, &st) != 0) { |
| 638 | err(1, "failed to stat '%s'", dir); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 639 | } else if (!S_ISDIR(st.st_mode)) { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 640 | errx(1, "'%s' is not a directory", dir); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | std::set<CompilationType> compilation_types; |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 644 | NdkSymbolDatabase symbol_database; |
| 645 | |
| 646 | compilation_types = generateCompilationTypes(selected_architectures, selected_levels); |
| 647 | |
| 648 | // Do this before compiling so that we can early exit if the platforms don't match what we |
| 649 | // expect. |
| 650 | if (!platform_dir.empty()) { |
| 651 | symbol_database = parsePlatforms(compilation_types, platform_dir); |
| 652 | } |
| 653 | |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 654 | auto start = std::chrono::high_resolution_clock::now(); |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 655 | std::unique_ptr<HeaderDatabase> declaration_database = |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 656 | compileHeaders(compilation_types, location); |
Josh Gao | 338cf12 | 2016-11-09 18:01:41 -0800 | [diff] [blame] | 657 | auto end = std::chrono::high_resolution_clock::now(); |
| 658 | |
| 659 | if (verbose) { |
| 660 | auto diff = (end - start) / 1.0ms; |
| 661 | printf("Compiled headers for %zu targets in %0.2LFms\n", compilation_types.size(), diff); |
| 662 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 663 | |
Josh Gao | 16016df | 2016-11-07 18:27:16 -0800 | [diff] [blame] | 664 | bool failed = false; |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 665 | if (dump) { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 666 | declaration_database->dump(location.header_dir + "/"); |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 667 | } else { |
| 668 | if (!sanityCheck(declaration_database.get())) { |
| 669 | printf("versioner: sanity check failed\n"); |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 670 | failed = true; |
| 671 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 672 | |
Josh Gao | bfb6bae | 2016-07-15 17:25:21 -0700 | [diff] [blame] | 673 | if (!platform_dir.empty()) { |
| 674 | if (!checkVersions(compilation_types, declaration_database.get(), symbol_database)) { |
| 675 | printf("versioner: version check failed\n"); |
| 676 | failed = true; |
| 677 | } |
| 678 | } |
| 679 | } |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 680 | |
| 681 | if (!preprocessor_output_path.empty() && (force || !failed)) { |
George Burgess IV | b97049c | 2017-07-24 15:05:05 -0700 | [diff] [blame] | 682 | failed = !preprocessHeaders(preprocessor_output_path, location.header_dir, declaration_database.get()); |
Josh Gao | f8592a3 | 2016-07-26 18:58:27 -0700 | [diff] [blame] | 683 | } |
Josh Gao | bf8a285 | 2016-05-27 11:59:09 -0700 | [diff] [blame] | 684 | return failed; |
| 685 | } |