Skip to content

Commit 134adad

Browse files
Jayant ChowdharyGerrit Code Review
authored andcommitted
Merge "Allow symlinks to be included while collecting exported headers."
2 parents 4437c89 + 367427e commit 134adad

File tree

9 files changed

+33
-32
lines changed

9 files changed

+33
-32
lines changed

vndk/tools/header-checker/header-abi-dumper/src/abi_wrappers.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ std::string ABIWrapper::GetDeclSourceFile(const clang::Decl *decl,
6161
// belonging to the library.
6262
clang::SourceLocation expansion_location = sm.getExpansionLoc(location);
6363
llvm::StringRef file_name = sm.getFilename(expansion_location);
64-
std::string file_name_adjusted = "";
65-
char file_abs_path[PATH_MAX];
66-
if (realpath(file_name.str().c_str(), file_abs_path) == nullptr) {
67-
return "";
68-
}
69-
return file_abs_path;
64+
return abi_util::RealPath(file_name.str());
7065
}
7166

7267
static abi_util::AccessSpecifierIR AccessClangToIR(

vndk/tools/header-checker/header-abi-dumper/src/ast_processing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class HeaderASTConsumer : public clang::ASTConsumer {
8787
std::string file_name_;
8888
clang::CompilerInstance *cip_;
8989
std::string out_dump_name_;
90-
std::set<std::string> exported_headers_;
90+
const std::set<std::string> &exported_headers_;
9191
};
9292

9393
#endif // AST_PROCESSING_H_

vndk/tools/header-checker/header-abi-dumper/src/frontend_action.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@
2525
#include <llvm/Support/Path.h>
2626

2727
HeaderCheckerFrontendAction::HeaderCheckerFrontendAction(
28-
const std::string &dump_name, const std::vector<std::string> &exports)
29-
: dump_name_(dump_name), exported_header_dirs_(exports) { }
28+
const std::string &dump_name, const std::set<std::string> &exported_headers)
29+
: dump_name_(dump_name), exported_headers_(exported_headers) { }
3030

3131
std::unique_ptr<clang::ASTConsumer>
3232
HeaderCheckerFrontendAction::CreateASTConsumer(clang::CompilerInstance &ci,
3333
llvm::StringRef header_file) {
34-
std::set<std::string> exported_headers;
35-
exported_headers = abi_util::CollectAllExportedHeaders(exported_header_dirs_);
3634
// Create AST consumers.
37-
return llvm::make_unique<HeaderASTConsumer>(header_file,
38-
&ci, dump_name_,
39-
exported_headers);
35+
return llvm::make_unique<HeaderASTConsumer>(header_file, &ci, dump_name_,
36+
exported_headers_);
4037
}

vndk/tools/header-checker/header-abi-dumper/src/frontend_action.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ namespace clang {
3131
class HeaderCheckerFrontendAction : public clang::ASTFrontendAction {
3232
private:
3333
std::string dump_name_;
34-
const std::vector<std::string> &exported_header_dirs_;
34+
const std::set<std::string> &exported_headers_;
3535

3636
public:
3737
HeaderCheckerFrontendAction(
3838
const std::string &dump_name,
39-
const std::vector<std::string> &export_header_dirs);
39+
const std::set<std::string> &exported_headers);
4040

4141
protected:
4242
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(

vndk/tools/header-checker/header-abi-dumper/src/frontend_action_factory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
HeaderCheckerFrontendActionFactory::HeaderCheckerFrontendActionFactory(
2222
const std::string &dump_name,
23-
const std::vector<std::string> &export_header_dirs)
24-
: dump_name_(dump_name), export_header_dirs_(export_header_dirs) { }
23+
const std::set<std::string> &exported_headers)
24+
: dump_name_(dump_name), exported_headers_(exported_headers) { }
2525

2626
clang::FrontendAction *HeaderCheckerFrontendActionFactory::create() {
27-
return new HeaderCheckerFrontendAction(dump_name_, export_header_dirs_);
27+
return new HeaderCheckerFrontendAction(dump_name_, exported_headers_);
2828
}

vndk/tools/header-checker/header-abi-dumper/src/frontend_action_factory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class HeaderCheckerFrontendActionFactory
2323
: public clang::tooling::FrontendActionFactory {
2424
private:
2525
std::string dump_name_;
26-
const std::vector<std::string> &export_header_dirs_;
26+
const std::set<std::string> &exported_headers_;
2727

2828
public:
2929
HeaderCheckerFrontendActionFactory(
3030
const std::string &dump_name,
31-
const std::vector<std::string> &exported_header_dirs);
31+
const std::set<std::string> &exported_headers);
3232

3333
clang::FrontendAction *create() override;
3434
};

vndk/tools/header-checker/header-abi-dumper/src/header_checker.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "frontend_action_factory.h"
16+
#include <header_abi_util.h>
1617

1718
#include <clang/Frontend/FrontendActions.h>
1819
#include <clang/Tooling/CommonOptionsParser.h>
@@ -96,16 +97,18 @@ int main(int argc, const char **argv) {
9697
::exit(1);
9798
}
9899

99-
if (no_filter) {
100-
static_cast<std::vector<std::string> &>(exported_header_dirs).clear();
100+
std::set<std::string> exported_headers;
101+
if (!no_filter) {
102+
exported_headers =
103+
abi_util::CollectAllExportedHeaders(exported_header_dirs);
101104
}
102105

103106
// Initialize clang tools and run front-end action.
104107
std::vector<std::string> header_files{ header_file };
105108

106109
clang::tooling::ClangTool tool(*compilations, header_files);
107110
std::unique_ptr<clang::tooling::FrontendActionFactory> factory(
108-
new HeaderCheckerFrontendActionFactory(out_dump, exported_header_dirs));
111+
new HeaderCheckerFrontendActionFactory(out_dump, exported_headers));
109112

110113
return tool.run(factory.get());
111114
}

vndk/tools/header-checker/header-abi-util/include/header_abi_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ using llvm::object::ELFDataTypeTypedefHelper;
3232

3333
namespace abi_util {
3434

35+
std::string RealPath(const std::string &path);
36+
3537
std::set<std::string> CollectAllExportedHeaders(
3638
const std::vector<std::string> &exported_header_dirs);
3739

vndk/tools/header-checker/header-abi-util/src/collect_exported_headers.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ static bool ShouldSkipFile(llvm::StringRef &file_name) {
3737
return false;
3838
}
3939

40+
std::string RealPath(const std::string &path) {
41+
char file_abs_path[PATH_MAX];
42+
if (realpath(path.c_str(), file_abs_path) == nullptr) {
43+
return "";
44+
}
45+
return file_abs_path;
46+
}
47+
4048
bool CollectExportedHeaderSet(const std::string &dir_name,
4149
std::set<std::string> *exported_headers) {
4250
std::error_code ec;
@@ -66,17 +74,13 @@ bool CollectExportedHeaderSet(const std::string &dir_name,
6674
return false;
6775
}
6876

69-
if (!llvm::sys::fs::is_regular_file(status)) {
70-
// Ignore non regular files. eg: soft links.
77+
if ((status.type() != llvm::sys::fs::file_type::symlink_file) &&
78+
!llvm::sys::fs::is_regular_file(status)) {
79+
// Ignore non regular files, except symlinks.
7180
continue;
7281
}
7382

74-
llvm::SmallString<128> abs_path(file_path);
75-
if (llvm::sys::fs::make_absolute(abs_path)) {
76-
llvm::errs() << "Failed to get absolute path for : " << file_name << "\n";
77-
return false;
78-
}
79-
exported_headers->insert(abs_path.str());
83+
exported_headers->insert(RealPath(file_path));
8084
}
8185
return true;
8286
}

0 commit comments

Comments
 (0)