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
This commit is contained in:
Hsin-Yi Chen
2020-04-14 17:26:12 +08:00
parent 8833757764
commit 3c5d03adab
3 changed files with 12 additions and 19 deletions

View File

@@ -156,10 +156,6 @@ bool HeaderASTVisitor::VisitVarDecl(const clang::VarDecl *decl) {
return global_var_decl_wrapper.GetGlobalVarDecl();
}
static bool AreHeadersExported(const std::set<std::string> &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<clang::MangleContext> 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<repr::ModuleIR> module(
new repr::ModuleIR(nullptr /*FIXME*/));

View File

@@ -128,16 +128,16 @@ int main(int argc, const char **argv) {
::exit(1);
}
std::set<std::string> exported_headers;
if (!no_filter) {
exported_headers = CollectAllExportedHeaders(exported_header_dirs);
}
bool dump_exported_only = (!no_filter && !exported_header_dirs.empty());
std::set<std::string> exported_headers =
CollectAllExportedHeaders(exported_header_dirs);
// Initialize clang tools and run front-end action.
std::vector<std::string> 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<clang::tooling::FrontendActionFactory> factory(

View File

@@ -29,19 +29,20 @@ class HeaderCheckerOptions {
public:
std::string source_file_;
std::string dump_name_;
std::set<std::string> exported_headers_;
const std::set<std::string> 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<std::string> 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) {}
};