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 88#include < swift/AST/SourceFile.h>
99#include < swift/AST/Builtins.h>
1010
11- #include " swift/extractor/trap/TrapDomain.h"
1211#include " swift/extractor/translators/SwiftVisitor.h"
1312#include " swift/extractor/TargetTrapDomain.h"
1413#include " swift/extractor/SwiftBuiltinSymbols.h"
@@ -121,7 +120,8 @@ static std::unordered_set<swift::ModuleDecl*> extractDeclarations(
121120 // The extractor can be called several times from different processes with
122121 // the same input file(s). Using `TargetFile` the first process will win, and the following
123122 // 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);
125125 if (!trap) {
126126 // another process arrived first, nothing to do for us
127127 return {};
Original file line number Diff line number Diff line change 11#include " swift/extractor/TargetTrapDomain.h"
22#include < iomanip>
33namespace 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+
425std::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) {
1136 *ret << " /* extractor-args:\n " ;
1237 for (const auto & opt : state.configuration .frontendOptions ) {
1338 *ret << " " << std::quoted (opt) << " \\\n " ;
Original file line number Diff line number Diff line change 55
66namespace codeql {
77
8+ enum class TrapType {
9+ source,
10+ module ,
11+ invocation,
12+ };
13+
814std::optional<TrapDomain> createTargetTrapDomain (SwiftExtractorState& state,
9- const std::filesystem::path& target);
15+ const std::filesystem::path& target,
16+ TrapType type);
1017
1118} // namespace codeql
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ static void lockOutputSwiftModuleTraps(codeql::SwiftExtractorState& state,
2626 for (const auto & input : options.InputsAndOutputs .getAllInputs ()) {
2727 if (const auto & module = input.getPrimarySpecificPaths ().SupplementaryOutputs .ModuleOutputPath ;
2828 !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 )) {
3031 target->emit (" // trap file deliberately empty\n "
3132 " // this swiftmodule was created during the build, so its entities must have"
3233 " been extracted directly from source files" );
@@ -152,7 +153,7 @@ codeql::TrapDomain invocationTrapDomain(codeql::SwiftExtractorState& state) {
152153 auto timestamp = std::chrono::system_clock::now ().time_since_epoch ().count ();
153154 auto filename = std::to_string (timestamp) + ' -' + std::to_string (getpid ());
154155 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 );
156157 if (!maybeDomain) {
157158 std::cerr << " Cannot create invocation trap file: " << target << " \n " ;
158159 abort ();
You can’t perform that action at this time.
0 commit comments