@@ -37,20 +37,35 @@ static void processFrontendOptions(swift::FrontendOptions& options) {
3737 case Action::EmitModuleOnly:
3838 case Action::MergeModules:
3939 case Action::CompileModuleFromInterface:
40- // for module emission actions, we redirect the output to our internal artifact storage
41- {
42- swift::SupplementaryOutputPaths paths;
43- paths.ModuleOutputPath =
44- codeql::redirect (options.InputsAndOutputs .getSingleOutputFilename ()).string ();
45- options.InputsAndOutputs .setMainAndSupplementaryOutputs (std::vector{paths.ModuleOutputPath },
46- std::vector{paths});
47- return ;
40+ case Action::EmitObject: {
41+ auto & inOuts = options.InputsAndOutputs ;
42+ std::vector<swift::InputFile> inputs;
43+ inOuts.forEachInput ([&](const swift::InputFile& input) {
44+ swift::PrimarySpecificPaths psp{};
45+ if (std::filesystem::path output = input.getPrimarySpecificPaths ().OutputFilename ;
46+ !output.empty ()) {
47+ if (output.extension () == " .swiftmodule" ) {
48+ psp.OutputFilename = codeql::redirect (output);
49+ } else {
50+ psp.OutputFilename = " /dev/null" ;
51+ }
52+ }
53+ if (std::filesystem::path module =
54+ input.getPrimarySpecificPaths ().SupplementaryOutputs .ModuleOutputPath ;
55+ !module .empty ()) {
56+ psp.SupplementaryOutputs .ModuleOutputPath = codeql::redirect (module );
57+ }
58+ auto inputCopy = input;
59+ inputCopy.setPrimarySpecificPaths (std::move (psp));
60+ inputs.push_back (std::move (inputCopy));
61+ return false ;
62+ });
63+ inOuts.clearInputs ();
64+ for (const auto & i : inputs) {
65+ inOuts.addInput (i);
4866 }
49- case Action::EmitObject:
50- // for object emission, we do a type check pass instead, muting output but getting the sema
51- // phase to run in order to extract everything
52- options.RequestedAction = Action::Typecheck;
5367 return ;
68+ }
5469 case Action::PrintVersion:
5570 case Action::DumpAST:
5671 case Action::PrintAST:
0 commit comments