@@ -133,7 +133,6 @@ static void addCommonFrontendArgs(const ToolChain &TC,
133133 inputArgs.AddLastArg (arguments, options::OPT_enable_app_extension);
134134 inputArgs.AddLastArg (arguments, options::OPT_enable_testing);
135135 inputArgs.AddLastArg (arguments, options::OPT_g_Group);
136- inputArgs.AddLastArg (arguments, options::OPT_import_objc_header);
137136 inputArgs.AddLastArg (arguments, options::OPT_import_underlying_module);
138137 inputArgs.AddLastArg (arguments, options::OPT_module_cache_path);
139138 inputArgs.AddLastArg (arguments, options::OPT_module_link_name);
@@ -258,9 +257,6 @@ ToolChain::constructInvocation(const CompileJobAction &job,
258257
259258 Arguments.push_back (FrontendModeOption);
260259
261- assert (context.Inputs .empty () &&
262- " The Swift frontend does not expect to be fed any input Jobs!" );
263-
264260 // Add input arguments.
265261 switch (context.OI .CompilerMode ) {
266262 case OutputInfo::Mode::StandardCompile:
@@ -318,6 +314,23 @@ ToolChain::constructInvocation(const CompileJobAction &job,
318314 addCommonFrontendArgs (*this , context.OI , context.Output , context.Args ,
319315 Arguments);
320316
317+ // Pass along an -import-objc-header arg, replacing the argument with the name
318+ // of any input PCH to the current action if one is present.
319+ if (context.Args .hasArgNoClaim (options::OPT_import_objc_header)) {
320+ bool ForwardAsIs = true ;
321+ for (auto *IJ : context.Inputs ) {
322+ if (!IJ->getOutput ().getAnyOutputForType (types::TY_PCH).empty ()) {
323+ Arguments.push_back (" -import-objc-header" );
324+ addInputsOfType (Arguments, context.Inputs , types::TY_PCH);
325+ ForwardAsIs = false ;
326+ break ;
327+ }
328+ }
329+ if (ForwardAsIs) {
330+ context.Args .AddLastArg (Arguments, options::OPT_import_objc_header);
331+ }
332+ }
333+
321334 // Pass the optimization level down to the frontend.
322335 context.Args .AddLastArg (Arguments, options::OPT_O_Group);
323336
@@ -426,6 +439,7 @@ ToolChain::constructInvocation(const InterpretJobAction &job,
426439
427440 addCommonFrontendArgs (*this , context.OI , context.Output , context.Args ,
428441 Arguments);
442+ context.Args .AddLastArg (Arguments, options::OPT_import_objc_header);
429443
430444 // Pass the optimization level down to the frontend.
431445 context.Args .AddLastArg (Arguments, options::OPT_O_Group);
@@ -618,6 +632,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
618632
619633 addCommonFrontendArgs (*this , context.OI , context.Output , context.Args ,
620634 Arguments);
635+ context.Args .AddLastArg (Arguments, options::OPT_import_objc_header);
621636
622637 Arguments.push_back (" -module-name" );
623638 Arguments.push_back (context.Args .MakeArgString (context.OI .ModuleName ));
@@ -687,6 +702,7 @@ ToolChain::constructInvocation(const REPLJobAction &job,
687702 ArgStringList FrontendArgs;
688703 addCommonFrontendArgs (*this , context.OI , context.Output , context.Args ,
689704 FrontendArgs);
705+ context.Args .AddLastArg (FrontendArgs, options::OPT_import_objc_header);
690706 context.Args .AddAllArgs (FrontendArgs, options::OPT_l, options::OPT_framework,
691707 options::OPT_L);
692708
@@ -731,6 +747,30 @@ ToolChain::constructInvocation(const GenerateDSYMJobAction &job,
731747 return {" dsymutil" , Arguments};
732748}
733749
750+ ToolChain::InvocationInfo
751+ ToolChain::constructInvocation (const GeneratePCHJobAction &job,
752+ const JobContext &context) const {
753+ assert (context.Inputs .empty ());
754+ assert (context.InputActions .size () == 1 );
755+ assert (context.Output .getPrimaryOutputType () == types::TY_PCH);
756+
757+ ArgStringList Arguments;
758+
759+ Arguments.push_back (" -frontend" );
760+
761+ addCommonFrontendArgs (*this , context.OI , context.Output , context.Args ,
762+ Arguments);
763+
764+ addInputsOfType (Arguments, context.InputActions , types::TY_ObjCHeader);
765+
766+ Arguments.push_back (" -emit-pch" );
767+ Arguments.push_back (" -o" );
768+ Arguments.push_back (
769+ context.Args .MakeArgString (context.Output .getPrimaryOutputFilename ()));
770+
771+ return {SWIFT_EXECUTABLE_NAME, Arguments};
772+ }
773+
734774ToolChain::InvocationInfo
735775ToolChain::constructInvocation (const AutolinkExtractJobAction &job,
736776 const JobContext &context) const {
0 commit comments