diff options
author | Lukacs Berki <lberki@google.com> | 2015-07-07 08:15:23 +0000 |
---|---|---|
committer | Lukacs Berki <lberki@google.com> | 2015-07-07 08:42:42 +0000 |
commit | 130246293c7c36d6538c78e82b59cac343b37c48 (patch) | |
tree | 048242f6b5030594c07509276c235ab5cd8f8ec8 /src/main/java/com/google/devtools/build/lib/syntax | |
parent | b21df3d2a022a24f66c88671ab7694c9b0d9735c (diff) |
Make absolute labels in remote repositories refer to the same repository by default.
If we do otherwise, this makes it impossible to seamlessly move code from the main repository to another one, because if two targets (one depending another) were moved, the dependency edge would still point back to the main repository.
--
MOS_MIGRATED_REVID=97650057
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Label.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Label.java b/src/main/java/com/google/devtools/build/lib/syntax/Label.java index 5a744c0f6a..61621b94b9 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Label.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Label.java @@ -355,6 +355,30 @@ public final class Label implements Comparable<Label>, Serializable { } } + /** + * Resolves the repository of a label in the context of another label. + * + * <p>This is necessary so that dependency edges in remote repositories do not need to explicitly + * mention their repository name. Otherwise, referring to e.g. <code>//a:b</code> in a remote + * repository would point back to the main repository, which is usually not what is intended. + */ + public Label resolveRepositoryRelative(Label relative) { + if (packageIdentifier.getRepository().isDefault() + || !relative.packageIdentifier.getRepository().isDefault()) { + return relative; + } else { + try { + return new Label( + new PackageIdentifier(packageIdentifier.getRepository(), relative.getPackageFragment()), + relative.getName()); + } catch (Label.SyntaxException e) { + // We are creating the new label from an existing one which is guaranteed to be valid, so + // this can't happen + throw new IllegalStateException(e); + } + } + } + @Override public int hashCode() { return name.hashCode() ^ packageIdentifier.hashCode(); |