|
15 | 15 | #include "swift/extractor/remapping/SwiftFileInterception.h" |
16 | 16 | #include "swift/extractor/invocation/SwiftDiagnosticsConsumer.h" |
17 | 17 | #include "swift/extractor/trap/TrapDomain.h" |
| 18 | +#include "swift/extractor/infra/file/Path.h" |
18 | 19 | #include <swift/Basic/InitializeSwiftModules.h> |
19 | 20 |
|
20 | 21 | using namespace std::string_literals; |
21 | 22 |
|
| 23 | +// must be called before processFrontendOptions modifies output paths |
22 | 24 | static void lockOutputSwiftModuleTraps(const codeql::SwiftExtractorConfiguration& config, |
23 | | - const swift::CompilerInstance& compiler) { |
24 | | - std::filesystem::path output = compiler.getInvocation().getOutputFilename(); |
25 | | - if (output.extension() == ".swiftmodule") { |
26 | | - if (auto target = codeql::createTargetTrapFile(config, output)) { |
27 | | - *target << "// trap file deliberately empty\n" |
28 | | - "// this swiftmodule was created during the build, so its entities must have" |
29 | | - " been extracted directly from source files"; |
| 25 | + const swift::FrontendOptions& options) { |
| 26 | + for (const auto& input : options.InputsAndOutputs.getAllInputs()) { |
| 27 | + if (const auto& module = input.getPrimarySpecificPaths().SupplementaryOutputs.ModuleOutputPath; |
| 28 | + !module.empty()) { |
| 29 | + if (auto target = codeql::createTargetTrapFile(config, codeql::resolvePath(module))) { |
| 30 | + *target << "// trap file deliberately empty\n" |
| 31 | + "// this swiftmodule was created during the build, so its entities must have" |
| 32 | + " been extracted directly from source files"; |
| 33 | + } |
30 | 34 | } |
31 | 35 | } |
32 | 36 | } |
@@ -71,12 +75,13 @@ class Observer : public swift::FrontendObserver { |
71 | 75 | : config{config}, diagConsumer{diagConsumer} {} |
72 | 76 |
|
73 | 77 | void parsedArgs(swift::CompilerInvocation& invocation) override { |
74 | | - processFrontendOptions(invocation.getFrontendOptions()); |
| 78 | + auto& options = invocation.getFrontendOptions(); |
| 79 | + lockOutputSwiftModuleTraps(config, options); |
| 80 | + processFrontendOptions(options); |
75 | 81 | } |
76 | 82 |
|
77 | 83 | void configuredCompiler(swift::CompilerInstance& instance) override { |
78 | 84 | instance.addDiagnosticConsumer(&diagConsumer); |
79 | | - lockOutputSwiftModuleTraps(config, instance); |
80 | 85 | } |
81 | 86 |
|
82 | 87 | void performedSemanticAnalysis(swift::CompilerInstance& compiler) override { |
|
0 commit comments