Skip to content

Commit 107a54e

Browse files
larsrc-googlecopybara-github
authored andcommitted
Fix flag file regexp broken by bazelbuild@cb2cd9f.
PiperOrigin-RevId: 460216776 Change-Id: I31f5ce3a4a7ce76d635ba5b0ce90f0eac41df0ad
1 parent c09b942 commit 107a54e

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/main/java/com/google/devtools/build/lib/worker/WorkerParser.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class WorkerParser {
5151
private static final String REASON_NO_FINAL_FLAGFILE =
5252
"because the command-line arguments does not end with a @flagfile or --flagfile= argument";
5353

54-
/** Pattern for @flagfile.txt and --flagfile=flagfile.txt */
55-
private static final Pattern FLAG_FILE_PATTERN = Pattern.compile("(?:@[^@]|--?flagfile=.)(.*)");
54+
/** Pattern for @flagfile.txt and --flagfile=flagfile.txt. This doesn't handle @@-escapes. */
55+
private static final Pattern FLAG_FILE_PATTERN = Pattern.compile("(?:@|--?flagfile=)(.+)");
5656

5757
/** The global execRoot. */
5858
private final Path execRoot;
@@ -147,6 +147,10 @@ static WorkerKey createWorkerKey(
147147
protocolFormat);
148148
}
149149

150+
private static boolean isFlagFileArg(String arg) {
151+
return FLAG_FILE_PATTERN.matcher(arg).matches() && !arg.startsWith("@@");
152+
}
153+
150154
/**
151155
* Splits the command-line arguments of the {@code Spawn} into the part that is used to start the
152156
* persistent worker ({@code workerArgs}) and the part that goes into the {@code WorkRequest}
@@ -161,20 +165,20 @@ ImmutableList<String> splitSpawnArgsIntoWorkerArgsAndFlagFiles(
161165
if (args.isEmpty()) {
162166
throwFlagFileFailure(REASON_NO_FLAGFILE, spawn);
163167
}
164-
if (!FLAG_FILE_PATTERN.matcher(Iterables.getLast(args)).matches()) {
168+
if (!isFlagFileArg(Iterables.getLast(args))) {
165169
throwFlagFileFailure(REASON_NO_FINAL_FLAGFILE, spawn);
166170
}
167171
flagFiles.add(Iterables.getLast(args));
168172
for (int i = 0; i < args.size() - 1; i++) {
169-
if (FLAG_FILE_PATTERN.matcher(args.get(i)).matches()) {
173+
if (isFlagFileArg(args.get(i))) {
170174
throwFlagFileFailure(REASON_EXCESS_FLAGFILE, spawn);
171175
} else {
172176
workerArgs.add(args.get(i));
173177
}
174178
}
175179
} else {
176180
for (String arg : spawn.getArguments()) {
177-
if (FLAG_FILE_PATTERN.matcher(arg).matches()) {
181+
if (isFlagFileArg(arg)) {
178182
flagFiles.add(arg);
179183
} else {
180184
workerArgs.add(arg);

0 commit comments

Comments
 (0)