bzlmod: Refactor repository mapping with a new class
To support strict repository dependency in Bzlmod, we need to distinguish repo mapping behaviour between repos generated from Bzlmod and WORKSPACE, therefore we have to refactor the repo mapping from a ImmutableMap to the RepositoryMapping class.
Working towards: https://github.com/bazelbuild/bazel/issues/13793
Related: https://github.com/bazelbuild/bazel/issues/13316
RELNOTES: None
PiperOrigin-RevId: 394180770
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java b/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java
index 2e92de0..fdf64e6 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java
@@ -18,6 +18,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.LocationExpander.LocationFunction;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import java.util.ArrayList;
import java.util.List;
@@ -73,7 +74,7 @@
ImmutableMap.<String, LocationFunction>of(
"location", f1,
"locations", f2),
- ImmutableMap.of());
+ RepositoryMapping.ALWAYS_FALLBACK);
}
private String expand(String input) throws Exception {
@@ -133,10 +134,11 @@
RepositoryName.create("@foo"),
RepositoryName.create("@bar"));
- LocationExpander locationExpander = new LocationExpander(
- new Capture(),
- ImmutableMap.<String, LocationFunction>of("location", f1),
- repositoryMapping);
+ LocationExpander locationExpander =
+ new LocationExpander(
+ new Capture(),
+ ImmutableMap.<String, LocationFunction>of("location", f1),
+ RepositoryMapping.createAllowingFallback(repositoryMapping));
String value = locationExpander.expand("$(location @foo//a)");
assertThat(value).isEqualTo("src/a");
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java
index 311ae2e..c333ad7 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java
@@ -25,6 +25,7 @@
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.LocationExpander.LocationFunction;
import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
@@ -47,23 +48,25 @@
public void absoluteAndRelativeLabels() throws Exception {
LocationFunction func =
new LocationFunctionBuilder("//foo", false).add("//foo", "/exec/src/bar").build();
- assertThat(func.apply("//foo", ImmutableMap.of())).isEqualTo("src/bar");
- assertThat(func.apply(":foo", ImmutableMap.of())).isEqualTo("src/bar");
- assertThat(func.apply("foo", ImmutableMap.of())).isEqualTo("src/bar");
+ assertThat(func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK)).isEqualTo("src/bar");
+ assertThat(func.apply(":foo", RepositoryMapping.ALWAYS_FALLBACK)).isEqualTo("src/bar");
+ assertThat(func.apply("foo", RepositoryMapping.ALWAYS_FALLBACK)).isEqualTo("src/bar");
}
@Test
public void pathUnderExecRootUsesDotSlash() throws Exception {
LocationFunction func =
new LocationFunctionBuilder("//foo", false).add("//foo", "/exec/bar").build();
- assertThat(func.apply("//foo", ImmutableMap.of())).isEqualTo("./bar");
+ assertThat(func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK)).isEqualTo("./bar");
}
@Test
public void noSuchLabel() throws Exception {
LocationFunction func = new LocationFunctionBuilder("//foo", false).build();
IllegalStateException expected =
- assertThrows(IllegalStateException.class, () -> func.apply("//bar", ImmutableMap.of()));
+ assertThrows(
+ IllegalStateException.class,
+ () -> func.apply("//bar", RepositoryMapping.ALWAYS_FALLBACK));
assertThat(expected)
.hasMessageThat()
.isEqualTo(
@@ -75,7 +78,9 @@
public void emptyList() throws Exception {
LocationFunction func = new LocationFunctionBuilder("//foo", false).add("//foo").build();
IllegalStateException expected =
- assertThrows(IllegalStateException.class, () -> func.apply("//foo", ImmutableMap.of()));
+ assertThrows(
+ IllegalStateException.class,
+ () -> func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK));
assertThat(expected)
.hasMessageThat()
.isEqualTo("label '//foo:foo' in $(location) expression expands to no files");
@@ -86,7 +91,9 @@
LocationFunction func =
new LocationFunctionBuilder("//foo", false).add("//foo", "/exec/1", "/exec/2").build();
IllegalStateException expected =
- assertThrows(IllegalStateException.class, () -> func.apply("//foo", ImmutableMap.of()));
+ assertThrows(
+ IllegalStateException.class,
+ () -> func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK));
assertThat(expected)
.hasMessageThat()
.isEqualTo(
@@ -99,7 +106,9 @@
public void noSuchLabelMultiple() throws Exception {
LocationFunction func = new LocationFunctionBuilder("//foo", true).build();
IllegalStateException expected =
- assertThrows(IllegalStateException.class, () -> func.apply("//bar", ImmutableMap.of()));
+ assertThrows(
+ IllegalStateException.class,
+ () -> func.apply("//bar", RepositoryMapping.ALWAYS_FALLBACK));
assertThat(expected)
.hasMessageThat()
.isEqualTo(
@@ -111,7 +120,8 @@
public void fileWithSpace() throws Exception {
LocationFunction func =
new LocationFunctionBuilder("//foo", false).add("//foo", "/exec/file/with space").build();
- assertThat(func.apply("//foo", ImmutableMap.of())).isEqualTo("'file/with space'");
+ assertThat(func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK))
+ .isEqualTo("'file/with space'");
}
@Test
@@ -119,7 +129,8 @@
LocationFunction func = new LocationFunctionBuilder("//foo", true)
.add("//foo", "/exec/foo/bar", "/exec/out/foo/foobar")
.build();
- assertThat(func.apply("//foo", ImmutableMap.of())).isEqualTo("foo/bar foo/foobar");
+ assertThat(func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK))
+ .isEqualTo("foo/bar foo/foobar");
}
@Test
@@ -127,7 +138,7 @@
LocationFunction func = new LocationFunctionBuilder("//foo", true)
.add("//foo", "/exec/file/with space", "/exec/file/with spaces ")
.build();
- assertThat(func.apply("//foo", ImmutableMap.of()))
+ assertThat(func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK))
.isEqualTo("'file/with space' 'file/with spaces '");
}
@@ -137,7 +148,8 @@
.setExecPaths(true)
.add("//foo", "/exec/bar", "/exec/out/foobar")
.build();
- assertThat(func.apply("//foo", ImmutableMap.of())).isEqualTo("./bar out/foobar");
+ assertThat(func.apply("//foo", RepositoryMapping.ALWAYS_FALLBACK))
+ .isEqualTo("./bar out/foobar");
}
@Test
@@ -147,7 +159,8 @@
ImmutableMap<RepositoryName, RepositoryName> repositoryMapping = ImmutableMap.of(a, b);
LocationFunction func =
new LocationFunctionBuilder("//foo", false).add("@b//foo", "/exec/src/bar").build();
- assertThat(func.apply("@a//foo", repositoryMapping)).isEqualTo("src/bar");
+ assertThat(func.apply("@a//foo", RepositoryMapping.createAllowingFallback(repositoryMapping)))
+ .isEqualTo("src/bar");
}
@Test
@@ -157,7 +170,9 @@
ImmutableMap<RepositoryName, RepositoryName> repositoryMapping = ImmutableMap.of(a, b);
LocationFunction func =
new LocationFunctionBuilder("//foo", false).add("@potato//foo", "/exec/src/bar").build();
- assertThat(func.apply("@potato//foo", repositoryMapping)).isEqualTo("src/bar");
+ assertThat(
+ func.apply("@potato//foo", RepositoryMapping.createAllowingFallback(repositoryMapping)))
+ .isEqualTo("src/bar");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/cmdline/RepositoryMappingTest.java b/src/test/java/com/google/devtools/build/lib/cmdline/RepositoryMappingTest.java
new file mode 100644
index 0000000..c7cb715
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/cmdline/RepositoryMappingTest.java
@@ -0,0 +1,47 @@
+// Copyright 2021 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.cmdline;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for @{link RepositoryMapping}. */
+@RunWith(JUnit4.class)
+public final class RepositoryMappingTest {
+
+ @Test
+ public void maybeFallback() throws Exception {
+ RepositoryMapping mapping =
+ RepositoryMapping.createAllowingFallback(
+ ImmutableMap.of(RepositoryName.create("@A"), RepositoryName.create("@com_foo_bar_a")));
+ assertThat(mapping.get(RepositoryName.create("@A")))
+ .isEqualTo(RepositoryName.create("@com_foo_bar_a"));
+ assertThat(mapping.get(RepositoryName.create("@B"))).isEqualTo(RepositoryName.create("@B"));
+ }
+
+ @Test
+ public void neverFallback() throws Exception {
+ RepositoryMapping mapping =
+ RepositoryMapping.create(
+ ImmutableMap.of(RepositoryName.create("@A"), RepositoryName.create("@com_foo_bar_a")));
+ assertThat(mapping.get(RepositoryName.create("@A")))
+ .isEqualTo(RepositoryName.create("@com_foo_bar_a"));
+ assertThat(mapping.get(RepositoryName.create("@B"))).isNull();
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java b/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java
index 4b07663..b7654fa 100644
--- a/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java
+++ b/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java
@@ -20,7 +20,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.cmdline.TargetPattern.TargetsBelowDirectory;
import com.google.devtools.build.lib.cmdline.TargetPattern.TargetsBelowDirectory.ContainsResult;
-import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -167,10 +166,11 @@
@Test
public void testRenameRepository() throws Exception {
- Map<RepositoryName, RepositoryName> renaming =
- ImmutableMap.of(
- RepositoryName.create("@foo"), RepositoryName.create("@bar"),
- RepositoryName.create("@myworkspace"), RepositoryName.create("@"));
+ RepositoryMapping renaming =
+ RepositoryMapping.createAllowingFallback(
+ ImmutableMap.of(
+ RepositoryName.create("@foo"), RepositoryName.create("@bar"),
+ RepositoryName.create("@myworkspace"), RepositoryName.create("@")));
// Expecting renaming
assertThat(TargetPattern.renameRepository("@foo//package:target", renaming))
diff --git a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
index 8b54a24..316936d 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
@@ -22,6 +22,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.packages.BuildType.LabelConversionContext;
import com.google.devtools.build.lib.packages.BuildType.Selector;
@@ -46,7 +47,7 @@
private final LabelConversionContext labelConversionContext =
new LabelConversionContext(
currentRule,
- /*repositoryMapping=*/ ImmutableMap.of(),
+ RepositoryMapping.ALWAYS_FALLBACK,
/*convertedLabelsInPackage=*/ new HashMap<>());
@Test
@@ -273,8 +274,9 @@
LabelConversionContext context =
new LabelConversionContext(
currentRule,
- ImmutableMap.of(
- RepositoryName.create("@orig_repo"), RepositoryName.create("@new_repo")),
+ RepositoryMapping.createAllowingFallback(
+ ImmutableMap.of(
+ RepositoryName.create("@orig_repo"), RepositoryName.create("@new_repo"))),
/* convertedLabelsInPackage= */ new HashMap<>());
Label label = BuildType.LABEL.convert("@orig_repo//foo:bar", null, context);
assertThat(label)
diff --git a/src/test/java/com/google/devtools/build/lib/packages/PackageTest.java b/src/test/java/com/google/devtools/build/lib/packages/PackageTest.java
index 8b8f190..3d33e49 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/PackageTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/PackageTest.java
@@ -18,9 +18,9 @@
import static org.mockito.Mockito.mock;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.events.StoredEventHandler;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
@@ -164,7 +164,7 @@
PackageIdentifier.createInMainRepo(name),
"workspace",
/*noImplicitFileExport=*/ true,
- ImmutableMap.of());
+ RepositoryMapping.ALWAYS_FALLBACK);
result.setFilename(
RootedPath.toRootedPath(
Root.fromPath(fileSystem.getPath("/irrelevantRoot")), PathFragment.create(name)));
diff --git a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
index eddb34c..23a8192 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/RuleClassTest.java
@@ -45,6 +45,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventCollector;
import com.google.devtools.build.lib.events.EventKind;
@@ -264,7 +265,7 @@
PackageIdentifier.createInMainRepo(TEST_PACKAGE_NAME),
"TESTING",
StarlarkSemantics.DEFAULT,
- /*repositoryMapping=*/ ImmutableMap.of())
+ RepositoryMapping.ALWAYS_FALLBACK)
.setFilename(RootedPath.toRootedPath(root, testBuildfilePath));
}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java
index 52c9666..df85e78 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/RuleFactoryTest.java
@@ -26,6 +26,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelConstants;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap;
import com.google.devtools.build.lib.packages.util.PackageLoadingTestCase;
@@ -58,7 +59,7 @@
private Package.Builder newBuilder(PackageIdentifier id, Path filename) {
return packageFactory
.newPackageBuilder(
- id, "TESTING", StarlarkSemantics.DEFAULT, /* repositoryMapping= */ ImmutableMap.of())
+ id, "TESTING", StarlarkSemantics.DEFAULT, RepositoryMapping.ALWAYS_FALLBACK)
.setFilename(RootedPath.toRootedPath(root, filename));
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java
index 1f65555..45ddd97 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RepositoryMappingFunctionTest.java
@@ -26,6 +26,7 @@
import com.google.devtools.build.lib.bazel.bzlmod.FakeRegistry;
import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction;
import com.google.devtools.build.lib.bazel.bzlmod.Version.ParseException;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils;
@@ -71,6 +72,17 @@
getSkyframeExecutor().getDifferencerForTesting(), ImmutableList.of(registry.getUrl()));
}
+ public static RepositoryMappingValue withMapping(
+ ImmutableMap<RepositoryName, RepositoryName> repositoryMapping) {
+ return RepositoryMappingValue.withMapping(RepositoryMapping.create(repositoryMapping));
+ }
+
+ public static RepositoryMappingValue withMappingAllowingFallback(
+ ImmutableMap<RepositoryName, RepositoryName> repositoryMapping) {
+ return RepositoryMappingValue.withMapping(
+ RepositoryMapping.createAllowingFallback(repositoryMapping));
+ }
+
@Test
public void testSimpleMapping() throws Exception {
scratch.overwriteFile(
@@ -89,7 +101,7 @@
assertThatEvaluationResult(result)
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(
RepositoryName.create("@a"),
RepositoryName.create("@b"),
@@ -113,7 +125,7 @@
assertThatEvaluationResult(result)
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMapping(
ImmutableMap.of(
RepositoryName.create("@com_foo_bar_b"), RepositoryName.create("@B.1.0"))));
}
@@ -140,7 +152,7 @@
assertThatEvaluationResult(result)
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMapping(
ImmutableMap.of(
RepositoryName.create("@com_foo_bar_b"), RepositoryName.create("@B.1.0"))));
}
@@ -162,8 +174,7 @@
assertThatEvaluationResult(result)
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
- ImmutableMap.of(RepositoryName.create("@A"), RepositoryName.create("@"))));
+ withMapping(ImmutableMap.of(RepositoryName.create("@A"), RepositoryName.create("@"))));
}
@Test
@@ -188,10 +199,12 @@
assertThatEvaluationResult(result)
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMapping(
ImmutableMap.of(
- RepositoryName.create("@B1"), RepositoryName.create("@B.1.0"),
- RepositoryName.create("@B2"), RepositoryName.create("@B.2.0"))));
+ RepositoryName.create("@B1"),
+ RepositoryName.create("@B.1.0"),
+ RepositoryName.create("@B2"),
+ RepositoryName.create("@B.2.0"))));
}
@Test
@@ -222,9 +235,8 @@
assertThatEvaluationResult(result)
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
- ImmutableMap.of(
- RepositoryName.create("@D"), RepositoryName.create("@D.1.0"))));
+ withMapping(
+ ImmutableMap.of(RepositoryName.create("@D"), RepositoryName.create("@D.1.0"))));
}
@Test
@@ -253,7 +265,7 @@
assertThatEvaluationResult(result)
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMapping(
ImmutableMap.of(
RepositoryName.create("@com_foo_bar_c"), RepositoryName.create("@C.1.0"))));
}
@@ -281,7 +293,7 @@
assertThatEvaluationResult(eval(skyKey1))
.hasEntryThat(skyKey1)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(
RepositoryName.create("@a"),
RepositoryName.create("@b"),
@@ -290,7 +302,7 @@
assertThatEvaluationResult(eval(skyKey2))
.hasEntryThat(skyKey2)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(
RepositoryName.create("@x"),
RepositoryName.create("@y"),
@@ -314,7 +326,7 @@
assertThatEvaluationResult(eval(skyKey))
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(
RepositoryName.create("@a"),
RepositoryName.create("@b"),
@@ -360,7 +372,7 @@
assertThatEvaluationResult(eval(skyKey))
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.<RepositoryName, RepositoryName>builder()
.put(RepositoryName.create("@root"), RepositoryName.MAIN)
// mappings to @B get remapped to @B.1.0 because of module B@1.0
@@ -413,7 +425,7 @@
assertThatEvaluationResult(eval(skyKey))
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(
RepositoryName.createFromValidStrippedName(TestConstants.WORKSPACE_NAME),
RepositoryName.MAIN)));
@@ -434,7 +446,7 @@
assertThatEvaluationResult(eval(skyKey))
.hasEntryThat(skyKey)
.isEqualTo(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(RepositoryName.create("@good"), RepositoryName.MAIN)));
}
@@ -442,14 +454,14 @@
public void testEqualsAndHashCode() throws Exception {
new EqualsTester()
.addEqualityGroup(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(RepositoryName.create("@foo"), RepositoryName.create("@bar"))),
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(RepositoryName.create("@foo"), RepositoryName.create("@bar"))))
.addEqualityGroup(
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(RepositoryName.create("@fizz"), RepositoryName.create("@buzz"))),
- RepositoryMappingValue.withMapping(
+ withMappingAllowingFallback(
ImmutableMap.of(RepositoryName.create("@fizz"), RepositoryName.create("@buzz"))))
.testEquals();
}
diff --git a/src/test/java/com/google/devtools/build/lib/starlark/util/BazelEvaluationTestCase.java b/src/test/java/com/google/devtools/build/lib/starlark/util/BazelEvaluationTestCase.java
index 088ef64..7ee391b 100644
--- a/src/test/java/com/google/devtools/build/lib/starlark/util/BazelEvaluationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/starlark/util/BazelEvaluationTestCase.java
@@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.starlark.StarlarkModules;
import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventCollector;
import com.google.devtools.build.lib.events.EventKind;
@@ -127,7 +128,7 @@
BazelStarlarkContext.Phase.LOADING,
TestConstants.TOOLS_REPOSITORY,
/*fragmentNameToClass=*/ null,
- /*repoMapping=*/ ImmutableMap.of(),
+ /*repoMapping=*/ RepositoryMapping.ALWAYS_FALLBACK,
/*convertedLabelsInPackage=*/ new HashMap<>(),
new SymbolGenerator<>(new Object()),
/*analysisRuleLabel=*/ null,