@@ -77,6 +77,20 @@ static llvm::SmallVector<swift::Decl*> getTopLevelDecls(swift::ModuleDecl& modul
7777 return ret;
7878}
7979
80+ static void dumpArgs (TargetFile& out, const SwiftExtractorConfiguration& config) {
81+ out << " /* extractor-args:\n " ;
82+ for (const auto & opt : config.frontendOptions ) {
83+ out << " " << std::quoted (opt) << " \\\n " ;
84+ }
85+ out << " \n */\n " ;
86+
87+ out << " /* swift-frontend-args:\n " ;
88+ for (const auto & opt : config.patchedFrontendOptions ) {
89+ out << " " << std::quoted (opt) << " \\\n " ;
90+ }
91+ out << " \n */\n " ;
92+ }
93+
8094static void extractDeclarations (const SwiftExtractorConfiguration& config,
8195 swift::CompilerInstance& compiler,
8296 swift::ModuleDecl& module ,
@@ -86,25 +100,13 @@ static void extractDeclarations(const SwiftExtractorConfiguration& config,
86100 // The extractor can be called several times from different processes with
87101 // the same input file(s). Using `TargetFile` the first process will win, and the following
88102 // will just skip the work
89- TargetFile trapStream{ filename + " .trap" , config.trapDir , config.getTempTrapDir ()} ;
90- if (!trapStream. good () ) {
103+ auto trapTarget = TargetFile::create ( filename + " .trap" , config.trapDir , config.getTempTrapDir ()) ;
104+ if (!trapTarget ) {
91105 // another process arrived first, nothing to do for us
92106 return ;
93107 }
94-
95- trapStream << " /* extractor-args:\n " ;
96- for (const auto & opt : config.frontendOptions ) {
97- trapStream << " " << std::quoted (opt) << " \\\n " ;
98- }
99- trapStream << " \n */\n " ;
100-
101- trapStream << " /* swift-frontend-args:\n " ;
102- for (const auto & opt : config.patchedFrontendOptions ) {
103- trapStream << " " << std::quoted (opt) << " \\\n " ;
104- }
105- trapStream << " \n */\n " ;
106-
107- TrapDomain trap{trapStream};
108+ dumpArgs (*trapTarget, config);
109+ TrapDomain trap{*trapTarget};
108110
109111 // TODO: move default location emission elsewhere, possibly in a separate global trap file
110112 // the following cannot conflict with actual files as those have an absolute path starting with /
@@ -129,7 +131,6 @@ static void extractDeclarations(const SwiftExtractorConfiguration& config,
129131 auto fileLabel = trap.createLabel <FileTag>(name.str ().str ());
130132 trap.emit (FilesTrap{fileLabel, name.str ().str ()});
131133 }
132- trapStream.commit ();
133134}
134135
135136static std::unordered_set<std::string> collectInputFilenames (swift::CompilerInstance& compiler) {
0 commit comments