@@ -512,7 +512,8 @@ private int addToFingerprint(
512512 ActionKeyContext actionKeyContext ,
513513 Fingerprint fingerprint ,
514514 @ Nullable InputMetadataProvider inputMetadataProvider ,
515- CoreOptions .OutputPathsMode outputPathsMode )
515+ CoreOptions .OutputPathsMode outputPathsMode ,
516+ RepositoryMapping mainRepoMapping )
516517 throws CommandLineExpansionException , InterruptedException {
517518 StarlarkCallable mapEach = null ;
518519 Location location = null ;
@@ -569,6 +570,10 @@ private int addToFingerprint(
569570 }
570571 } else {
571572 fingerprint .addInt (stringificationType .ordinal ());
573+ if (stringificationType == StringificationType .LABEL ) {
574+ fingerprint .addStringMap (
575+ Maps .transformValues (mainRepoMapping .entries (), RepositoryName ::getName ));
576+ }
572577 actionKeyContext .addNestedSetToFingerprint (fingerprint , values );
573578 }
574579 } else {
@@ -597,7 +602,7 @@ private int addToFingerprint(
597602 starlarkSemantics );
598603 } else {
599604 for (Object value : maybeExpandedValues ) {
600- addSingleObjectToFingerprint (fingerprint , value );
605+ addSingleObjectToFingerprint (fingerprint , value , mainRepoMapping );
601606 }
602607 }
603608 }
@@ -822,9 +827,13 @@ static int preprocess(
822827 return argi ;
823828 }
824829
825- static int addToFingerprint (List <Object > arguments , int argi , Fingerprint fingerprint ) {
830+ static int addToFingerprint (
831+ List <Object > arguments ,
832+ int argi ,
833+ Fingerprint fingerprint ,
834+ @ Nullable RepositoryMapping mainRepoMapping ) {
826835 Object object = arguments .get (argi ++);
827- addSingleObjectToFingerprint (fingerprint , object );
836+ addSingleObjectToFingerprint (fingerprint , object , mainRepoMapping );
828837 String formatStr = (String ) arguments .get (argi ++);
829838 fingerprint .addString (formatStr );
830839 fingerprint .addUUID (SINGLE_FORMATTED_ARG_UUID );
@@ -958,7 +967,7 @@ public final Iterable<String> arguments(
958967 private static Object /* String | DerivedArtifact */ expandToCommandLine (
959968 Object object , @ Nullable RepositoryMapping mainRepoMapping ) {
960969 // Label arguments are rare, so we don't bother rendering them lazily.
961- if (mainRepoMapping != null && object instanceof Label label ) {
970+ if (object instanceof Label label ) {
962971 return label .getDisplayForm (mainRepoMapping );
963972 }
964973
@@ -968,13 +977,14 @@ public final Iterable<String> arguments(
968977 : CommandLineItem .expandToCommandLine (object );
969978 }
970979
971- private static void addSingleObjectToFingerprint (Fingerprint fingerprint , Object object ) {
980+ private static void addSingleObjectToFingerprint (
981+ Fingerprint fingerprint , Object object , @ Nullable RepositoryMapping mainRepoMapping ) {
982+ if (object instanceof Label label ) {
983+ fingerprint .addString (label .getDisplayForm (mainRepoMapping ));
984+ return ;
985+ }
972986 StringificationType stringificationType =
973- switch (object ) {
974- case FileApi ignored -> StringificationType .FILE ;
975- case Label ignored -> StringificationType .LABEL ;
976- default -> StringificationType .DEFAULT ;
977- };
987+ object instanceof FileApi ? StringificationType .FILE : StringificationType .DEFAULT ;
978988 fingerprint .addInt (stringificationType .ordinal ());
979989 fingerprint .addString (CommandLineItem .expandToCommandLine (object ));
980990 }
@@ -1047,11 +1057,12 @@ public void addToFingerprint(
10471057 throws CommandLineExpansionException , InterruptedException {
10481058 List <Object > arguments = rawArgsAsList ();
10491059 int size ;
1050- if ( arguments . getLast () instanceof RepositoryMapping mainRepoMapping ) {
1051- fingerprint . addStringMap (
1052- Maps . transformValues ( mainRepoMapping . entries (), RepositoryName :: getName )) ;
1060+ RepositoryMapping mainRepoMapping ;
1061+ if ( arguments . getLast () instanceof RepositoryMapping mapping ) {
1062+ mainRepoMapping = mapping ;
10531063 size = arguments .size () - 1 ;
10541064 } else {
1065+ mainRepoMapping = null ;
10551066 size = arguments .size ();
10561067 }
10571068 for (int argi = 0 ; argi < size ; ) {
@@ -1065,11 +1076,12 @@ public void addToFingerprint(
10651076 actionKeyContext ,
10661077 fingerprint ,
10671078 inputMetadataProvider ,
1068- effectiveOutputPathsMode );
1079+ effectiveOutputPathsMode ,
1080+ mainRepoMapping );
10691081 } else if (arg == SINGLE_FORMATTED_ARG_MARKER ) {
1070- argi = SingleFormattedArg .addToFingerprint (arguments , argi , fingerprint );
1082+ argi = SingleFormattedArg .addToFingerprint (arguments , argi , fingerprint , mainRepoMapping );
10711083 } else {
1072- addSingleObjectToFingerprint (fingerprint , arg );
1084+ addSingleObjectToFingerprint (fingerprint , arg , mainRepoMapping );
10731085 }
10741086 }
10751087 }
0 commit comments