Skip to content

Commit bffd22a

Browse files
authored
Fix dropping args when checking for -Xwrapped-swift arg in worker (#1551)
1 parent 6d28b81 commit bffd22a

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

tools/worker/swift_runner.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ bool ArgumentEnablesWMO(const std::string &arg) {
2727
arg == "-force-single-frontend-invocation";
2828
}
2929

30-
bool StripPrefix(const std::string &prefix, std::string &str) {
31-
if (str.find(prefix) != 0) {
32-
return false;
33-
}
34-
str.erase(0, prefix.size());
35-
return true;
36-
}
37-
3830
namespace {
3931

4032
// Creates a temporary file and writes the given arguments to it, one per line.
@@ -100,6 +92,17 @@ static std::string Unescape(const std::string &arg) {
10092
return result;
10193
}
10294

95+
// If `str` starts with `prefix`, `str` is mutated to remove `prefix` and the
96+
// function returns true. Otherwise, `str` is left unmodified and the function
97+
// returns `false`.
98+
static bool StripPrefix(const std::string &prefix, std::string &str) {
99+
if (str.find(prefix) != 0) {
100+
return false;
101+
}
102+
str.erase(0, prefix.size());
103+
return true;
104+
}
105+
103106
} // namespace
104107

105108
SwiftRunner::SwiftRunner(const std::vector<std::string> &args,

tools/worker/swift_runner.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
// optimization in the compiler.
3030
extern bool ArgumentEnablesWMO(const std::string &arg);
3131

32-
// If `str` starts with `prefix`, `str` is mutated to remove `prefix` and the
33-
// function returns true. Otherwise, `str` is left unmodified and the function
34-
// returns `false`.
35-
extern bool StripPrefix(const std::string &prefix, std::string &str);
36-
3732
// Handles spawning the Swift compiler driver, making any required substitutions
3833
// of the command line arguments (for example, Bazel's magic Xcode placeholder
3934
// strings).

tools/worker/work_processor.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,16 @@ void WorkProcessor::ProcessWorkRequest(
9191
std::string prev_arg;
9292
for (std::string arg : request.arguments) {
9393
std::string original_arg = arg;
94-
// Peel off the `-output-file-map` argument, so we can rewrite it if
95-
// necessary later.
96-
if (StripPrefix("-Xwrapped-swift=", arg)) {
97-
if (arg == "-emit-swiftsourceinfo") {
98-
emit_swift_source_info = true;
99-
}
100-
arg.clear();
101-
} else if (arg == "-output-file-map") {
94+
95+
// Handle arguments, in some cases we rewrite the argument entirely and in others we simply use it to determine
96+
// specific behavior.
97+
if (arg == "-output-file-map") {
98+
// Peel off the `-output-file-map` argument, so we can rewrite it if necessary later.
10299
arg.clear();
103100
} else if (arg == "-dump-ast") {
104101
is_dump_ast = true;
105102
} else if (prev_arg == "-output-file-map") {
103+
// Peel off the `-output-file-map` argument, so we can rewrite it if necessary later.
106104
output_file_map_path = arg;
107105
arg.clear();
108106
} else if (prev_arg == "-emit-module-path") {
@@ -111,6 +109,8 @@ void WorkProcessor::ProcessWorkRequest(
111109
emit_objc_header_path = arg;
112110
} else if (ArgumentEnablesWMO(arg)) {
113111
is_wmo = true;
112+
} else if (prev_arg == "-Xwrapped-swift=-emit-swiftsourceinfo") {
113+
emit_swift_source_info = true;
114114
}
115115

116116
if (!arg.empty()) {
@@ -167,7 +167,7 @@ void WorkProcessor::ProcessWorkRequest(
167167
// When using non-sandboxed mode, previous builds will contain these files and cause build failures
168168
// when Swift tries to use them, in order to work around this compatibility issue, we remove them if they are
169169
// present but not requested.
170-
if (expected_object_path.extension() == ".swiftsourceinfo" && !emit_swift_source_info) {
170+
if (!emit_swift_source_info && expected_object_path.extension() == ".swiftsourceinfo") {
171171
std::filesystem::remove(expected_object_path);
172172
}
173173

0 commit comments

Comments
 (0)