aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2015-10-09 09:57:19 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-10-09 14:41:46 +0000
commitb9321901f2cb457c08037193154bdc7e5b7f9c5e (patch)
tree377faa51832c91d7fee925bb1a1676c64b971807 /src/main/java/com/google/devtools/build
parente8061718bb3ed36e153d23e55f3484091bad1045 (diff)
Make RedirectChaser follow redirects through external repositories correctly and implement a "@//" label syntax that always points to the main repository.
-- MOS_MIGRATED_REVID=105041493
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/cmdline/Label.java16
3 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java b/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java
index 946f2a9427..d6c6ab3b46 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RedirectChaser.java
@@ -92,6 +92,7 @@ public final class RedirectChaser {
return label;
}
+ newLabel = label.resolveRepositoryRelative(newLabel);
label = newLabel;
if (!visitedLabels.add(label)) {
throw new InvalidConfigurationException("The " + name + " points to a filegroup which "
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java
index 5f31945bfb..8ab04b3694 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java
@@ -278,10 +278,12 @@ public class BazelConfigurationCollection implements ConfigurationCollectionFact
// not necessarily the configuration actually applied to the rule. We should correlate the
// two. However, doing so requires faithfully reflecting the configuration transitions that
// might happen as we traverse the dependency chain.
+ // TODO(bazel-team): Why don't we use AbstractAttributeMapper#visitLabels() here?
for (List<Label> labelsForConfiguration :
AggregatingAttributeMapper.of(rule).visitAttribute("srcs", BuildType.LABEL_LIST)) {
for (Label label : labelsForConfiguration) {
- collectTransitiveClosure(packageProvider, reachableLabels, label);
+ collectTransitiveClosure(packageProvider, reachableLabels,
+ from.resolveRepositoryRelative(label));
}
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
index f7126ae769..fc3c3bba7c 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/Label.java
@@ -41,6 +41,7 @@ import java.io.Serializable;
@SkylarkModule(name = "Label", doc = "A BUILD target identifier.")
@Immutable @ThreadSafe
public final class Label implements Comparable<Label>, Serializable, SkylarkPrintableValue {
+ private static final PathFragment EXTERNAL = new PathFragment("external");
/**
* Factory for Labels from absolute string form. e.g.
@@ -352,8 +353,21 @@ public final class Label implements Comparable<Label>, Serializable, SkylarkPrin
* repository would point back to the main repository, which is usually not what is intended.
*/
public Label resolveRepositoryRelative(Label relative) {
+ if (relative.packageIdentifier.getRepository().getName().equals("@")) {
+ try {
+ return new Label(
+ PackageIdentifier.create(
+ PackageIdentifier.DEFAULT_REPOSITORY_NAME,
+ relative.packageIdentifier.getPackageFragment()),
+ relative.getName());
+ } catch (LabelSyntaxException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
if (packageIdentifier.getRepository().isDefault()
- || !relative.packageIdentifier.getRepository().isDefault()) {
+ || !relative.packageIdentifier.getRepository().isDefault()
+ || relative.packageIdentifier.getPackageFragment().equals(EXTERNAL)) {
return relative;
} else {
try {