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
}
@@ -752,6 +767,7 @@ public static final class Builder {
752
767
*
753
768
* <p>Prefer this over its dynamic cousin, as using static strings saves memory.
754
769
*/
770
+ @ CanIgnoreReturnValue
755
771
public Builder add (@ CompileTimeConstant String value ) {
756
772
return addObjectInternal (value );
757
773
}
@@ -761,6 +777,7 @@ public Builder add(@CompileTimeConstant String value) {
761
777
*
762
778
* <p>If the value is null, neither the arg nor the value is added.
763
779
*/
780
+ @ CanIgnoreReturnValue
764
781
public Builder add (@ CompileTimeConstant String arg , @ Nullable String value ) {
765
782
return addObjectInternal (arg , value );
766
783
}
@@ -797,6 +814,7 @@ public Builder addObject(@Nullable Object value) {
797
814
* <p>There are many other ways you can try to avoid calling this. In general, try to use
798
815
* constants or objects that are already on the heap elsewhere.
799
816
*/
817
+ @ CanIgnoreReturnValue
800
818
public Builder addDynamicString (@ Nullable String value ) {
801
819
return addObjectInternal (value );
802
820
}
@@ -807,6 +825,7 @@ public Builder addDynamicString(@Nullable String value) {
807
825
* <p>Prefer this over manually calling {@link Label#getCanonicalForm}, as it avoids a copy of
808
826
* the label value.
809
827
*/
828
+ @ CanIgnoreReturnValue
810
829
public Builder addLabel (@ Nullable Label value ) {
811
830
return addObjectInternal (value );
812
831
}
@@ -819,6 +838,7 @@ public Builder addLabel(@Nullable Label value) {
819
838
*
820
839
* <p>If the value is null, neither the arg nor the value is added.
821
840
*/
841
+ @ CanIgnoreReturnValue
822
842
public Builder addLabel (@ CompileTimeConstant String arg , @ Nullable Label value ) {
823
843
return addObjectInternal (arg , value );
824
844
}
@@ -829,6 +849,7 @@ public Builder addLabel(@CompileTimeConstant String arg, @Nullable Label value)
829
849
* <p>Prefer this over manually calling {@link PathFragment#getPathString}, as it avoids storing
830
850
* a copy of the path string.
831
851
*/
852
+ @ CanIgnoreReturnValue
832
853
public Builder addPath (@ Nullable PathFragment value ) {
833
854
return addObjectInternal (value );
834
855
}
@@ -841,6 +862,7 @@ public Builder addPath(@Nullable PathFragment value) {
841
862
*
842
863
* <p>If the value is null, neither the arg nor the value is added.
843
864
*/
865
+ @ CanIgnoreReturnValue
844
866
public Builder addPath (@ CompileTimeConstant String arg , @ Nullable PathFragment value ) {
845
867
return addObjectInternal (arg , value );
846
868
}
@@ -851,6 +873,7 @@ public Builder addPath(@CompileTimeConstant String arg, @Nullable PathFragment v
851
873
* <p>Prefer this over manually calling {@link Artifact#getExecPath}, as it avoids storing a
852
874
* copy of the artifact path string.
853
875
*/
876
+ @ CanIgnoreReturnValue
854
877
public Builder addExecPath (@ Nullable Artifact value ) {
855
878
return addObjectInternal (value );
856
879
}
@@ -863,16 +886,19 @@ public Builder addExecPath(@Nullable Artifact value) {
863
886
*
864
887
* <p>If the value is null, neither the arg nor the value is added.
865
888
*/
889
+ @ CanIgnoreReturnValue
866
890
public Builder addExecPath (@ CompileTimeConstant String arg , @ Nullable Artifact value ) {
867
891
return addObjectInternal (arg , value );
868
892
}
869
893
870
894
/** Adds a lazily expanded string. */
895
+ @ CanIgnoreReturnValue
871
896
public Builder addLazyString (@ Nullable OnDemandString value ) {
872
897
return addObjectInternal (value );
873
898
}
874
899
875
900
/** Adds a lazily expanded string. */
901
+ @ CanIgnoreReturnValue
876
902
public Builder addLazyString (@ CompileTimeConstant String arg , @ Nullable OnDemandString value ) {
877
903
return addObjectInternal (arg , value );
878
904
}
@@ -887,23 +913,33 @@ public Builder addFormatted(@FormatString String formatStr, Object... args) {
887
913
}
888
914
889
915
/** Concatenates the passed prefix string and the string. */
916
+ @ CanIgnoreReturnValue
890
917
public Builder addPrefixed (@ CompileTimeConstant String prefix , @ Nullable String arg ) {
891
- return addPrefixedInternal (prefix , arg );
918
+ return addPrefixedInternal (prefix , arg , /* mainRepoMapping= */ null );
892
919
}
893
920
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 );
921
+ /**
922
+ * Concatenates the passed prefix string and the label using {@link Label#getDisplayForm}, which
923
+ * is identical to {@link Label#getCanonicalForm()} for main repo labels.
924
+ */
925
+ @ CanIgnoreReturnValue
926
+ public Builder addPrefixedLabel (
927
+ @ CompileTimeConstant String prefix ,
928
+ @ Nullable Label arg ,
929
+ RepositoryMapping mainRepoMapping ) {
930
+ return addPrefixedInternal (prefix , arg , mainRepoMapping );
897
931
}
898
932
899
933
/** Concatenates the passed prefix string and the path. */
934
+ @ CanIgnoreReturnValue
900
935
public Builder addPrefixedPath (@ CompileTimeConstant String prefix , @ Nullable PathFragment arg ) {
901
- return addPrefixedInternal (prefix , arg );
936
+ return addPrefixedInternal (prefix , arg , /* mainRepoMapping= */ null );
902
937
}
903
938
904
939
/** Concatenates the passed prefix string and the artifact's exec path. */
940
+ @ CanIgnoreReturnValue
905
941
public Builder addPrefixedExecPath (@ CompileTimeConstant String prefix , @ Nullable Artifact arg ) {
906
- return addPrefixedInternal (prefix , arg );
942
+ return addPrefixedInternal (prefix , arg , /* mainRepoMapping= */ null );
907
943
}
908
944
909
945
/**
@@ -912,6 +948,7 @@ public Builder addPrefixedExecPath(@CompileTimeConstant String prefix, @Nullable
912
948
* <p>If you are converting long lists or nested sets of a different type to string lists,
913
949
* please try to use a different method that supports what you are trying to do directly.
914
950
*/
951
+ @ CanIgnoreReturnValue
915
952
public Builder addAll (@ Nullable Collection <String > values ) {
916
953
return addCollectionInternal (values );
917
954
}
@@ -922,6 +959,7 @@ public Builder addAll(@Nullable Collection<String> values) {
922
959
* <p>If you are converting long lists or nested sets of a different type to string lists,
923
960
* please try to use a different method that supports what you are trying to do directly.
924
961
*/
962
+ @ CanIgnoreReturnValue
925
963
public Builder addAll (@ Nullable NestedSet <String > values ) {
926
964
return addNestedSetInternal (values );
927
965
}
@@ -934,6 +972,7 @@ public Builder addAll(@Nullable NestedSet<String> values) {
934
972
*
935
973
* <p>If values is empty, the arg isn't added.
936
974
*/
975
+ @ CanIgnoreReturnValue
937
976
public Builder addAll (@ CompileTimeConstant String arg , @ Nullable Collection <String > values ) {
938
977
return addCollectionInternal (arg , values );
939
978
}
@@ -943,11 +982,13 @@ public Builder addAll(@CompileTimeConstant String arg, @Nullable Collection<Stri
943
982
*
944
983
* <p>If values is empty, the arg isn't added.
945
984
*/
985
+ @ CanIgnoreReturnValue
946
986
public Builder addAll (@ CompileTimeConstant String arg , @ Nullable NestedSet <String > values ) {
947
987
return addNestedSetInternal (arg , values );
948
988
}
949
989
950
990
/** Adds the passed vector arg. See {@link VectorArg}. */
991
+ @ CanIgnoreReturnValue
951
992
public Builder addAll (VectorArg <String > vectorArg ) {
952
993
return addVectorArgInternal (vectorArg );
953
994
}
@@ -957,16 +998,19 @@ public Builder addAll(VectorArg<String> vectorArg) {
957
998
*
958
999
* <p>If values is empty, the arg isn't added.
959
1000
*/
1001
+ @ CanIgnoreReturnValue
960
1002
public Builder addAll (@ CompileTimeConstant String arg , VectorArg <String > vectorArg ) {
961
1003
return addVectorArgInternal (arg , vectorArg );
962
1004
}
963
1005
964
1006
/** Adds the passed paths to the command line. */
1007
+ @ CanIgnoreReturnValue
965
1008
public Builder addPaths (@ Nullable Collection <PathFragment > values ) {
966
1009
return addCollectionInternal (values );
967
1010
}
968
1011
969
1012
/** Adds the passed paths to the command line. */
1013
+ @ CanIgnoreReturnValue
970
1014
public Builder addPaths (@ Nullable NestedSet <PathFragment > values ) {
971
1015
return addNestedSetInternal (values );
972
1016
}
@@ -976,6 +1020,7 @@ public Builder addPaths(@Nullable NestedSet<PathFragment> values) {
976
1020
*
977
1021
* <p>If values is empty, the arg isn't added.
978
1022
*/
1023
+ @ CanIgnoreReturnValue
979
1024
public Builder addPaths (
980
1025
@ CompileTimeConstant String arg , @ Nullable Collection <PathFragment > values ) {
981
1026
return addCollectionInternal (arg , values );
@@ -986,12 +1031,14 @@ public Builder addPaths(
986
1031
*
987
1032
* <p>If values is empty, the arg isn't added.
988
1033
*/
1034
+ @ CanIgnoreReturnValue
989
1035
public Builder addPaths (
990
1036
@ CompileTimeConstant String arg , @ Nullable NestedSet <PathFragment > values ) {
991
1037
return addNestedSetInternal (arg , values );
992
1038
}
993
1039
994
1040
/** Adds the passed vector arg. See {@link VectorArg}. */
1041
+ @ CanIgnoreReturnValue
995
1042
public Builder addPaths (VectorArg <PathFragment > vectorArg ) {
996
1043
return addVectorArgInternal (vectorArg );
997
1044
}
@@ -1001,6 +1048,7 @@ public Builder addPaths(VectorArg<PathFragment> vectorArg) {
1001
1048
*
1002
1049
* <p>If values is empty, the arg isn't added.
1003
1050
*/
1051
+ @ CanIgnoreReturnValue
1004
1052
public Builder addPaths (@ CompileTimeConstant String arg , VectorArg <PathFragment > vectorArg ) {
1005
1053
return addVectorArgInternal (arg , vectorArg );
1006
1054
}
@@ -1011,11 +1059,13 @@ public Builder addPaths(@CompileTimeConstant String arg, VectorArg<PathFragment>
1011
1059
* <p>Do not use this method if the list is derived from a flattened nested set. Instead, figure
1012
1060
* out how to avoid flattening the set and use {@link #addExecPaths(NestedSet)}.
1013
1061
*/
1062
+ @ CanIgnoreReturnValue
1014
1063
public Builder addExecPaths (@ Nullable Collection <Artifact > values ) {
1015
1064
return addCollectionInternal (values );
1016
1065
}
1017
1066
1018
1067
/** Adds the artifacts' exec paths to the command line. */
1068
+ @ CanIgnoreReturnValue
1019
1069
public Builder addExecPaths (@ Nullable NestedSet <Artifact > values ) {
1020
1070
return addNestedSetInternal (values );
1021
1071
}
@@ -1028,6 +1078,7 @@ public Builder addExecPaths(@Nullable NestedSet<Artifact> values) {
1028
1078
*
1029
1079
* <p>If values is empty, the arg isn't added.
1030
1080
*/
1081
+ @ CanIgnoreReturnValue
1031
1082
public Builder addExecPaths (
1032
1083
@ CompileTimeConstant String arg , @ Nullable Collection <Artifact > values ) {
1033
1084
return addCollectionInternal (arg , values );
@@ -1038,12 +1089,14 @@ public Builder addExecPaths(
1038
1089
*
1039
1090
* <p>If values is empty, the arg isn't added.
1040
1091
*/
1092
+ @ CanIgnoreReturnValue
1041
1093
public Builder addExecPaths (
1042
1094
@ CompileTimeConstant String arg , @ Nullable NestedSet <Artifact > values ) {
1043
1095
return addNestedSetInternal (arg , values );
1044
1096
}
1045
1097
1046
1098
/** Adds the passed vector arg. See {@link VectorArg}. */
1099
+ @ CanIgnoreReturnValue
1047
1100
public Builder addExecPaths (VectorArg <Artifact > vectorArg ) {
1048
1101
return addVectorArgInternal (vectorArg );
1049
1102
}
@@ -1053,6 +1106,7 @@ public Builder addExecPaths(VectorArg<Artifact> vectorArg) {
1053
1106
*
1054
1107
* <p>If values is empty, the arg isn't added.
1055
1108
*/
1109
+ @ CanIgnoreReturnValue
1056
1110
public Builder addExecPaths (@ CompileTimeConstant String arg , VectorArg <Artifact > vectorArg ) {
1057
1111
return addVectorArgInternal (arg , vectorArg );
1058
1112
}
@@ -1129,10 +1183,11 @@ private Builder addObjectInternal(@CompileTimeConstant String arg, @Nullable Obj
1129
1183
}
1130
1184
1131
1185
@ CanIgnoreReturnValue
1132
- private Builder addPrefixedInternal (String prefix , @ Nullable Object arg ) {
1186
+ private Builder addPrefixedInternal (
1187
+ String prefix , @ Nullable Object arg , @ Nullable RepositoryMapping mainRepoMapping ) {
1133
1188
Preconditions .checkNotNull (prefix );
1134
1189
if (arg != null ) {
1135
- PrefixArg .push (arguments , prefix , arg );
1190
+ PrefixArg .push (arguments , prefix , arg , mainRepoMapping );
1136
1191
}
1137
1192
return this ;
1138
1193
}
0 commit comments