@@ -165,7 +165,7 @@ public static BzlLoadFunction create(
165
165
// (b) The memory overhead of the extra Skyframe node and edge per bzl file is pure
166
166
// waste.
167
167
new InliningAndCachingGetter (packageFactory , hashFunction , bzlCompileCache ),
168
- /*cachedBzlLoadDataManager=*/ null );
168
+ /* cachedBzlLoadDataManager= */ null );
169
169
}
170
170
171
171
public static BzlLoadFunction createForInlining (
@@ -188,7 +188,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
188
188
throws SkyFunctionException , InterruptedException {
189
189
BzlLoadValue .Key key = (BzlLoadValue .Key ) skyKey .argument ();
190
190
try {
191
- return computeInternal (key , env , /*inliningState=*/ null );
191
+ return computeInternal (key , env , /* inliningState= */ null );
192
192
} catch (BzlLoadFailedException e ) {
193
193
throw new BzlLoadFunctionException (e );
194
194
}
@@ -455,12 +455,12 @@ private InliningState(
455
455
static InliningState create (Environment env ) {
456
456
return new InliningState (
457
457
new RecordingSkyFunctionEnvironment (env , x -> {}, x -> {}, x -> {}),
458
- /*cachedDataBuilder=*/ null ,
459
- /*loadStack=*/ new LinkedHashSet <>(),
460
- /*successfulLoads=*/ new HashMap <>(),
461
- /*unsuccessfulLoads=*/ new HashSet <>(),
458
+ /* cachedDataBuilder= */ null ,
459
+ /* loadStack= */ new LinkedHashSet <>(),
460
+ /* successfulLoads= */ new HashMap <>(),
461
+ /* unsuccessfulLoads= */ new HashSet <>(),
462
462
// No parent value to mutate
463
- /*childCachedDataHandler=*/ x -> {});
463
+ /* childCachedDataHandler= */ x -> {});
464
464
}
465
465
466
466
/**
@@ -598,7 +598,10 @@ private StarlarkBuiltinsValue getBuiltins(
598
598
env .getValueOrThrow (StarlarkBuiltinsValue .key (), BuiltinsFailedException .class );
599
599
} else {
600
600
return StarlarkBuiltinsFunction .computeInline (
601
- StarlarkBuiltinsValue .key (), inliningState , packageFactory , /*bzlLoadFunction=*/ this );
601
+ StarlarkBuiltinsValue .key (),
602
+ inliningState ,
603
+ packageFactory ,
604
+ /* bzlLoadFunction= */ this );
602
605
}
603
606
} catch (BuiltinsFailedException e ) {
604
607
throw BzlLoadFailedException .builtinsFailed (key .getLabel (), e );
@@ -776,7 +779,7 @@ private BzlLoadValue computeInternalWithCompiledBzl(
776
779
loadValues ,
777
780
loadKeys ,
778
781
programLoads ,
779
- /*demoteErrorsToWarnings=*/ !builtins .starlarkSemantics .getBool (
782
+ /* demoteErrorsToWarnings= */ !builtins .starlarkSemantics .getBool (
780
783
BuildLanguageOptions .CHECK_BZL_VISIBILITY ),
781
784
env .getListener ());
782
785
@@ -845,7 +848,8 @@ private BzlLoadValue computeInternalWithCompiledBzl(
845
848
private static RepositoryMapping getRepositoryMapping (
846
849
BzlLoadValue .Key key , StarlarkSemantics semantics , Environment env )
847
850
throws InterruptedException {
848
- if (key .isBuiltins () && !semantics .getBool (BuildLanguageOptions .ENABLE_BZLMOD )) {
851
+ boolean bzlmod = semantics .getBool (BuildLanguageOptions .ENABLE_BZLMOD );
852
+ if (key .isBuiltins () && !bzlmod ) {
849
853
// Without Bzlmod, builtins .bzls never have a repo mapping defined for them, so return
850
854
// without requesting a RepositoryMappingValue. (NB: In addition to being a slight
851
855
// optimization, this avoids adding a reverse dependency on the special //external package,
@@ -862,21 +866,37 @@ private static RepositoryMapping getRepositoryMapping(
862
866
if (key instanceof BzlLoadValue .KeyForWorkspace ) {
863
867
// Still during workspace file evaluation
864
868
BzlLoadValue .KeyForWorkspace keyForWorkspace = (BzlLoadValue .KeyForWorkspace ) key ;
869
+ RepositoryMapping pureWorkspaceMapping ;
865
870
if (keyForWorkspace .getWorkspaceChunk () == 0 ) {
866
871
// There is no previous workspace chunk
867
- return RepositoryMapping .ALWAYS_FALLBACK ;
872
+ pureWorkspaceMapping = RepositoryMapping .ALWAYS_FALLBACK ;
868
873
} else {
869
874
SkyKey workspaceFileKey =
870
875
WorkspaceFileValue .key (
871
876
keyForWorkspace .getWorkspacePath (), keyForWorkspace .getWorkspaceChunk () - 1 );
872
877
WorkspaceFileValue workspaceFileValue = (WorkspaceFileValue ) env .getValue (workspaceFileKey );
873
878
// Note: we know for sure that the requested WorkspaceFileValue is fully computed so we do
874
879
// not need to check if it is null
875
- return RepositoryMapping .createAllowingFallback (
876
- workspaceFileValue .getRepositoryMapping ().getOrDefault (repoName , ImmutableMap .of ()));
877
- // NOTE(wyv): this means that, in the WORKSPACE file, we can't load from a repo generated by
878
- // bzlmod. If that's a problem, we should "fall back" to the bzlmod case below.
880
+ pureWorkspaceMapping =
881
+ RepositoryMapping .createAllowingFallback (
882
+ workspaceFileValue
883
+ .getRepositoryMapping ()
884
+ .getOrDefault (repoName , ImmutableMap .of ()));
885
+ }
886
+ if (!bzlmod ) {
887
+ // Without Bzlmod, we just return the mapping purely computed from WORKSPACE stuff.
888
+ return pureWorkspaceMapping ;
889
+ }
890
+ // If Bzlmod is in play, we need to make sure that pure WORKSPACE mapping is composed with the
891
+ // root module's mapping (just like how all WORKSPACE repos can see what the root module sees
892
+ // _after_ WORKSPACE evaluation).
893
+ RepositoryMappingValue rootModuleMappingValue =
894
+ (RepositoryMappingValue )
895
+ env .getValue (RepositoryMappingValue .KEY_FOR_ROOT_MODULE_WITHOUT_WORKSPACE_REPOS );
896
+ if (rootModuleMappingValue == null ) {
897
+ return null ;
879
898
}
899
+ return pureWorkspaceMapping .composeWith (rootModuleMappingValue .getRepositoryMapping ());
880
900
}
881
901
882
902
if (key instanceof BzlLoadValue .KeyForBzlmod ) {
@@ -903,9 +923,8 @@ private static RepositoryMapping getRepositoryMapping(
903
923
}
904
924
}
905
925
906
- // This is either a .bzl loaded from BUILD files, or a .bzl loaded for bzlmod (in which case the
907
- // .bzl file *has* to be from a Bazel module anyway). So we can just use the full repo mapping
908
- // from RepositoryMappingFunction.
926
+ // This is either a .bzl loaded from BUILD files, or a .bzl loaded for bzlmod, so we can just
927
+ // use the full repo mapping from RepositoryMappingFunction.
909
928
RepositoryMappingValue repositoryMappingValue =
910
929
(RepositoryMappingValue ) env .getValue (RepositoryMappingValue .key (repoName ));
911
930
if (repositoryMappingValue == null ) {
0 commit comments