File tree Expand file tree Collapse file tree 4 files changed +44
-11
lines changed Expand file tree Collapse file tree 4 files changed +44
-11
lines changed Original file line number Diff line number Diff line change 8
8
#include < swift/AST/SourceFile.h>
9
9
#include < swift/AST/Builtins.h>
10
10
11
- #include " swift/extractor/trap/TrapDomain.h"
12
11
#include " swift/extractor/translators/SwiftVisitor.h"
13
12
#include " swift/extractor/TargetTrapDomain.h"
14
13
#include " swift/extractor/SwiftBuiltinSymbols.h"
@@ -121,7 +120,8 @@ static std::unordered_set<swift::ModuleDecl*> extractDeclarations(
121
120
// The extractor can be called several times from different processes with
122
121
// the same input file(s). Using `TargetFile` the first process will win, and the following
123
122
// will just skip the work
124
- auto trap = createTargetTrapDomain (state, filename);
123
+ const auto trapType = primaryFile ? TrapType::source : TrapType::module ;
124
+ auto trap = createTargetTrapDomain (state, filename, trapType);
125
125
if (!trap) {
126
126
// another process arrived first, nothing to do for us
127
127
return {};
Original file line number Diff line number Diff line change 1
1
#include " swift/extractor/TargetTrapDomain.h"
2
2
#include < iomanip>
3
3
namespace codeql {
4
+ static const char * typeToStr (TrapType type) {
5
+ switch (type) {
6
+ case TrapType::source:
7
+ return " sources" ;
8
+ case TrapType::module :
9
+ return " modules" ;
10
+ case TrapType::invocation:
11
+ return " invocations" ;
12
+ default :
13
+ return " " ;
14
+ }
15
+ }
16
+
17
+ static std::filesystem::path getRelativeTrapPath (const std::filesystem::path& target,
18
+ TrapType type,
19
+ const char * extension = " .trap" ) {
20
+ auto trap = typeToStr (type) / target.relative_path ();
21
+ trap += extension;
22
+ return trap;
23
+ }
24
+
4
25
std::optional<TrapDomain> createTargetTrapDomain (SwiftExtractorState& state,
5
- const std::filesystem::path& target) {
6
- auto trap = target;
7
- trap += " .trap" ;
8
- state.traps .push_back (trap.relative_path ());
9
- if (auto ret = TargetFile::create (trap, state.configuration .trapDir ,
10
- state.configuration .getTempTrapDir ())) {
26
+ const std::filesystem::path& target,
27
+ TrapType type) {
28
+ if (target.empty ()) {
29
+ return std::nullopt;
30
+ }
31
+ auto trap = getRelativeTrapPath (target, type);
32
+ auto ret =
33
+ TargetFile::create (trap, state.configuration .trapDir , state.configuration .getTempTrapDir ());
34
+ state.traps .push_back (std::move (trap));
35
+ if (ret) {
11
36
*ret << " /* extractor-args:\n " ;
12
37
for (const auto & opt : state.configuration .frontendOptions ) {
13
38
*ret << " " << std::quoted (opt) << " \\\n " ;
Original file line number Diff line number Diff line change 5
5
6
6
namespace codeql {
7
7
8
+ enum class TrapType {
9
+ source,
10
+ module ,
11
+ invocation,
12
+ };
13
+
8
14
std::optional<TrapDomain> createTargetTrapDomain (SwiftExtractorState& state,
9
- const std::filesystem::path& target);
15
+ const std::filesystem::path& target,
16
+ TrapType type);
10
17
11
18
} // namespace codeql
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ static void lockOutputSwiftModuleTraps(codeql::SwiftExtractorState& state,
26
26
for (const auto & input : options.InputsAndOutputs .getAllInputs ()) {
27
27
if (const auto & module = input.getPrimarySpecificPaths ().SupplementaryOutputs .ModuleOutputPath ;
28
28
!module .empty ()) {
29
- if (auto target = codeql::createTargetTrapDomain (state, codeql::resolvePath (module ))) {
29
+ if (auto target = codeql::createTargetTrapDomain (state, codeql::resolvePath (module ),
30
+ codeql::TrapType::module )) {
30
31
target->emit (" // trap file deliberately empty\n "
31
32
" // this swiftmodule was created during the build, so its entities must have"
32
33
" been extracted directly from source files" );
@@ -152,7 +153,7 @@ codeql::TrapDomain invocationTrapDomain(codeql::SwiftExtractorState& state) {
152
153
auto timestamp = std::chrono::system_clock::now ().time_since_epoch ().count ();
153
154
auto filename = std::to_string (timestamp) + ' -' + std::to_string (getpid ());
154
155
auto target = std::filesystem::path (" invocations" ) / std::filesystem::path (filename);
155
- auto maybeDomain = codeql::createTargetTrapDomain (state, target);
156
+ auto maybeDomain = codeql::createTargetTrapDomain (state, target, codeql::TrapType::invocation );
156
157
if (!maybeDomain) {
157
158
std::cerr << " Cannot create invocation trap file: " << target << " \n " ;
158
159
abort ();
You can’t perform that action at this time.
0 commit comments