@@ -248,6 +248,13 @@ public enum ConfigSettingVisibilityPolicy {
248
248
*/
249
249
private RepositoryMapping repositoryMapping ;
250
250
251
+ /**
252
+ * The repository mapping of the main repository. This is only used internally to obtain
253
+ * user-friendly apparent names from canonical repository names in error message arising from this
254
+ * package.
255
+ */
256
+ private RepositoryMapping mainRepositoryMapping ;
257
+
251
258
private Set <Label > defaultCompatibleWith = ImmutableSet .of ();
252
259
private Set <Label > defaultRestrictedTo = ImmutableSet .of ();
253
260
@@ -478,6 +485,7 @@ private void finishInit(Builder builder) {
478
485
this .registeredExecutionPlatforms = ImmutableList .copyOf (builder .registeredExecutionPlatforms );
479
486
this .registeredToolchains = ImmutableList .copyOf (builder .registeredToolchains );
480
487
this .repositoryMapping = Preconditions .checkNotNull (builder .repositoryMapping );
488
+ this .mainRepositoryMapping = Preconditions .checkNotNull (builder .mainRepositoryMapping );
481
489
ImmutableMap .Builder <RepositoryName , ImmutableMap <String , RepositoryName >>
482
490
repositoryMappingsBuilder = ImmutableMap .builder ();
483
491
if (!builder .externalPackageRepositoryMappings .isEmpty () && !builder .isRepoRulePackage ()) {
@@ -731,7 +739,7 @@ private String getAlternateTargetSuggestion(String targetName) {
731
739
String blazeQuerySuggestion =
732
740
String .format (
733
741
"Tip: use `query %s:*` to see all the targets in that package" ,
734
- packageIdentifier .getCanonicalForm ( ));
742
+ packageIdentifier .getDisplayForm ( mainRepositoryMapping ));
735
743
return String .format (
736
744
" (%s)" , Joiner .on (" " ).skipNulls ().join (targetSuggestion , blazeQuerySuggestion ));
737
745
}
@@ -880,6 +888,7 @@ public static Builder newExternalPackageBuilder(
880
888
LabelConstants .EXTERNAL_PACKAGE_IDENTIFIER ,
881
889
workspaceName ,
882
890
starlarkSemantics .getBool (BuildLanguageOptions .INCOMPATIBLE_NO_IMPLICIT_FILE_EXPORT ),
891
+ mainRepoMapping ,
883
892
mainRepoMapping )
884
893
.setFilename (workspacePath );
885
894
}
@@ -894,7 +903,11 @@ public static Builder newExternalPackageBuilderForBzlmod(
894
903
basePackageId ,
895
904
DUMMY_WORKSPACE_NAME_FOR_BZLMOD_PACKAGES ,
896
905
starlarkSemantics .getBool (BuildLanguageOptions .INCOMPATIBLE_NO_IMPLICIT_FILE_EXPORT ),
897
- repoMapping )
906
+ repoMapping ,
907
+ // This mapping is *not* the main repository's mapping, but since it is only used to
908
+ // construct a query command in an error message and the package built here can't be
909
+ // seen by query, the particular value does not matter.
910
+ RepositoryMapping .ALWAYS_FALLBACK )
898
911
.setFilename (moduleFilePath );
899
912
}
900
913
@@ -974,6 +987,11 @@ public boolean recordLoadedModules() {
974
987
* workspace.
975
988
*/
976
989
private final RepositoryMapping repositoryMapping ;
990
+ /**
991
+ * The repository mapping of the main repository. This is only used to resolve user-friendly
992
+ * apparent names from canonical repository names in error message arising from this package.
993
+ */
994
+ private final RepositoryMapping mainRepositoryMapping ;
977
995
/** Converts label literals to Label objects within this package. */
978
996
private final LabelConverter labelConverter ;
979
997
@@ -1098,10 +1116,12 @@ public T intern(T sample) {
1098
1116
PackageIdentifier id ,
1099
1117
String workspaceName ,
1100
1118
boolean noImplicitFileExport ,
1101
- RepositoryMapping repositoryMapping ) {
1119
+ RepositoryMapping repositoryMapping ,
1120
+ RepositoryMapping mainRepositoryMapping ) {
1102
1121
this .pkg = new Package (id , workspaceName , packageSettings .succinctTargetNotFoundErrors ());
1103
1122
this .noImplicitFileExport = noImplicitFileExport ;
1104
1123
this .repositoryMapping = repositoryMapping ;
1124
+ this .mainRepositoryMapping = mainRepositoryMapping ;
1105
1125
this .labelConverter = new LabelConverter (id , repositoryMapping );
1106
1126
if (pkg .getName ().startsWith ("javatests/" )) {
1107
1127
setDefaultTestonly (true );
0 commit comments