26
26
import com .google .devtools .build .lib .actions .FileValue ;
27
27
import com .google .devtools .build .lib .analysis .BlazeDirectories ;
28
28
import com .google .devtools .build .lib .cmdline .LabelConstants ;
29
+ import com .google .devtools .build .lib .cmdline .LabelSyntaxException ;
29
30
import com .google .devtools .build .lib .cmdline .LabelValidator ;
30
31
import com .google .devtools .build .lib .cmdline .RepositoryName ;
31
32
import com .google .devtools .build .lib .skyframe .ActionEnvironmentFunction ;
@@ -76,8 +77,10 @@ public abstract static class Parser {
76
77
77
78
/**
78
79
* Parses a recorded input from the post-colon substring that identifies the specific input: for
79
- * example, the {@code MY_ENV_VAR} part of {@code ENV:MY_ENV_VAR}.
80
+ * example, the {@code MY_ENV_VAR} part of {@code ENV:MY_ENV_VAR}. Returns null if the parsed
81
+ * part is invalid.
80
82
*/
83
+ @ Nullable
81
84
public abstract RepoRecordedInput parse (String s );
82
85
}
83
86
@@ -95,6 +98,9 @@ public abstract static class Parser {
95
98
@ Nullable
96
99
public static RepoRecordedInput parse (String s ) {
97
100
List <String > parts = Splitter .on (':' ).limit (2 ).splitToList (s );
101
+ if (parts .size () < 2 ) {
102
+ return null ;
103
+ }
98
104
for (Parser parser :
99
105
new Parser [] {
100
106
File .PARSER , Dirents .PARSER , DirTree .PARSER , EnvVar .PARSER , RecordedRepoMapping .PARSER
@@ -213,12 +219,12 @@ public final String toString() {
213
219
return repoName ().map (repoName -> repoName + "//" + path ()).orElse (path ().toString ());
214
220
}
215
221
216
- public static RepoCacheFriendlyPath parse (String s ) {
222
+ public static RepoCacheFriendlyPath parse (String s ) throws LabelSyntaxException {
217
223
if (LabelValidator .isAbsolute (s )) {
218
224
int doubleSlash = s .indexOf ("//" );
219
225
int skipAts = s .startsWith ("@@" ) ? 2 : s .startsWith ("@" ) ? 1 : 0 ;
220
226
return createInsideWorkspace (
221
- RepositoryName .createUnvalidated (s .substring (skipAts , doubleSlash )),
227
+ RepositoryName .create (s .substring (skipAts , doubleSlash )),
222
228
PathFragment .create (s .substring (doubleSlash + 2 )));
223
229
}
224
230
return createOutsideWorkspace (PathFragment .create (s ));
@@ -262,9 +268,15 @@ public String getPrefix() {
262
268
return "FILE" ;
263
269
}
264
270
271
+ @ Nullable
265
272
@ Override
266
273
public RepoRecordedInput parse (String s ) {
267
- return new File (RepoCacheFriendlyPath .parse (s ));
274
+ try {
275
+ return new File (RepoCacheFriendlyPath .parse (s ));
276
+ } catch (LabelSyntaxException e ) {
277
+ // ignore malformed input
278
+ return null ;
279
+ }
268
280
}
269
281
};
270
282
@@ -354,9 +366,15 @@ public String getPrefix() {
354
366
return "DIRENTS" ;
355
367
}
356
368
369
+ @ Nullable
357
370
@ Override
358
371
public RepoRecordedInput parse (String s ) {
359
- return new Dirents (RepoCacheFriendlyPath .parse (s ));
372
+ try {
373
+ return new Dirents (RepoCacheFriendlyPath .parse (s ));
374
+ } catch (LabelSyntaxException e ) {
375
+ // Ignore malformed input.
376
+ return null ;
377
+ }
360
378
}
361
379
};
362
380
@@ -437,9 +455,15 @@ public String getPrefix() {
437
455
return "DIRTREE" ;
438
456
}
439
457
458
+ @ Nullable
440
459
@ Override
441
460
public RepoRecordedInput parse (String s ) {
442
- return new DirTree (RepoCacheFriendlyPath .parse (s ));
461
+ try {
462
+ return new DirTree (RepoCacheFriendlyPath .parse (s ));
463
+ } catch (LabelSyntaxException e ) {
464
+ // ignore malformed input
465
+ return null ;
466
+ }
443
467
}
444
468
};
445
469
@@ -573,11 +597,16 @@ public String getPrefix() {
573
597
return "REPO_MAPPING" ;
574
598
}
575
599
600
+ @ Nullable
576
601
@ Override
577
602
public RepoRecordedInput parse (String s ) {
578
603
List <String > parts = Splitter .on (',' ).limit (2 ).splitToList (s );
579
- return new RecordedRepoMapping (
580
- RepositoryName .createUnvalidated (parts .get (0 )), parts .get (1 ));
604
+ try {
605
+ return new RecordedRepoMapping (RepositoryName .create (parts .get (0 )), parts .get (1 ));
606
+ } catch (LabelSyntaxException | IndexOutOfBoundsException e ) {
607
+ // ignore malformed input
608
+ return null ;
609
+ }
581
610
}
582
611
};
583
612
@@ -632,9 +661,14 @@ public boolean isUpToDate(
632
661
throws InterruptedException {
633
662
RepositoryMappingValue repoMappingValue =
634
663
(RepositoryMappingValue ) env .getValue (getSkyKey (directories ));
635
- return repoMappingValue != RepositoryMappingValue .NOT_FOUND_VALUE
636
- && RepositoryName .createUnvalidated (oldValue )
637
- .equals (repoMappingValue .getRepositoryMapping ().get (apparentName ));
664
+ try {
665
+ return repoMappingValue != RepositoryMappingValue .NOT_FOUND_VALUE
666
+ && RepositoryName .create (oldValue )
667
+ .equals (repoMappingValue .getRepositoryMapping ().get (apparentName ));
668
+ } catch (LabelSyntaxException e ) {
669
+ // ignore malformed old value
670
+ return false ;
671
+ }
638
672
}
639
673
}
640
674
}
0 commit comments