aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/cmdline
diff options
context:
space:
mode:
authorGravatar dannark <dannark@google.com>2018-06-27 13:35:04 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-27 13:36:25 -0700
commit90e2b4b5e745fe2de9ca82bc8163c198e5be8ca9 (patch)
treef827defac036acf55c4253c01f11126e0c502572 /src/main/java/com/google/devtools/build/lib/cmdline
parent116971c08caa3f9bd94fc91066cd4cd1e432cafe (diff)
Automated refactor of Label.parseAbsolute() to always pass a repository mapping
RELNOTES: None PiperOrigin-RevId: 202360925
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/cmdline')
-rw-r--r--src/main/java/com/google/devtools/build/lib/cmdline/Label.java23
-rw-r--r--src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java3
2 files changed, 19 insertions, 7 deletions
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 3f11858871..873d85ef10 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
@@ -98,13 +98,21 @@ public final class Label
* </pre>
*
* <p>Treats labels in the default repository as being in the main repository instead.
+ *
+ * <p>Labels that begin with a repository name may have the repository name remapped to a
+ * different name if it appears in {@code repositoryMapping}. This happens if the current
+ * repository being evaluated is external to the main repository and the main repository set the
+ * {@code repo_mapping} attribute when declaring this repository.
+ *
+ * @param absName label-like string to be parsed
+ * @param repositoryMapping map of repository names from the local name found in the current
+ * repository to the global name declared in the main repository
*/
- @Deprecated
- // TODO(b/110698008): deprecate this method and only have parseAbsolute() methods that pass
- // a repositoryMapping
- public static Label parseAbsolute(String absName) throws LabelSyntaxException {
+ public static Label parseAbsolute(
+ String absName, ImmutableMap<RepositoryName, RepositoryName> repositoryMapping)
+ throws LabelSyntaxException {
return parseAbsolute(
- absName, /* defaultToMain= */ true, /* repositoryMapping= */ ImmutableMap.of());
+ absName, /* defaultToMain= */ true, repositoryMapping);
}
/**
@@ -123,7 +131,10 @@ public final class Label
* repository being evaluated is external to the main repository and the main repository set the
* {@code repo_mapping} attribute when declaring this repository.
*
+ * @param absName label-like string to be parsed
* @param defaultToMain Treat labels in the default repository as being in the main one instead.
+ * @param repositoryMapping map of repository names from the local name found in the current
+ * repository to the global name declared in the main repository
*/
public static Label parseAbsolute(
String absName,
@@ -242,7 +253,7 @@ public final class Label
throws LabelSyntaxException {
Preconditions.checkArgument(!workspaceRelativePath.isAbsolute());
if (LabelValidator.isAbsolute(label)) {
- return parseAbsolute(label);
+ return parseAbsolute(label, ImmutableMap.of());
}
int index = label.indexOf(':');
if (index < 0) {
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java b/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java
index 1b1f5e7399..c256c5fd3b 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/TargetPattern.java
@@ -19,6 +19,7 @@ import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -900,7 +901,7 @@ public abstract class TargetPattern implements Serializable {
// TargetParsingException.
private static Label label(String label) throws TargetParsingException {
try {
- return Label.parseAbsolute(label);
+ return Label.parseAbsolute(label, ImmutableMap.of());
} catch (LabelSyntaxException e) {
throw new TargetParsingException("invalid target format: '"
+ StringUtilities.sanitizeControlChars(label) + "'; "