Skip to content

Commit 454af0d

Browse files
committed
Swift: fix locking of output swiftmodule trap
1 parent a1161c6 commit 454af0d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

swift/extractor/main.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
#include "swift/extractor/remapping/SwiftFileInterception.h"
1616
#include "swift/extractor/invocation/SwiftDiagnosticsConsumer.h"
1717
#include "swift/extractor/trap/TrapDomain.h"
18+
#include "swift/extractor/infra/file/Path.h"
1819
#include <swift/Basic/InitializeSwiftModules.h>
1920

2021
using namespace std::string_literals;
2122

23+
// must be called before processFrontendOptions modifies output paths
2224
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+
}
3034
}
3135
}
3236
}
@@ -71,12 +75,13 @@ class Observer : public swift::FrontendObserver {
7175
: config{config}, diagConsumer{diagConsumer} {}
7276

7377
void parsedArgs(swift::CompilerInvocation& invocation) override {
74-
processFrontendOptions(invocation.getFrontendOptions());
78+
auto& options = invocation.getFrontendOptions();
79+
lockOutputSwiftModuleTraps(config, options);
80+
processFrontendOptions(options);
7581
}
7682

7783
void configuredCompiler(swift::CompilerInstance& instance) override {
7884
instance.addDiagnosticConsumer(&diagConsumer);
79-
lockOutputSwiftModuleTraps(config, instance);
8085
}
8186

8287
void performedSemanticAnalysis(swift::CompilerInstance& compiler) override {

0 commit comments

Comments
 (0)