File tree Expand file tree Collapse file tree 9 files changed +33
-32
lines changed Expand file tree Collapse file tree 9 files changed +33
-32
lines changed Original file line number Diff line number Diff line change @@ -61,12 +61,7 @@ std::string ABIWrapper::GetDeclSourceFile(const clang::Decl *decl,
61
61
// belonging to the library.
62
62
clang::SourceLocation expansion_location = sm.getExpansionLoc (location);
63
63
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 ());
70
65
}
71
66
72
67
static abi_util::AccessSpecifierIR AccessClangToIR (
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ class HeaderASTConsumer : public clang::ASTConsumer {
87
87
std::string file_name_;
88
88
clang::CompilerInstance *cip_;
89
89
std::string out_dump_name_;
90
- std::set<std::string> exported_headers_;
90
+ const std::set<std::string> & exported_headers_;
91
91
};
92
92
93
93
#endif // AST_PROCESSING_H_
Original file line number Diff line number Diff line change 25
25
#include < llvm/Support/Path.h>
26
26
27
27
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 ) { }
30
30
31
31
std::unique_ptr<clang::ASTConsumer>
32
32
HeaderCheckerFrontendAction::CreateASTConsumer (clang::CompilerInstance &ci,
33
33
llvm::StringRef header_file) {
34
- std::set<std::string> exported_headers;
35
- exported_headers = abi_util::CollectAllExportedHeaders (exported_header_dirs_);
36
34
// 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_);
40
37
}
Original file line number Diff line number Diff line change @@ -31,12 +31,12 @@ namespace clang {
31
31
class HeaderCheckerFrontendAction : public clang ::ASTFrontendAction {
32
32
private:
33
33
std::string dump_name_;
34
- const std::vector <std::string> &exported_header_dirs_ ;
34
+ const std::set <std::string> &exported_headers_ ;
35
35
36
36
public:
37
37
HeaderCheckerFrontendAction (
38
38
const std::string &dump_name,
39
- const std::vector <std::string> &export_header_dirs );
39
+ const std::set <std::string> &exported_headers );
40
40
41
41
protected:
42
42
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer (
Original file line number Diff line number Diff line change 20
20
21
21
HeaderCheckerFrontendActionFactory::HeaderCheckerFrontendActionFactory (
22
22
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 ) { }
25
25
26
26
clang::FrontendAction *HeaderCheckerFrontendActionFactory::create () {
27
- return new HeaderCheckerFrontendAction (dump_name_, export_header_dirs_ );
27
+ return new HeaderCheckerFrontendAction (dump_name_, exported_headers_ );
28
28
}
Original file line number Diff line number Diff line change @@ -23,12 +23,12 @@ class HeaderCheckerFrontendActionFactory
23
23
: public clang::tooling::FrontendActionFactory {
24
24
private:
25
25
std::string dump_name_;
26
- const std::vector <std::string> &export_header_dirs_ ;
26
+ const std::set <std::string> &exported_headers_ ;
27
27
28
28
public:
29
29
HeaderCheckerFrontendActionFactory (
30
30
const std::string &dump_name,
31
- const std::vector <std::string> &exported_header_dirs );
31
+ const std::set <std::string> &exported_headers );
32
32
33
33
clang::FrontendAction *create () override ;
34
34
};
Original file line number Diff line number Diff line change 13
13
// limitations under the License.
14
14
15
15
#include " frontend_action_factory.h"
16
+ #include < header_abi_util.h>
16
17
17
18
#include < clang/Frontend/FrontendActions.h>
18
19
#include < clang/Tooling/CommonOptionsParser.h>
@@ -96,16 +97,18 @@ int main(int argc, const char **argv) {
96
97
::exit (1 );
97
98
}
98
99
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);
101
104
}
102
105
103
106
// Initialize clang tools and run front-end action.
104
107
std::vector<std::string> header_files{ header_file };
105
108
106
109
clang::tooling::ClangTool tool (*compilations, header_files);
107
110
std::unique_ptr<clang::tooling::FrontendActionFactory> factory (
108
- new HeaderCheckerFrontendActionFactory (out_dump, exported_header_dirs ));
111
+ new HeaderCheckerFrontendActionFactory (out_dump, exported_headers ));
109
112
110
113
return tool.run (factory.get ());
111
114
}
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ using llvm::object::ELFDataTypeTypedefHelper;
32
32
33
33
namespace abi_util {
34
34
35
+ std::string RealPath (const std::string &path);
36
+
35
37
std::set<std::string> CollectAllExportedHeaders (
36
38
const std::vector<std::string> &exported_header_dirs);
37
39
Original file line number Diff line number Diff line change @@ -37,6 +37,14 @@ static bool ShouldSkipFile(llvm::StringRef &file_name) {
37
37
return false ;
38
38
}
39
39
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
+
40
48
bool CollectExportedHeaderSet (const std::string &dir_name,
41
49
std::set<std::string> *exported_headers) {
42
50
std::error_code ec;
@@ -66,17 +74,13 @@ bool CollectExportedHeaderSet(const std::string &dir_name,
66
74
return false ;
67
75
}
68
76
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.
71
80
continue ;
72
81
}
73
82
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));
80
84
}
81
85
return true ;
82
86
}
You can’t perform that action at this time.
0 commit comments