@@ -149,6 +149,20 @@ static void handleColorDiagnostics(opt::InputArgList &args) {
149149 }
150150}
151151
152+ static cl::TokenizerCallback getQuotingStyle (opt::InputArgList &args) {
153+ if (auto *arg = args.getLastArg (OPT_rsp_quoting)) {
154+ StringRef s = arg->getValue ();
155+ if (s != " windows" && s != " posix" )
156+ error (" invalid response file quoting: " + s);
157+ if (s == " windows" )
158+ return cl::TokenizeWindowsCommandLine;
159+ return cl::TokenizeGNUCommandLine;
160+ }
161+ if (Triple (sys::getProcessTriple ()).isOSWindows ())
162+ return cl::TokenizeWindowsCommandLine;
163+ return cl::TokenizeGNUCommandLine;
164+ }
165+
152166// Find a file by concatenating given paths.
153167static Optional<std::string> findFile (StringRef path1, const Twine &path2) {
154168 SmallString<128 > s;
@@ -164,11 +178,16 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
164178 unsigned missingIndex;
165179 unsigned missingCount;
166180
167- // Expand response files (arguments in the form of @<filename>)
168- cl::ExpandResponseFiles (saver, cl::TokenizeGNUCommandLine, vec);
169-
181+ // We need to get the quoting style for response files before parsing all
182+ // options so we parse here before and ignore all the options but
183+ // --rsp-quoting.
170184 opt::InputArgList args = this ->ParseArgs (vec, missingIndex, missingCount);
171185
186+ // Expand response files (arguments in the form of @<filename>)
187+ // and then parse the argument again.
188+ cl::ExpandResponseFiles (saver, getQuotingStyle (args), vec);
189+ args = this ->ParseArgs (vec, missingIndex, missingCount);
190+
172191 handleColorDiagnostics (args);
173192 for (auto *arg : args.filtered (OPT_UNKNOWN))
174193 error (" unknown argument: " + arg->getAsString (args));
0 commit comments