mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Swift: generalize output redirection code
This commit is contained in:
@@ -37,20 +37,35 @@ static void processFrontendOptions(swift::FrontendOptions& options) {
|
||||
case Action::EmitModuleOnly:
|
||||
case Action::MergeModules:
|
||||
case Action::CompileModuleFromInterface:
|
||||
// for module emission actions, we redirect the output to our internal artifact storage
|
||||
{
|
||||
swift::SupplementaryOutputPaths paths;
|
||||
paths.ModuleOutputPath =
|
||||
codeql::redirect(options.InputsAndOutputs.getSingleOutputFilename()).string();
|
||||
options.InputsAndOutputs.setMainAndSupplementaryOutputs(std::vector{paths.ModuleOutputPath},
|
||||
std::vector{paths});
|
||||
return;
|
||||
case Action::EmitObject: {
|
||||
auto& inOuts = options.InputsAndOutputs;
|
||||
std::vector<swift::InputFile> inputs;
|
||||
inOuts.forEachInput([&](const swift::InputFile& input) {
|
||||
swift::PrimarySpecificPaths psp{};
|
||||
if (std::filesystem::path output = input.getPrimarySpecificPaths().OutputFilename;
|
||||
!output.empty()) {
|
||||
if (output.extension() == ".swiftmodule") {
|
||||
psp.OutputFilename = codeql::redirect(output);
|
||||
} else {
|
||||
psp.OutputFilename = "/dev/null";
|
||||
}
|
||||
}
|
||||
if (std::filesystem::path module =
|
||||
input.getPrimarySpecificPaths().SupplementaryOutputs.ModuleOutputPath;
|
||||
!module.empty()) {
|
||||
psp.SupplementaryOutputs.ModuleOutputPath = codeql::redirect(module);
|
||||
}
|
||||
auto inputCopy = input;
|
||||
inputCopy.setPrimarySpecificPaths(std::move(psp));
|
||||
inputs.push_back(std::move(inputCopy));
|
||||
return false;
|
||||
});
|
||||
inOuts.clearInputs();
|
||||
for (const auto& i : inputs) {
|
||||
inOuts.addInput(i);
|
||||
}
|
||||
case Action::EmitObject:
|
||||
// for object emission, we do a type check pass instead, muting output but getting the sema
|
||||
// phase to run in order to extract everything
|
||||
options.RequestedAction = Action::Typecheck;
|
||||
return;
|
||||
}
|
||||
case Action::PrintVersion:
|
||||
case Action::DumpAST:
|
||||
case Action::PrintAST:
|
||||
|
||||
@@ -6,4 +6,6 @@
|
||||
| F1.swift:0:0:0:0 | F1.swift |
|
||||
| F2.swift:0:0:0:0 | F2.swift |
|
||||
| G.swift:0:0:0:0 | G.swift |
|
||||
| H1.swift:0:0:0:0 | H1.swift |
|
||||
| H2.swift:0:0:0:0 | H2.swift |
|
||||
| file://:0:0:0:0 | |
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
func h1() {}
|
||||
@@ -0,0 +1 @@
|
||||
func h2() {}
|
||||
@@ -0,0 +1 @@
|
||||
func h3() {}
|
||||
@@ -15,5 +15,7 @@ $FRONTEND -frontend -c -primary-file D.swift -o D.o $SDK
|
||||
$FRONTEND -frontend -c -primary-file E.swift Esup.swift -o E.o $SDK
|
||||
$FRONTEND -frontend -emit-module -primary-file F1.swift F2.swift -module-name F -o F1.swiftmodule $SDK
|
||||
$FRONTEND -frontend -emit-module F1.swift -primary-file F2.swift -module-name F -o F2.swiftmodule $SDK
|
||||
$FRONTEND -frontend -emit-module F1.swift F2.swift -o Fs.swiftmodule $SDK
|
||||
$FRONTEND -frontend -merge-modules F1.swiftmodule F2.swiftmodule -o F.swiftmodule $SDK
|
||||
( cd dir; $FRONTEND -frontend -c ../G.swift $SDK )
|
||||
$FRONTEND -frontend -c -primary-file H1.swift -primary-file H2.swift H3.swift -emit-module-path H1.swiftmodule -emit-module-path H2.swiftmodule -o H1.o -o H2.o $SDK
|
||||
|
||||
Reference in New Issue
Block a user