34
34
import com .google .devtools .build .lib .actions .PathMapper ;
35
35
import com .google .devtools .build .lib .actions .SingleStringArgFormatter ;
36
36
import com .google .devtools .build .lib .cmdline .Label ;
37
+ import com .google .devtools .build .lib .cmdline .RepositoryMapping ;
37
38
import com .google .devtools .build .lib .collect .nestedset .NestedSet ;
38
39
import com .google .devtools .build .lib .concurrent .BlazeInterners ;
39
40
import com .google .devtools .build .lib .concurrent .ThreadSafety .Immutable ;
@@ -580,9 +581,16 @@ static class PrefixArg implements ArgvFragment {
580
581
581
582
private static final UUID PREFIX_UUID = UUID .fromString ("a95eccdf-4f54-46fc-b925-c8c7e1f50c95" );
582
583
583
- private static void push (List <Object > arguments , String before , Object arg ) {
584
+ private static void push (
585
+ List <Object > arguments ,
586
+ String before ,
587
+ Object arg ,
588
+ @ Nullable RepositoryMapping mainRepoMapping ) {
584
589
arguments .add (INSTANCE );
585
590
arguments .add (before );
591
+ if (mainRepoMapping != null ) {
592
+ arguments .add (mainRepoMapping );
593
+ }
586
594
arguments .add (arg );
587
595
}
588
596
@@ -594,6 +602,9 @@ public int eval(
594
602
PathMapper pathMapper ) {
595
603
String before = (String ) arguments .get (argi ++);
596
604
Object arg = arguments .get (argi ++);
605
+ if (arg instanceof RepositoryMapping mainRepoMapping ) {
606
+ arg = ((Label ) arguments .get (argi ++)).getDisplayForm (mainRepoMapping );
607
+ }
597
608
builder .add (before + CommandLineItem .expandToCommandLine (arg ));
598
609
return argi ;
599
610
}
@@ -606,7 +617,11 @@ public int addToFingerprint(
606
617
Fingerprint fingerprint ) {
607
618
fingerprint .addUUID (PREFIX_UUID );
608
619
fingerprint .addString ((String ) arguments .get (argi ++));
609
- fingerprint .addString (CommandLineItem .expandToCommandLine (arguments .get (argi ++)));
620
+ Object arg = arguments .get (argi ++);
621
+ if (arg instanceof RepositoryMapping mainRepoMapping ) {
622
+ arg = ((Label ) arguments .get (argi ++)).getDisplayForm (mainRepoMapping );
623
+ }
624
+ fingerprint .addString (CommandLineItem .expandToCommandLine (arg ));
610
625
return argi ;
611
626
}
612
627
}
@@ -888,22 +903,28 @@ public Builder addFormatted(@FormatString String formatStr, Object... args) {
888
903
889
904
/** Concatenates the passed prefix string and the string. */
890
905
public Builder addPrefixed (@ CompileTimeConstant String prefix , @ Nullable String arg ) {
891
- return addPrefixedInternal (prefix , arg );
906
+ return addPrefixedInternal (prefix , arg , /* mainRepoMapping= */ null );
892
907
}
893
908
894
- /** Concatenates the passed prefix string and the label using {@link Label#getCanonicalForm}. */
895
- public Builder addPrefixedLabel (@ CompileTimeConstant String prefix , @ Nullable Label arg ) {
896
- return addPrefixedInternal (prefix , arg );
909
+ /**
910
+ * Concatenates the passed prefix string and the label using {@link Label#getDisplayForm}, which
911
+ * is identical to {@link Label#getCanonicalForm()} for main repo labels.
912
+ */
913
+ public Builder addPrefixedLabel (
914
+ @ CompileTimeConstant String prefix ,
915
+ @ Nullable Label arg ,
916
+ RepositoryMapping mainRepoMapping ) {
917
+ return addPrefixedInternal (prefix , arg , mainRepoMapping );
897
918
}
898
919
899
920
/** Concatenates the passed prefix string and the path. */
900
921
public Builder addPrefixedPath (@ CompileTimeConstant String prefix , @ Nullable PathFragment arg ) {
901
- return addPrefixedInternal (prefix , arg );
922
+ return addPrefixedInternal (prefix , arg , /* mainRepoMapping= */ null );
902
923
}
903
924
904
925
/** Concatenates the passed prefix string and the artifact's exec path. */
905
926
public Builder addPrefixedExecPath (@ CompileTimeConstant String prefix , @ Nullable Artifact arg ) {
906
- return addPrefixedInternal (prefix , arg );
927
+ return addPrefixedInternal (prefix , arg , /* mainRepoMapping= */ null );
907
928
}
908
929
909
930
/**
@@ -1129,10 +1150,11 @@ private Builder addObjectInternal(@CompileTimeConstant String arg, @Nullable Obj
1129
1150
}
1130
1151
1131
1152
@ CanIgnoreReturnValue
1132
- private Builder addPrefixedInternal (String prefix , @ Nullable Object arg ) {
1153
+ private Builder addPrefixedInternal (
1154
+ String prefix , @ Nullable Object arg , @ Nullable RepositoryMapping mainRepoMapping ) {
1133
1155
Preconditions .checkNotNull (prefix );
1134
1156
if (arg != null ) {
1135
- PrefixArg .push (arguments , prefix , arg );
1157
+ PrefixArg .push (arguments , prefix , arg , mainRepoMapping );
1136
1158
}
1137
1159
return this ;
1138
1160
}
0 commit comments