Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Add option to parse version script during linking."
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Apr 13, 2017
2 parents 2f38d23 + 0f82afe commit 2802d06
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 90 deletions.
27 changes: 27 additions & 0 deletions vndk/tools/header-checker/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ cc_defaults {

shared_libs: [
"libprotobuf-cpp-full",
"libheader-abi-util",
],
}

Expand Down Expand Up @@ -129,6 +130,10 @@ cc_binary_host {
"libheader-checker-proto",
],

shared_libs: [
"libheader-abi-util",
],

target: {
linux: {
host_ldlibs: [
Expand Down Expand Up @@ -208,3 +213,25 @@ cc_binary_host {
},
},
}

cc_library_shared {
name: "libheader-abi-util",
defaults: [
"header-checker-defaults",
],
host_supported: true,
export_include_dirs: ["header-abi-util/include"],
local_include_dirs: ["header-abi-util/include"],

srcs: [
"header-abi-util/src/*.cpp"
],
static_libs: [
"libLLVMSupport",
],
cflags: [
"-Wcast-qual",
"-Wno-long-long",
"-Wno-unused-parameter",
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static bool Diff(const T &old_element, const T &new_element) {

template <>
bool Diff<EnumFieldDecl>(const EnumFieldDecl &old_element,
const EnumFieldDecl &new_element) {
const EnumFieldDecl &new_element) {
// Can be specialized for future changes in the format.
return DiffBasicTypeAbi(old_element.basic_abi().type_abi(),
new_element.basic_abi().type_abi()) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ static llvm::cl::opt<std::string> old_dump(
"old", llvm::cl::desc("<old dump>"), llvm::cl::Required,
llvm::cl::cat(header_checker_category));

static llvm::cl::opt<bool> advice_only(
"advice-only", llvm::cl::desc("Advisory mode only"), llvm::cl::Optional,
llvm::cl::cat(header_checker_category));

int main(int argc, const char **argv) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
llvm::cl::ParseCommandLineOptions(argc, argv, "header-checker");
Expand All @@ -53,6 +57,9 @@ int main(int argc, const char **argv) {
<< " Please check compatiblity report at : "
<< compatibility_report << "\n"
<< "*****************************************************\n";
if (!advice_only) {
return extension_or_incompatible;
}
}
return extension_or_incompatible;
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,18 @@ bool HeaderASTVisitor::VisitVarDecl(const clang::VarDecl *decl) {
return true;
}

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) {
return true;
}
std::string source_file = ABIWrapper::GetDeclSourceFile(decl, cip_);
if ((decl != tu_decl_) &&
// If no exported headers are specified we assume the whole AST is exported.
if ((decl != tu_decl_) && !AreHeadersExported(exported_headers_) &&
(exported_headers_.find(source_file) == exported_headers_.end())) {
return true;
}
Expand Down Expand Up @@ -167,10 +172,6 @@ void HeaderASTConsumer::HandleTranslationUnit(clang::ASTContext &ctx) {
}
}

void HeaderASTConsumer::HandleVTable(clang::CXXRecordDecl *crd) {
llvm::errs() << "HandleVTable: " << crd->getName() << "\n";
}

void HeaderASTPPCallbacks::MacroDefined(const clang::Token &macro_name_tok,
const clang::MacroDirective *) {
assert(macro_name_tok.getLength() != 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class HeaderASTConsumer : public clang::ASTConsumer {

void HandleTranslationUnit(clang::ASTContext &ctx) override;

void HandleVTable(clang::CXXRecordDecl *crd) override;

private:
std::string file_name_;
clang::CompilerInstance *cip_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "frontend_action.h"

#include "ast_processing.h"
#include "frontend_action.h"
#include <header_abi_util.h>

#include <clang/AST/ASTConsumer.h>
#include <clang/Frontend/CompilerInstance.h>
Expand All @@ -35,7 +36,7 @@ HeaderCheckerFrontendAction::CreateASTConsumer(clang::CompilerInstance &ci,
pp.addPPCallbacks(llvm::make_unique<HeaderASTPPCallbacks>());
std::set<std::string> exported_headers;
for (auto &&dir_name : export_header_dirs_) {
if (!CollectExportedHeaderSet(dir_name, &exported_headers)) {
if (!abi_util::CollectExportedHeaderSet(dir_name, &exported_headers)) {
return nullptr;
}
}
Expand All @@ -44,55 +45,3 @@ HeaderCheckerFrontendAction::CreateASTConsumer(clang::CompilerInstance &ci,
&ci, dump_name_,
exported_headers);
}

static bool ShouldSkipFile(llvm::StringRef &file_name) {
return (file_name.empty() || file_name.startswith(".") ||
file_name.endswith(".swp") || file_name.endswith(".swo") ||
file_name.endswith("#") || file_name.endswith(".cpp") ||
file_name.endswith(".cc") || file_name.endswith(".c"));
}

bool HeaderCheckerFrontendAction::CollectExportedHeaderSet(
const std::string &dir_name,
std::set<std::string> *exported_headers) {
std::error_code ec;
llvm::sys::fs::recursive_directory_iterator walker(dir_name, ec);
// Default construction - end of directory.
llvm::sys::fs::recursive_directory_iterator end;
llvm::sys::fs::file_status status;
for ( ; walker != end; walker.increment(ec)) {
if (ec) {
llvm::errs() << "Failed to walk dir : " << dir_name << "\n";
return false;
}

const std::string &file_path = walker->path();

llvm::StringRef file_name(llvm::sys::path::filename(file_path));
// Ignore swap files and hidden files / dirs. Do not recurse into them too.
// We should also not look at source files. Many projects include source
// files in their exports.
if (ShouldSkipFile(file_name)) {
walker.no_push();
continue;
}

if (walker->status(status)) {
llvm::errs() << "Failed to stat file : " << file_path << "\n";
return false;
}

if (!llvm::sys::fs::is_regular_file(status)) {
// Ignore non regular files. eg: soft links.
continue;
}

llvm::SmallString<128> abs_path(file_path);
if (llvm::sys::fs::make_absolute(abs_path)) {
llvm::errs() << "Failed to get absolute path for : " << file_name << "\n";
return false;
}
exported_headers->insert(abs_path.str());
}
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class HeaderCheckerFrontendAction : public clang::ASTFrontendAction {
protected:
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
clang::CompilerInstance &ci, llvm::StringRef header_file) override;

private:
bool CollectExportedHeaderSet(
const std::string &dir_name,
std::set<std::string> *eh);
};

#endif // FRONTEND_ACTION_H_
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static llvm::cl::opt<std::string> out_dump(
llvm::cl::cat(header_checker_category));

static llvm::cl::list<std::string> exported_header_dirs(
"I", llvm::cl::desc("<export_include_dirs>"), llvm::cl::OneOrMore,
"I", llvm::cl::desc("<export_include_dirs>"), llvm::cl::ZeroOrMore,
llvm::cl::cat(header_checker_category));

// Hide irrelevant command line options defined in LLVM libraries.
Expand Down

0 comments on commit 2802d06

Please sign in to comment.