34
34
import com .google .devtools .build .lib .bazel .repository .downloader .DownloadManager ;
35
35
import com .google .devtools .build .lib .bazel .repository .starlark .StarlarkRepositoryModule .RepositoryRuleFunction ;
36
36
import com .google .devtools .build .lib .cmdline .BazelModuleContext ;
37
+ import com .google .devtools .build .lib .cmdline .BazelStarlarkContext ;
38
+ import com .google .devtools .build .lib .cmdline .BazelStarlarkContext .Phase ;
37
39
import com .google .devtools .build .lib .cmdline .Label ;
38
40
import com .google .devtools .build .lib .cmdline .LabelConstants ;
39
41
import com .google .devtools .build .lib .cmdline .LabelSyntaxException ;
@@ -132,6 +134,12 @@ public SkyValue compute(SkyKey skyKey, Environment env)
132
134
if (starlarkSemantics == null ) {
133
135
return null ;
134
136
}
137
+ RepositoryMappingValue mainRepoMappingValue =
138
+ (RepositoryMappingValue )
139
+ env .getValue (RepositoryMappingValue .KEY_FOR_ROOT_MODULE_WITHOUT_WORKSPACE_REPOS );
140
+ if (mainRepoMappingValue == null ) {
141
+ return null ;
142
+ }
135
143
136
144
ModuleExtensionId extensionId = (ModuleExtensionId ) skyKey .argument ();
137
145
SingleExtensionUsagesValue usagesValue =
@@ -182,7 +190,12 @@ public SkyValue compute(SkyKey skyKey, Environment env)
182
190
// Run that extension!
183
191
env .getListener ().post (ModuleExtensionEvaluationProgress .ongoing (extensionId , "starting" ));
184
192
RunModuleExtensionResult moduleExtensionResult =
185
- extension .run (env , usagesValue , starlarkSemantics , extensionId );
193
+ extension .run (
194
+ env ,
195
+ usagesValue ,
196
+ starlarkSemantics ,
197
+ extensionId ,
198
+ mainRepoMappingValue .getRepositoryMapping ());
186
199
if (moduleExtensionResult == null ) {
187
200
return null ;
188
201
}
@@ -525,7 +538,8 @@ RunModuleExtensionResult run(
525
538
Environment env ,
526
539
SingleExtensionUsagesValue usagesValue ,
527
540
StarlarkSemantics starlarkSemantics ,
528
- ModuleExtensionId extensionId )
541
+ ModuleExtensionId extensionId ,
542
+ RepositoryMapping repositoryMapping )
529
543
throws InterruptedException , SingleExtensionEvalFunctionException ;
530
544
}
531
545
@@ -677,7 +691,8 @@ public RunModuleExtensionResult run(
677
691
Environment env ,
678
692
SingleExtensionUsagesValue usagesValue ,
679
693
StarlarkSemantics starlarkSemantics ,
680
- ModuleExtensionId extensionId )
694
+ ModuleExtensionId extensionId ,
695
+ RepositoryMapping mainRepositoryMapping )
681
696
throws InterruptedException , SingleExtensionEvalFunctionException {
682
697
var generatedRepoSpecs = ImmutableMap .<String , RepoSpec >builderWithExpectedSize (repos .size ());
683
698
// Instantiate the repos one by one.
@@ -846,7 +861,8 @@ public RunModuleExtensionResult run(
846
861
Environment env ,
847
862
SingleExtensionUsagesValue usagesValue ,
848
863
StarlarkSemantics starlarkSemantics ,
849
- ModuleExtensionId extensionId )
864
+ ModuleExtensionId extensionId ,
865
+ RepositoryMapping mainRepositoryMapping )
850
866
throws InterruptedException , SingleExtensionEvalFunctionException {
851
867
ModuleExtensionEvalStarlarkThreadContext threadContext =
852
868
new ModuleExtensionEvalStarlarkThreadContext (
@@ -870,6 +886,8 @@ public RunModuleExtensionResult run(
870
886
thread .setPrintHandler (Event .makeDebugPrintHandler (env .getListener ()));
871
887
moduleContext = createContext (env , usagesValue , starlarkSemantics , extensionId );
872
888
threadContext .storeInThread (thread );
889
+ new BazelStarlarkContext (Phase .WORKSPACE , () -> mainRepositoryMapping )
890
+ .storeInThread (thread );
873
891
// This is used by the `Label()` constructor in Starlark, to record any attempts to resolve
874
892
// apparent repo names to canonical repo names. See #20721 for why this is necessary.
875
893
thread .setThreadLocal (Label .RepoMappingRecorder .class , repoMappingRecorder );
0 commit comments