From 3c5d03adab1cc0acfbb8218c0f53ca855e70ef2f Mon Sep 17 00:00:00 2001 From: Hsin-Yi Chen Date: Tue, 14 Apr 2020 17:26:12 +0800 Subject: [PATCH] Filter ABI if exported include dir is specified. The ABI dumper used to disable filtering ABI when no header file is found in the exported include dirs. The output content depends on the existence of the header files. This commit makes the dumper decide the filtering by the command line arguments. If at least one exported include dir is specifed, the dumper filters the ABI, so that it produces consistent output in an environment where some usused header files don't exist. Test: development/vndk/tools/header-checker/tests/test.py Bug: 153926507 Change-Id: I5c1fd1e74554d875554b4908c9caaf28b9e73236 --- .../header-checker/src/dumper/ast_processing.cpp | 14 +++----------- .../header-checker/src/dumper/header_checker.cpp | 10 +++++----- .../header-checker/src/dumper/header_checker.h | 7 ++++--- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/vndk/tools/header-checker/src/dumper/ast_processing.cpp b/vndk/tools/header-checker/src/dumper/ast_processing.cpp index 43df29dd2..2bc90d181 100644 --- a/vndk/tools/header-checker/src/dumper/ast_processing.cpp +++ b/vndk/tools/header-checker/src/dumper/ast_processing.cpp @@ -156,10 +156,6 @@ bool HeaderASTVisitor::VisitVarDecl(const clang::VarDecl *decl) { return global_var_decl_wrapper.GetGlobalVarDecl(); } -static bool AreHeadersExported(const std::set &exported_headers) { - return !exported_headers.empty(); -} - // We don't need to recurse into Declarations which are not exported. bool HeaderASTVisitor::TraverseDecl(clang::Decl *decl) { if (!decl) { @@ -170,7 +166,8 @@ bool HeaderASTVisitor::TraverseDecl(clang::Decl *decl) { std::make_pair(decl, source_file)); // If no exported headers are specified we assume the whole AST is exported. const auto &exported_headers = options_.exported_headers_; - if ((decl != tu_decl_) && AreHeadersExported(exported_headers) && + if ((decl != tu_decl_) && options_.dump_exported_only_ && + source_file != ast_caches_->translation_unit_source_ && (exported_headers.find(source_file) == exported_headers.end())) { return true; } @@ -198,12 +195,7 @@ void HeaderASTConsumer::HandleTranslationUnit(clang::ASTContext &ctx) { clang::TranslationUnitDecl *translation_unit = ctx.getTranslationUnitDecl(); std::unique_ptr mangle_contextp( ctx.createMangleContext()); - const std::string &translation_unit_source = - ABIWrapper::GetDeclSourceFile(translation_unit, cip_); - ASTCaches ast_caches(translation_unit_source); - if (!options_.exported_headers_.empty()) { - options_.exported_headers_.insert(translation_unit_source); - } + ASTCaches ast_caches(ABIWrapper::GetDeclSourceFile(translation_unit, cip_)); std::unique_ptr module( new repr::ModuleIR(nullptr /*FIXME*/)); diff --git a/vndk/tools/header-checker/src/dumper/header_checker.cpp b/vndk/tools/header-checker/src/dumper/header_checker.cpp index f856f2c2c..ea98ecf91 100644 --- a/vndk/tools/header-checker/src/dumper/header_checker.cpp +++ b/vndk/tools/header-checker/src/dumper/header_checker.cpp @@ -128,16 +128,16 @@ int main(int argc, const char **argv) { ::exit(1); } - std::set exported_headers; - if (!no_filter) { - exported_headers = CollectAllExportedHeaders(exported_header_dirs); - } + bool dump_exported_only = (!no_filter && !exported_header_dirs.empty()); + std::set exported_headers = + CollectAllExportedHeaders(exported_header_dirs); // Initialize clang tools and run front-end action. std::vector header_files{ header_file }; HeaderCheckerOptions options(RealPath(header_file), out_dump, std::move(exported_headers), output_format, - dump_function_declarations, suppress_errors); + dump_exported_only, dump_function_declarations, + suppress_errors); clang::tooling::ClangTool tool(*compilations, header_files); std::unique_ptr factory( diff --git a/vndk/tools/header-checker/src/dumper/header_checker.h b/vndk/tools/header-checker/src/dumper/header_checker.h index 6acd59628..4ec86c62d 100644 --- a/vndk/tools/header-checker/src/dumper/header_checker.h +++ b/vndk/tools/header-checker/src/dumper/header_checker.h @@ -29,19 +29,20 @@ class HeaderCheckerOptions { public: std::string source_file_; std::string dump_name_; - std::set exported_headers_; + const std::set exported_headers_; repr::TextFormatIR text_format_; + const bool dump_exported_only_; bool dump_function_declarations_; bool suppress_errors_; public: HeaderCheckerOptions(std::string source_file, std::string dump_name, std::set exported_headers, - repr::TextFormatIR text_format, + repr::TextFormatIR text_format, bool dump_exported_only, bool dump_function_declarations, bool suppress_errors) : source_file_(std::move(source_file)), dump_name_(std::move(dump_name)), exported_headers_(std::move(exported_headers)), - text_format_(text_format), + text_format_(text_format), dump_exported_only_(dump_exported_only), dump_function_declarations_(dump_function_declarations), suppress_errors_(suppress_errors) {} };