|
65 | 65 | import java.util.LinkedHashSet;
|
66 | 66 | import java.util.List;
|
67 | 67 | import java.util.Map;
|
68 |
| -import java.util.Optional; |
69 | 68 | import java.util.concurrent.atomic.AtomicBoolean;
|
70 | 69 | import java.util.function.Consumer;
|
71 | 70 | import javax.annotation.Nullable;
|
@@ -763,7 +762,7 @@ private BzlLoadValue computeInternalWithCompiledBzl(
|
763 | 762 | if (repoMapping == null) {
|
764 | 763 | return null;
|
765 | 764 | }
|
766 |
| - Optional<RepositoryMapping> mainRepoMapping = |
| 765 | + RepositoryMapping mainRepoMapping = |
767 | 766 | getMainRepositoryMapping(key, builtins.starlarkSemantics, env);
|
768 | 767 | if (mainRepoMapping == null) {
|
769 | 768 | return null;
|
@@ -846,7 +845,7 @@ private BzlLoadValue computeInternalWithCompiledBzl(
|
846 | 845 | BazelModuleContext.create(
|
847 | 846 | label,
|
848 | 847 | repoMapping,
|
849 |
| - mainRepoMapping.orElse(null), |
| 848 | + mainRepoMapping, |
850 | 849 | prog.getFilename(),
|
851 | 850 | ImmutableList.copyOf(loadMap.values()),
|
852 | 851 | transitiveDigest);
|
@@ -980,30 +979,29 @@ private static RepositoryMapping getRepositoryMapping(
|
980 | 979 | }
|
981 | 980 |
|
982 | 981 | @Nullable
|
983 |
| - private static Optional<RepositoryMapping> getMainRepositoryMapping( |
| 982 | + private static RepositoryMapping getMainRepositoryMapping( |
984 | 983 | BzlLoadValue.Key key, StarlarkSemantics starlarkSemantics, Environment env)
|
985 | 984 | throws InterruptedException {
|
986 |
| - if (!starlarkSemantics.getBool(BuildLanguageOptions.ENABLE_BZLMOD)) { |
987 |
| - return Optional.empty(); |
988 |
| - } |
| 985 | + boolean bzlmod = starlarkSemantics.getBool(BuildLanguageOptions.ENABLE_BZLMOD); |
989 | 986 | RepositoryMappingValue.Key repoMappingKey;
|
990 | 987 | if (key instanceof BzlLoadValue.KeyForBuild) {
|
991 | 988 | repoMappingKey = RepositoryMappingValue.key(RepositoryName.MAIN);
|
992 | 989 | } else if ((key instanceof BzlLoadValue.KeyForBzlmod
|
993 | 990 | && !(key instanceof BzlLoadValue.KeyForBzlmodBootstrap))
|
994 |
| - || key instanceof BzlLoadValue.KeyForWorkspace) { |
| 991 | + || (bzlmod && key instanceof BzlLoadValue.KeyForWorkspace)) { |
995 | 992 | // Since the main repo mapping requires evaluating WORKSPACE, but WORKSPACE can load from
|
996 | 993 | // extension repos, requesting the full main repo mapping would cause a cycle.
|
997 | 994 | repoMappingKey = RepositoryMappingValue.KEY_FOR_ROOT_MODULE_WITHOUT_WORKSPACE_REPOS;
|
998 | 995 | } else {
|
999 |
| - // Builtins and Bzlmod bootstrap repo rules don't need the main repo mapping. |
1000 |
| - return Optional.empty(); |
| 996 | + // For builtins, @bazel_tools, and legacy WORKSPACE, the key's local repo mapping can be used |
| 997 | + // as the main repo mapping. |
| 998 | + return getRepositoryMapping(key, starlarkSemantics, env); |
1001 | 999 | }
|
1002 | 1000 | var mainRepositoryMappingValue = (RepositoryMappingValue) env.getValue(repoMappingKey);
|
1003 | 1001 | if (mainRepositoryMappingValue == null) {
|
1004 | 1002 | return null;
|
1005 | 1003 | }
|
1006 |
| - return Optional.of(mainRepositoryMappingValue.getRepositoryMapping()); |
| 1004 | + return mainRepositoryMappingValue.getRepositoryMapping(); |
1007 | 1005 | }
|
1008 | 1006 |
|
1009 | 1007 | /**
|
|
0 commit comments