18
18
19
19
using namespace codeql ;
20
20
21
- static void archiveFile (const SwiftExtractorConfiguration& config, swift::SourceFile* file) {
21
+ static void archiveFile (const SwiftExtractorConfiguration& config, swift::SourceFile& file) {
22
22
if (std::error_code ec = llvm::sys::fs::create_directories (config.trapDir )) {
23
23
std::cerr << " Cannot create TRAP directory: " << ec.message () << " \n " ;
24
24
return ;
@@ -29,7 +29,7 @@ static void archiveFile(const SwiftExtractorConfiguration& config, swift::Source
29
29
return ;
30
30
}
31
31
32
- llvm::SmallString<PATH_MAX> srcFilePath (file-> getFilename ());
32
+ llvm::SmallString<PATH_MAX> srcFilePath (file. getFilename ());
33
33
llvm::sys::fs::make_absolute (srcFilePath);
34
34
35
35
llvm::SmallString<PATH_MAX> dstFilePath (config.sourceArchiveDir );
@@ -51,12 +51,12 @@ static void archiveFile(const SwiftExtractorConfiguration& config, swift::Source
51
51
52
52
static void extractFile (const SwiftExtractorConfiguration& config,
53
53
swift::CompilerInstance& compiler,
54
- swift::SourceFile* file) {
54
+ swift::SourceFile& file) {
55
55
// The extractor can be called several times from different processes with
56
56
// the same input file(s)
57
57
// We are using PID to avoid concurrent access
58
58
// TODO: find a more robust approach to avoid collisions?
59
- std::string tempTrapName = file-> getFilename ().str () + ' .' + std::to_string (getpid ()) + " .trap" ;
59
+ std::string tempTrapName = file. getFilename ().str () + ' .' + std::to_string (getpid ()) + " .trap" ;
60
60
llvm::SmallString<PATH_MAX> tempTrapPath (config.trapDir );
61
61
llvm::sys::path::append (tempTrapPath, tempTrapName);
62
62
@@ -87,19 +87,19 @@ static void extractFile(const SwiftExtractorConfiguration& config,
87
87
// In the case of emtpy files, the dispatcher is not called, but we still want to 'record' the
88
88
// fact that the file was extracted
89
89
// TODO: to be moved elsewhere
90
- llvm::SmallString<PATH_MAX> srcFilePath (file-> getFilename ());
90
+ llvm::SmallString<PATH_MAX> srcFilePath (file. getFilename ());
91
91
llvm::sys::fs::make_absolute (srcFilePath);
92
92
auto fileLabel = arena.allocateLabel <FileTag>();
93
93
trap.assignKey (fileLabel, srcFilePath.str ().str ());
94
94
trap.emit (FilesTrap{fileLabel, srcFilePath.str ().str ()});
95
95
96
96
SwiftVisitor visitor (compiler.getSourceMgr (), arena, trap);
97
- for (swift::Decl* decl : file-> getTopLevelDecls ()) {
97
+ for (swift::Decl* decl : file. getTopLevelDecls ()) {
98
98
visitor.extract (decl);
99
99
}
100
100
101
101
// TODO: Pick a better name to avoid collisions
102
- std::string trapName = file-> getFilename ().str () + " .trap" ;
102
+ std::string trapName = file. getFilename ().str () + " .trap" ;
103
103
llvm::SmallString<PATH_MAX> trapPath (config.trapDir );
104
104
llvm::sys::path::append (trapPath, trapName);
105
105
@@ -112,8 +112,10 @@ static void extractFile(const SwiftExtractorConfiguration& config,
112
112
113
113
void codeql::extractSwiftFiles (const SwiftExtractorConfiguration& config,
114
114
swift::CompilerInstance& compiler) {
115
+ // The extraction will only work if one (or more) `-primary-file` CLI option is provided, which
116
+ // is what always happen in case of `swift build` and `xcodebuild`
115
117
for (auto s : compiler.getPrimarySourceFiles ()) {
116
- archiveFile (config, s);
117
- extractFile (config, compiler, s);
118
+ archiveFile (config, * s);
119
+ extractFile (config, compiler, * s);
118
120
}
119
121
}
0 commit comments