1 // Copyright (C) 2016 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "abi_diff.h" 16 17 #include <llvm/Support/CommandLine.h> 18 #include <llvm/Support/FileSystem.h> 19 #include <llvm/Support/raw_ostream.h> 20 21 static llvm::cl::OptionCategory header_checker_category( 22 "header-abi-diff options"); 23 24 static llvm::cl::opt<std::string> compatibility_report( 25 "o", llvm::cl::desc("<compatibility report>"), llvm::cl::Required, 26 llvm::cl::cat(header_checker_category)); 27 28 static llvm::cl::opt<std::string> lib_name( 29 "lib", llvm::cl::desc("<lib name>"), llvm::cl::Required, 30 llvm::cl::cat(header_checker_category)); 31 32 static llvm::cl::opt<std::string> arch( 33 "arch", llvm::cl::desc("<arch>"), llvm::cl::Required, 34 llvm::cl::cat(header_checker_category)); 35 36 static llvm::cl::opt<std::string> new_dump( 37 "new", llvm::cl::desc("<new dump>"), llvm::cl::Required, 38 llvm::cl::cat(header_checker_category)); 39 40 static llvm::cl::opt<std::string> old_dump( 41 "old", llvm::cl::desc("<old dump>"), llvm::cl::Required, 42 llvm::cl::cat(header_checker_category)); 43 44 static llvm::cl::opt<std::string> ignore_symbol_list( 45 "ignore-symbols", llvm::cl::desc("ignore symbols"), llvm::cl::Optional, 46 llvm::cl::cat(header_checker_category)); 47 48 static llvm::cl::opt<bool> advice_only( 49 "advice-only", llvm::cl::desc("Advisory mode only"), llvm::cl::Optional, 50 llvm::cl::cat(header_checker_category)); 51 52 static llvm::cl::opt<bool> suppress_local_warnings( 53 "suppress_local_warnings", llvm::cl::desc("suppress local warnings"), 54 llvm::cl::Optional, llvm::cl::cat(header_checker_category)); 55 56 static llvm::cl::opt<bool> allow_extensions( 57 "allow-extensions", 58 llvm::cl::desc("Do not return a non zero status on extensions"), 59 llvm::cl::Optional, llvm::cl::cat(header_checker_category)); 60 61 static std::set<std::string> LoadIgnoredSymbols(std::string &symbol_list_path) { 62 std::ifstream symbol_ifstream(symbol_list_path); 63 std::set<std::string> ignored_symbols; 64 if (!symbol_ifstream) { 65 llvm::errs() << "Failed to open file containing symbols to ignore\n"; 66 ::exit(1); 67 } 68 std::string line = ""; 69 while (std::getline(symbol_ifstream, line)) { 70 ignored_symbols.insert(line); 71 } 72 return ignored_symbols; 73 } 74 75 int main(int argc, const char **argv) { 76 GOOGLE_PROTOBUF_VERIFY_VERSION; 77 llvm::cl::ParseCommandLineOptions(argc, argv, "header-checker"); 78 std::set<std::string> ignored_symbols; 79 if (llvm::sys::fs::exists(ignore_symbol_list)) { 80 ignored_symbols = LoadIgnoredSymbols(ignore_symbol_list); 81 } 82 HeaderAbiDiff judge(lib_name, arch, old_dump, new_dump, compatibility_report, 83 ignored_symbols); 84 85 CompatibilityStatus status = judge.GenerateCompatibilityReport(); 86 87 std::string status_str = ""; 88 switch (status) { 89 case CompatibilityStatus::INCOMPATIBLE: 90 status_str = "broken"; 91 break; 92 case CompatibilityStatus::EXTENSION: 93 status_str = "extended"; 94 break; 95 default: 96 break; 97 } 98 99 if (!suppress_local_warnings && status) { 100 llvm::errs() << "******************************************************\n" 101 << "VNDK Abi " 102 << status_str 103 << ":" 104 << " Please check compatiblity report at : " 105 << compatibility_report << "\n" 106 << "*****************************************************\n"; 107 } 108 109 if (advice_only) { 110 return CompatibilityStatus::COMPATIBLE; 111 } 112 113 if (allow_extensions && status == CompatibilityStatus::EXTENSION) { 114 return CompatibilityStatus::COMPATIBLE; 115 } 116 return status; 117 } 118