Remap labels that include a repository name that appear in $(location x).
RELNOTES: None.
PiperOrigin-RevId: 201588988
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 c334cce..92f5616 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.RepositoryName;
import com.google.devtools.build.lib.packages.AbstractRuleErrorConsumer;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
import java.util.ArrayList;
@@ -60,7 +61,6 @@
}
private LocationExpander makeExpander(RuleErrorConsumer ruleErrorConsumer) throws Exception {
-
LocationFunction f1 = new LocationFunctionBuilder("//a", false)
.setExecPaths(false)
.add("//a", "/exec/src/a")
@@ -75,7 +75,8 @@
ruleErrorConsumer,
ImmutableMap.<String, LocationFunction>of(
"location", f1,
- "locations", f2));
+ "locations", f2),
+ ImmutableMap.of());
}
private String expand(String input) throws Exception {
@@ -123,4 +124,24 @@
assertThat(value).isEqualTo("foo $(location a) $(location a");
assertThat(capture.warnsOrErrors).containsExactly("ERROR: unterminated $(location) expression");
}
+
+ @Test
+ public void expansionWithRepositoryMapping() throws Exception {
+ LocationFunction f1 = new LocationFunctionBuilder("//a", false)
+ .setExecPaths(false)
+ .add("@bar//a", "/exec/src/a")
+ .build();
+
+ ImmutableMap<RepositoryName, RepositoryName> repositoryMapping = ImmutableMap.of(
+ RepositoryName.create("@foo"),
+ RepositoryName.create("@bar"));
+
+ LocationExpander locationExpander = new LocationExpander(
+ new Capture(),
+ ImmutableMap.<String, LocationFunction>of("location", f1),
+ repositoryMapping);
+
+ String value = locationExpander.expand("$(location @foo//a)");
+ assertThat(value).isEqualTo("src/a");
+ }
}