Parse the label syntax "@//a:b" so that eventually we can make that the syntax that means "refer to the main repository".
There isn't an overarching plan for what we are going to do with the cmdline package, which seems to be separated from the .syntax one in all sorts of awkward ways.
--
MOS_MIGRATED_REVID=103088960
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
index 2f4f86e..a94134f 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
@@ -29,6 +29,7 @@
import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory;
import com.google.devtools.build.lib.analysis.config.DefaultsPackage;
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.graph.Digraph;
import com.google.devtools.build.lib.graph.Node;
@@ -255,7 +256,7 @@
public Label load(String from) {
try {
return Label.parseAbsolute(from);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalArgumentException(from);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java
index 89ce2e7..9c16308 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/LabelExpander.java
@@ -19,6 +19,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.syntax.Label;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -154,7 +155,7 @@
private static Label resolveLabelText(String labelText, Label labelResolver) {
try {
return labelResolver.getRelative(labelText);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// It's a heuristic, so quietly ignore "errors". Because Label.getRelative never
// returns null, we can use null to indicate an error.
return null;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
index 04c2d5a..26b0f8c 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
@@ -23,6 +23,7 @@
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.OutputFile;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.syntax.Label;
@@ -212,7 +213,7 @@
private Label parseLabel(String labelText, String message, ErrorReporter reporter) {
try {
return ruleContext.getLabel().getRelative(labelText);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
reporter.report(ruleContext, String.format("invalid label%s: %s", message, e.getMessage()));
return null;
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java
index 4dcd080..1f00eca 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleDefinitionEnvironment.java
@@ -23,9 +23,7 @@
public interface RuleDefinitionEnvironment {
/**
* Parses the given string as a label and returns the label, by calling {@link
- * Label#parseAbsolute}. Instead of throwing a {@link
- * com.google.devtools.build.lib.syntax.Label.SyntaxException}, it throws an {@link
- * IllegalArgumentException}, if the parsing fails.
+ * Label#parseAbsolute}. Throws a {@link IllegalArgumentException} if the parsing fails.
*/
Label getLabel(String labelValue);
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
index 485786f..4ea1509 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
@@ -38,6 +38,7 @@
import com.google.devtools.build.lib.analysis.DependencyResolver;
import com.google.devtools.build.lib.analysis.ViewCreationFailedException;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection.Transitions;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.Attribute;
@@ -52,7 +53,6 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.rules.test.TestActionBuilder;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.syntax.SkylarkCallable;
import com.google.devtools.build.lib.syntax.SkylarkModule;
import com.google.devtools.build.lib.syntax.SkylarkModuleNameResolver;
@@ -286,7 +286,7 @@
input = "//" + input;
}
return Label.parseAbsolute(input);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new OptionsParsingException(e.getMessage());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/DefaultsPackage.java b/src/main/java/com/google/devtools/build/lib/analysis/config/DefaultsPackage.java
index e046330..e702ac2 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/DefaultsPackage.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/DefaultsPackage.java
@@ -18,8 +18,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import java.util.Locale;
import java.util.Map;
@@ -161,7 +161,7 @@
if (value.startsWith("//")) {
try {
return Label.parseAbsolute(value);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// We ignore this exception here - it will cause an error message at a later time.
return null;
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/FragmentOptions.java b/src/main/java/com/google/devtools/build/lib/analysis/config/FragmentOptions.java
index c7b8c47..677aa34 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/FragmentOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/FragmentOptions.java
@@ -17,9 +17,9 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.Attribute.SplitTransition;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.common.options.Options;
import com.google.devtools.common.options.OptionsBase;
@@ -115,7 +115,7 @@
if ((value != null) && value.startsWith("//")) {
try {
return Label.parseAbsolute(value);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// We ignore this exception here - it will cause an error message at a later time.
// TODO(bazel-team): We can use a Converter to check the validity of the crosstoolTop
// earlier.
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/PackageProviderForConfigurations.java b/src/main/java/com/google/devtools/build/lib/analysis/config/PackageProviderForConfigurations.java
index 83b4715..d6846ef 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/PackageProviderForConfigurations.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/PackageProviderForConfigurations.java
@@ -15,9 +15,9 @@
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.pkgcache.LoadedPackageProvider;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import java.io.IOException;
@@ -29,7 +29,7 @@
* Adds dependency to fileName if needed. Used only in skyframe, for creating correct dependencies
* for {@link com.google.devtools.build.lib.skyframe.ConfigurationCollectionValue}.
*/
- void addDependency(Package pkg, String fileName) throws SyntaxException, IOException;
+ void addDependency(Package pkg, String fileName) throws LabelSyntaxException, IOException;
/**
* Returns fragment based on fragment type and build options.
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/RunUnderConverter.java b/src/main/java/com/google/devtools/build/lib/analysis/config/RunUnderConverter.java
index 8da1fbb..951c478 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/RunUnderConverter.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/RunUnderConverter.java
@@ -13,10 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.analysis.config;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.shell.ShellUtils;
import com.google.devtools.build.lib.shell.ShellUtils.TokenizationException;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.OptionsParsingException;
@@ -44,7 +44,7 @@
try {
final Label runUnderLabel = Label.parseAbsolute(runUnderCommand);
return new RunUnderLabel(input, runUnderLabel, runUnderList);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new OptionsParsingException("Not a valid label " + e.getMessage());
}
} else {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java
index c8605b8..4bf10f7 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryFunction.java
@@ -17,7 +17,6 @@
import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName;
import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException;
@@ -255,8 +254,7 @@
public static Rule getRule(
RepositoryName repositoryName, @Nullable String ruleClassName, Environment env)
throws RepositoryFunctionException {
- SkyKey packageKey = PackageValue.key(
- PackageIdentifier.createInDefaultRepo(ExternalPackage.NAME));
+ SkyKey packageKey = PackageValue.key(ExternalPackage.PACKAGE_IDENTIFIER);
PackageValue packageValue;
try {
packageValue = (PackageValue) env.getValueOrThrow(packageKey,
@@ -327,7 +325,8 @@
}
public static Path getExternalRepositoryDirectory(BlazeDirectories directories) {
- return directories.getOutputBase().getRelative(ExternalPackage.NAME);
+ return directories.getOutputBase().getRelative(
+ ExternalPackage.PACKAGE_IDENTIFIER.getPackageFragment());
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/LabelSyntaxException.java b/src/main/java/com/google/devtools/build/lib/cmdline/LabelSyntaxException.java
new file mode 100644
index 0000000..3c66959
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/LabelSyntaxException.java
@@ -0,0 +1,24 @@
+// Copyright 2015 Google Inc. 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;
+
+/**
+ * Thrown by the parsing methods to indicate a bad label.
+ */
+public class LabelSyntaxException extends Exception {
+ public LabelSyntaxException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
index 8867c98..9d0ef0e 100644
--- a/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
+++ b/src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
@@ -55,12 +55,12 @@
.build(
new CacheLoader<String, RepositoryName> () {
@Override
- public RepositoryName load(String name) throws TargetParsingException {
+ public RepositoryName load(String name) throws LabelSyntaxException {
String errorMessage = validate(name);
if (errorMessage != null) {
errorMessage = "invalid repository name '"
+ StringUtilities.sanitizeControlChars(name) + "': " + errorMessage;
- throw new TargetParsingException(errorMessage);
+ throw new LabelSyntaxException(errorMessage);
}
return new RepositoryName(StringCanonicalizer.intern(name));
}
@@ -70,11 +70,11 @@
* Makes sure that name is a valid repository name and creates a new RepositoryName using it.
* @throws TargetParsingException if the name is invalid.
*/
- public static RepositoryName create(String name) throws TargetParsingException {
+ public static RepositoryName create(String name) throws LabelSyntaxException {
try {
return repositoryNameCache.get(name);
} catch (ExecutionException e) {
- Throwables.propagateIfInstanceOf(e.getCause(), TargetParsingException.class);
+ Throwables.propagateIfInstanceOf(e.getCause(), LabelSyntaxException.class);
throw new IllegalStateException("Failed to create RepositoryName from " + name, e);
}
}
@@ -97,11 +97,6 @@
return "workspace name must start with '@'";
}
- // "@" isn't a valid workspace name.
- if (name.length() == 1) {
- return "empty workspace name";
- }
-
// Check for any character outside of [/0-9A-Za-z_.-]. Try to evaluate the
// conditional quickly (by looking in decreasing order of character class
// likelihood).
@@ -174,11 +169,13 @@
public static final String DEFAULT_REPOSITORY = "";
public static final RepositoryName DEFAULT_REPOSITORY_NAME;
+ public static final RepositoryName MAIN_REPOSITORY_NAME;
static {
try {
DEFAULT_REPOSITORY_NAME = RepositoryName.create(DEFAULT_REPOSITORY);
- } catch (TargetParsingException e) {
+ MAIN_REPOSITORY_NAME = RepositoryName.create("@");
+ } catch (LabelSyntaxException e) {
throw new IllegalStateException(e);
}
}
@@ -205,7 +202,7 @@
throws IOException, ClassNotFoundException {
try {
packageId = new PackageIdentifier((String) in.readObject(), (PathFragment) in.readObject());
- } catch (TargetParsingException e) {
+ } catch (LabelSyntaxException e) {
throw new IOException("Error serializing package identifier: " + e.getMessage());
}
}
@@ -228,7 +225,7 @@
public static PackageIdentifier createInDefaultRepo(PathFragment name) {
try {
return new PackageIdentifier(DEFAULT_REPOSITORY, name);
- } catch (TargetParsingException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalArgumentException("could not create package identifier for " + name
+ ": " + e.getMessage());
}
@@ -243,7 +240,7 @@
/** The name of the package. Canonical (i.e. x.equals(y) <=> x==y). */
private final PathFragment pkgName;
- public PackageIdentifier(String repository, PathFragment pkgName) throws TargetParsingException {
+ public PackageIdentifier(String repository, PathFragment pkgName) throws LabelSyntaxException {
this(RepositoryName.create(repository), pkgName);
}
@@ -254,13 +251,15 @@
this.pkgName = Canonicalizer.fragments().intern(pkgName.normalize());
}
- public static PackageIdentifier parse(String input) throws TargetParsingException {
+ public static PackageIdentifier parse(String input) throws LabelSyntaxException {
String repo;
String packageName;
int packageStartPos = input.indexOf("//");
- if (packageStartPos > 0) {
+ if (input.startsWith("@") && packageStartPos > 0) {
repo = input.substring(0, packageStartPos);
packageName = input.substring(packageStartPos + 2);
+ } else if (input.startsWith("@")) {
+ throw new LabelSyntaxException("invalid package name '" + input + "'");
} else if (packageStartPos == 0) {
repo = PackageIdentifier.DEFAULT_REPOSITORY;
packageName = input.substring(2);
@@ -271,12 +270,12 @@
String error = RepositoryName.validate(repo);
if (error != null) {
- throw new TargetParsingException(error);
+ throw new LabelSyntaxException(error);
}
error = LabelValidator.validatePackageName(packageName);
if (error != null) {
- throw new TargetParsingException(error);
+ throw new LabelSyntaxException(error);
}
return new PackageIdentifier(repo, new PathFragment(packageName));
diff --git a/src/main/java/com/google/devtools/build/lib/packages/ConstantRuleVisibility.java b/src/main/java/com/google/devtools/build/lib/packages/ConstantRuleVisibility.java
index bb64015..8d50693 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/ConstantRuleVisibility.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/ConstantRuleVisibility.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.packages;
import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.syntax.Label;
@@ -43,7 +44,7 @@
PUBLIC_LABEL = Label.parseAbsolute("//visibility:public");
LEGACY_PUBLIC_LABEL = Label.parseAbsolute("//visibility:legacy_public");
PRIVATE_LABEL = Label.parseAbsolute("//visibility:private");
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalStateException();
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/ExternalPackage.java b/src/main/java/com/google/devtools/build/lib/packages/ExternalPackage.java
index cfb8143..fdb63e2 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/ExternalPackage.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/ExternalPackage.java
@@ -18,16 +18,15 @@
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName;
-import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.events.StoredEventHandler;
import com.google.devtools.build.lib.packages.RuleFactory.InvalidRuleException;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.vfs.Path;
import java.util.Map;
@@ -36,9 +35,15 @@
* This creates the //external package, where targets not homed in this repository can be bound.
*/
public class ExternalPackage extends Package {
- public static final String NAME = "external";
- public static final PackageIdentifier PACKAGE_IDENTIFIER =
- PackageIdentifier.createInDefaultRepo(NAME);
+ public static final PackageIdentifier PACKAGE_IDENTIFIER;
+
+ static {
+ try {
+ PACKAGE_IDENTIFIER = PackageIdentifier.parse("//external");
+ } catch (LabelSyntaxException e) {
+ throw new IllegalStateException();
+ }
+ }
private Map<RepositoryName, Rule> repositoryMap;
@@ -133,15 +138,16 @@
*/
public Builder createAndAddRepositoryRule(RuleClass ruleClass, RuleClass bindRuleClass,
Map<String, Object> kwargs, FuncallExpression ast, Environment env)
- throws InvalidRuleException, NameConflictException, SyntaxException, InterruptedException {
+ throws InvalidRuleException, NameConflictException, LabelSyntaxException,
+ InterruptedException {
StoredEventHandler eventHandler = new StoredEventHandler();
Rule tempRule = RuleFactory.createRule(
this, ruleClass, kwargs, eventHandler, ast, ast.getLocation(), env);
addEvents(eventHandler.getEvents());
try {
repositoryMap.put(RepositoryName.create("@" + tempRule.getName()), tempRule);
- } catch (TargetParsingException e) {
- throw new SyntaxException(e.getMessage());
+ } catch (LabelSyntaxException e) {
+ throw new LabelSyntaxException(e.getMessage());
}
for (Map.Entry<String, Label> entry :
ruleClass.getExternalBindingsFunction().apply(tempRule).entrySet()) {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/License.java b/src/main/java/com/google/devtools/build/lib/packages/License.java
index f4e554e..98ed31d 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/License.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/License.java
@@ -20,13 +20,13 @@
import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import java.util.Collection;
import java.util.Collections;
@@ -209,7 +209,7 @@
try {
Label label = Label.parseAbsolute(str.substring("exception=".length()));
exceptions.add(label);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new LicenseParsingException(e.getMessage());
}
} else {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java
index 256aab0..0fbc726 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Package.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -24,6 +24,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.collect.CollectionUtils;
import com.google.devtools.build.lib.collect.ImmutableSortedKeyMap;
@@ -36,7 +37,6 @@
import com.google.devtools.build.lib.packages.PackageFactory.Globber;
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.Canonicalizer;
import com.google.devtools.build.lib.vfs.Path;
@@ -586,7 +586,7 @@
throw new NoSuchTargetException(createLabel(targetName), "target '" + targetName
+ "' not declared in package '" + name + "'" + suffix + " defined by "
+ this.filename);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalArgumentException(targetName);
}
}
@@ -594,9 +594,9 @@
/**
* Creates a label for a target inside this package.
*
- * @throws SyntaxException if the {@code targetName} is invalid
+ * @throws LabelSyntaxException if the {@code targetName} is invalid
*/
- public Label createLabel(String targetName) throws SyntaxException {
+ public Label createLabel(String targetName) throws LabelSyntaxException {
return Label.create(packageIdentifier, targetName);
}
@@ -841,7 +841,7 @@
try {
buildFileLabel = createLabel(filename.getBaseName());
addInputFile(buildFileLabel, Location.fromFile(filename));
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// This can't actually happen.
throw new AssertionError("Package BUILD file has an illegal name: " + filename);
}
@@ -1105,7 +1105,7 @@
if (existing == null) {
try {
return addInputFile(createLabel(targetName), location);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalArgumentException("FileTarget in package " + pkg.getName()
+ " has illegal name: " + targetName);
}
@@ -1142,9 +1142,9 @@
/**
* Creates a label for a target inside this package.
*
- * @throws SyntaxException if the {@code targetName} is invalid
+ * @throws LabelSyntaxException if the {@code targetName} is invalid
*/
- Label createLabel(String targetName) throws SyntaxException {
+ Label createLabel(String targetName) throws LabelSyntaxException {
return Label.create(pkg.getPackageIdentifier(), targetName);
}
@@ -1153,7 +1153,7 @@
*/
void addPackageGroup(String name, Collection<String> packages, Collection<Label> includes,
EventHandler eventHandler, Location location)
- throws NameConflictException, Label.SyntaxException {
+ throws NameConflictException, LabelSyntaxException {
PackageGroup group =
new PackageGroup(createLabel(name), pkg, packages, includes, eventHandler, location);
Target existing = targets.get(group.getName());
@@ -1190,7 +1190,7 @@
*/
void addEnvironmentGroup(String name, List<Label> environments, List<Label> defaults,
EventHandler eventHandler, Location location)
- throws NameConflictException, SyntaxException {
+ throws NameConflictException, LabelSyntaxException {
if (!checkForDuplicateLabels(environments, name, "environments", location, eventHandler)
|| !checkForDuplicateLabels(defaults, name, "defaults", location, eventHandler)) {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
index 2f0715c..9dbb7ef 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
@@ -23,8 +23,8 @@
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.events.NullEventHandler;
@@ -40,7 +40,6 @@
import com.google.devtools.build.lib.syntax.GlobCriteria;
import com.google.devtools.build.lib.syntax.GlobList;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -92,7 +91,7 @@
public Label load(String labelString) throws PackageDeserializationException {
try {
return Label.parseAbsolute(labelString);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new PackageDeserializationException("Invalid label: " + e.getMessage(), e);
}
}
@@ -160,7 +159,7 @@
deserializeLabels(packageGroupPb.getIncludedPackageGroupList()),
NullEventHandler.INSTANCE, // TODO(bazel-team): Handle errors properly
EmptyLocation.INSTANCE);
- } catch (Label.SyntaxException | Package.NameConflictException e) {
+ } catch (LabelSyntaxException | Package.NameConflictException e) {
throw new PackageDeserializationException(e);
}
}
@@ -183,7 +182,7 @@
context.packageBuilder.addRule(rule);
Preconditions.checkState(!rule.containsErrors());
- } catch (NameConflictException | SyntaxException e) {
+ } catch (NameConflictException | LabelSyntaxException e) {
throw new PackageDeserializationException(e);
}
}
@@ -452,7 +451,7 @@
builder = new Package.Builder(
new PackageIdentifier(packagePb.getRepository(), new PathFragment(packagePb.getName())),
null);
- } catch (TargetParsingException e) {
+ } catch (LabelSyntaxException e) {
throw new PackageDeserializationException(e);
}
StoredEventHandler eventHandler = new StoredEventHandler();
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
index 4fd5428..1a7c376 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java
@@ -21,6 +21,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.LabelValidator;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.events.Event;
@@ -626,7 +627,7 @@
context.pkgBuilder.addEnvironmentGroup(
name, environments, defaults, context.eventHandler, loc);
return Runtime.NONE;
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new EvalException(loc,
"environment group has invalid name: " + name + ": " + e.getMessage());
} catch (Package.NameConflictException e) {
@@ -819,7 +820,7 @@
context.pkgBuilder.addPackageGroup(name, packages, includes, context.eventHandler,
ast.getLocation());
return Runtime.NONE;
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new EvalException(ast.getLocation(),
"package group has invalid name: " + name + ": " + e.getMessage());
} catch (Package.NameConflictException e) {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Rule.java b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
index da1c804..4802169 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Rule.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
@@ -27,6 +27,7 @@
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
@@ -36,7 +37,6 @@
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.GlobList;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.util.BinaryPredicate;
import java.util.Collection;
@@ -484,7 +484,7 @@
* will retain the relative order in which they were declared.
*/
void populateOutputFiles(EventHandler eventHandler, Package.Builder pkgBuilder)
- throws SyntaxException, InterruptedException {
+ throws LabelSyntaxException, InterruptedException {
Preconditions.checkState(outputFiles == null);
// Order is important here: implicit before explicit
outputFiles = Lists.newArrayList();
@@ -496,7 +496,7 @@
}
// Explicit output files are user-specified attributes of type OUTPUT.
- private void populateExplicitOutputFiles(EventHandler eventHandler) throws SyntaxException {
+ private void populateExplicitOutputFiles(EventHandler eventHandler) throws LabelSyntaxException {
NonconfigurableAttributeMapper nonConfigurableAttributes =
NonconfigurableAttributeMapper.of(this);
for (Attribute attribute : ruleClass.getAttributes()) {
@@ -525,7 +525,7 @@
for (String out : ruleClass.getImplicitOutputsFunction().getImplicitOutputs(attributeMap)) {
try {
addOutputFile(pkgBuilder.createLabel(out), eventHandler);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
reportError("illegal output file name '" + out + "' in rule "
+ getLabel(), eventHandler);
}
@@ -536,7 +536,7 @@
}
private void addLabelOutput(Attribute attribute, Label label, EventHandler eventHandler)
- throws SyntaxException {
+ throws LabelSyntaxException {
if (!label.getPackageIdentifier().equals(pkg.getPackageIdentifier())) {
throw new IllegalStateException("Label for attribute " + attribute
+ " should refer to '" + pkg.getName()
@@ -544,7 +544,7 @@
+ "' (label '" + label.getName() + "')");
}
if (label.getName().equals(".")) {
- throw new SyntaxException("output file name can't be equal '.'");
+ throw new LabelSyntaxException("output file name can't be equal '.'");
}
OutputFile outputFile = addOutputFile(label, eventHandler);
outputFileMap.put(attribute.getName(), outputFile);
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index 1e7dd2a..34ff1af 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -29,6 +29,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Ordering;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
@@ -40,7 +41,6 @@
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.GlobList;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.util.StringUtil;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -1315,7 +1315,7 @@
*/
Rule createRuleWithLabel(Package.Builder pkgBuilder, Label ruleLabel,
Map<String, Object> attributeValues, EventHandler eventHandler, FuncallExpression ast,
- Location location) throws SyntaxException, InterruptedException {
+ Location location) throws LabelSyntaxException, InterruptedException {
Rule rule = pkgBuilder.newRuleWithLabel(ruleLabel, this, null, location);
createRuleCommon(rule, pkgBuilder, attributeValues, eventHandler, ast);
return rule;
@@ -1323,7 +1323,7 @@
private void createRuleCommon(Rule rule, Package.Builder pkgBuilder,
Map<String, Object> attributeValues, EventHandler eventHandler, FuncallExpression ast)
- throws SyntaxException, InterruptedException {
+ throws LabelSyntaxException, InterruptedException {
populateRuleAttributeValues(
rule, pkgBuilder, attributeValues, eventHandler, ast);
rule.populateOutputFiles(eventHandler, pkgBuilder);
@@ -1365,7 +1365,7 @@
Rule createRuleWithParsedAttributeValues(Label label,
Package.Builder pkgBuilder, Location ruleLocation,
Map<String, ParsedAttributeValue> attributeValues, EventHandler eventHandler)
- throws SyntaxException, InterruptedException {
+ throws LabelSyntaxException, InterruptedException {
Rule rule = pkgBuilder.newRuleWithLabel(label, this, null, ruleLocation);
rule.checkValidityPredicate(eventHandler);
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
index f647c07..1eb2834 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleFactory.java
@@ -16,6 +16,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.Package.NameConflictException;
@@ -24,7 +25,6 @@
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.syntax.UserDefinedFunction;
import com.google.devtools.build.lib.util.Pair;
@@ -98,7 +98,7 @@
// Test that this would form a valid label name -- in particular, this
// catches cases where Makefile variables $(foo) appear in "name".
label = pkgBuilder.createLabel(name);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new InvalidRuleException("illegal rule name: " + name + ": " + e.getMessage());
}
boolean inWorkspaceFile =
@@ -115,7 +115,7 @@
try {
return ruleClass.createRuleWithLabel(
pkgBuilder, label, generator.attributes, eventHandler, ast, generator.location);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new RuleFactory.InvalidRuleException(ruleClass + " " + e.getMessage());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Type.java b/src/main/java/com/google/devtools/build/lib/packages/Type.java
index b88c7a1..fa2ce67 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Type.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Type.java
@@ -23,6 +23,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.License.DistributionType;
import com.google.devtools.build.lib.packages.License.LicenseParsingException;
import com.google.devtools.build.lib.syntax.EvalException;
@@ -670,7 +671,7 @@
try {
return currentRule.getRelative(
STRING.convert(x, what, currentRule));
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new ConversionException("invalid label '" + x + "' in "
+ what + ": " + e.getMessage());
}
@@ -796,7 +797,7 @@
throw new ConversionException("label '" + value + "' is not in the current package");
}
return result;
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new ConversionException(
"illegal output file name '" + value + "' in rule " + currentRule + ": "
+ e.getMessage());
@@ -1043,7 +1044,7 @@
try {
defaultConditionLabel = Label.parseAbsolute(DEFAULT_CONDITION_KEY);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalStateException(DEFAULT_CONDITION_KEY + " is not a valid label");
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
index 74def59..a19b36b 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java
@@ -16,6 +16,7 @@
import static com.google.devtools.build.lib.syntax.Runtime.NONE;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.LabelValidator;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.Location;
@@ -119,11 +120,11 @@
builder.addBindRule(ruleClass, nameLabel,
actual == null ? null : Label.parseAbsolute(actual), loc);
} catch (RuleFactory.InvalidRuleException | Package.NameConflictException |
- Label.SyntaxException e) {
+ LabelSyntaxException e) {
throw new EvalException(loc, e.getMessage());
}
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new EvalException(loc, e.getMessage());
}
return NONE;
@@ -146,7 +147,7 @@
RuleClass bindRuleClass = ruleFactory.getRuleClass("bind");
builder.createAndAddRepositoryRule(ruleClass, bindRuleClass, kwargs, ast, env);
} catch (RuleFactory.InvalidRuleException | Package.NameConflictException |
- Label.SyntaxException e) {
+ LabelSyntaxException e) {
throw new EvalException(ast.getLocation(), e.getMessage());
}
return NONE;
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternResolverUtil.java b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternResolverUtil.java
index a291150..c1794c0 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternResolverUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/TargetPatternResolverUtil.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.pkgcache;
import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.LabelValidator;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
@@ -32,12 +33,12 @@
// Utility class.
}
- // Parse 'label' as a Label, mapping Label.SyntaxException into
+ // Parse 'label' as a Label, mapping LabelSyntaxException into
// TargetParsingException.
public static Label label(String label) throws TargetParsingException {
try {
return Label.parseAbsolute(label);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw invalidTarget(label, e.getMessage());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
index da7c3d9..24cc3f2 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
@@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.events.EventHandler;
@@ -339,7 +340,7 @@
try {
addIfUniqueLabel(getSubincludeTarget(
subinclude.getLocalTargetLabel("BUILD"), pkg), seenLabels, dependentFiles);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new AssertionError("BUILD should always parse as a target name", e);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
index 1945c45..6171081 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
@@ -26,6 +26,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.cmdline.TargetPattern;
@@ -327,7 +328,7 @@
try {
addIfUniqueLabel(getSubincludeTarget(
subinclude.getLocalTargetLabel("BUILD"), pkg), seenLabels, dependentFiles);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new AssertionError("BUILD should always parse as a target name", e);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/PreciseAspectResolver.java b/src/main/java/com/google/devtools/build/lib/query2/output/PreciseAspectResolver.java
index dee20c4..a9c9936 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/output/PreciseAspectResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/output/PreciseAspectResolver.java
@@ -16,6 +16,7 @@
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.packages.AspectDefinition;
@@ -119,7 +120,7 @@
// If the package is not found, just add its BUILD file, which is already done above.
// Hopefully this error is not raised when there is a syntax error in a subincluded file
// or something.
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalStateException(e);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
index 2595cf9..066ac52 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
@@ -38,6 +38,7 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.RunUnder;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
@@ -115,7 +116,7 @@
public Label load(String from) throws Exception {
try {
return Label.parseAbsolute(from);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new Exception(from);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index c999e7f..1b9f786 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -38,13 +38,13 @@
import com.google.devtools.build.lib.analysis.config.CompilationMode;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.analysis.config.PerLabelOptions;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.rules.cpp.CppConfigurationLoader.CppConfigurationParameters;
import com.google.devtools.build.lib.rules.cpp.FdoSupport.FdoException;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.syntax.SkylarkCallable;
import com.google.devtools.build.lib.syntax.SkylarkModule;
import com.google.devtools.build.lib.util.IncludeScanningUtil;
@@ -382,7 +382,7 @@
this.dynamicRuntimeLibsLabel =
crosstoolTop.getRelative(toolchain.hasDynamicRuntimesFilegroup() ?
toolchain.getDynamicRuntimesFilegroup() : "dynamic-runtime-libs-" + targetCpu);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// All of the above label.getRelative() calls are valid labels, and the crosstool_top
// was already checked earlier in the process.
throw new AssertionError(e);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java
index 2ad010a..96b1add 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfigurationLoader.java
@@ -25,6 +25,7 @@
import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory;
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.InputFile;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
@@ -34,7 +35,6 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig;
@@ -153,7 +153,7 @@
throw new InvalidConfigurationException(
"The --fdo_optimize parameter you specified resolves to a file that does not exist");
}
- } catch (NoSuchPackageException | NoSuchTargetException | SyntaxException e) {
+ } catch (NoSuchPackageException | NoSuchTargetException | LabelSyntaxException e) {
throw new InvalidConfigurationException(e);
}
} else {
@@ -189,7 +189,7 @@
} else {
try {
ccToolchainLabel = crosstoolTopLabel.getRelative("cc-compiler-" + toolchain.getTargetCpu());
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new InvalidConfigurationException(String.format(
"'%s' is not a valid CPU. It should only consist of characters valid in labels",
toolchain.getTargetCpu()));
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index 0a628f3..1e8b247 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -30,6 +30,7 @@
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
import com.google.devtools.build.lib.packages.Type;
@@ -38,7 +39,6 @@
import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
import com.google.devtools.build.lib.shell.ShellUtils;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.util.IncludeScanningUtil;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -198,7 +198,7 @@
return true;
}
}
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// Quietly ignore and fall through.
}
linkopts.add(labelName);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
index 7915bb2..ebb4e77 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
@@ -24,11 +24,11 @@
import com.google.devtools.build.lib.analysis.config.CompilationMode;
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
import com.google.devtools.build.lib.analysis.config.PerLabelOptions;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration.HeadersCheckingMode;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration.LibcTop;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration.StripMode;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LipoMode;
@@ -134,7 +134,7 @@
try {
Label label = Label.parseAbsolute(input).getRelative(LIBC_RELATIVE_LABEL);
return new LibcTop(label);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new OptionsParsingException(e.getMessage());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java
index 15e91e2..22ae3ec 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoader.java
@@ -25,6 +25,7 @@
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.NoSuchThingException;
import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
import com.google.devtools.build.lib.packages.Package;
@@ -32,7 +33,6 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
@@ -210,7 +210,7 @@
return null;
}
path = env.getPath(containingPackage, CROSSTOOL_CONFIGURATION_FILENAME);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new InvalidConfigurationException(e);
} catch (NoSuchThingException e) {
// Handled later
diff --git a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java
index 737ab6d..dfe8715 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/genquery/GenQuery.java
@@ -183,7 +183,7 @@
for (Label scopePart : scopeLabels) {
SkyFunction.Environment env = context.getAnalysisEnvironment().getSkyframeEnv();
PackageValue packageNode =
- (PackageValue) env.getValue(PackageValue.key(scopePart.getPackageFragment()));
+ (PackageValue) env.getValue(PackageValue.key(scopePart.getPackageIdentifier()));
Preconditions.checkNotNull(
packageNode,
"Packages in transitive closure of scope '%s'"
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java
index 2151bff..ffca843 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java
@@ -19,11 +19,11 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsMode;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.syntax.SkylarkCallable;
import com.google.devtools.build.lib.syntax.SkylarkModule;
import com.google.devtools.common.options.TriState;
@@ -97,7 +97,7 @@
try {
Label label = Label.parseAbsolute(s);
translationsBuilder.add(label);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new InvalidConfigurationException("Invalid translations target '" + s + "', make " +
"sure it uses correct absolute path syntax.", e);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
index 4b564a5..6b7a353 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java
@@ -22,9 +22,9 @@
import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsMode;
import com.google.devtools.build.lib.analysis.config.DefaultsPackage;
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.rules.java.JavaConfiguration.JavaClasspathMode;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.common.options.Converters.StringSetConverter;
import com.google.devtools.common.options.EnumConverter;
import com.google.devtools.common.options.Option;
@@ -362,7 +362,7 @@
try {
Label label = Label.parseAbsolute(s);
result.add(label);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// We ignore this exception here - it will cause an error message at a later time.
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
index c6fff96..ecc013a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
@@ -23,6 +23,7 @@
import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory;
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
import com.google.devtools.build.lib.packages.RawAttributeMapper;
@@ -30,7 +31,6 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.List;
@@ -156,7 +156,7 @@
throw new InvalidConfigurationException(e.getMessage(), e);
} catch (NoSuchTargetException e) {
throw new InvalidConfigurationException("No such target: " + e.getMessage(), e);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new InvalidConfigurationException(e.getMessage(), e);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
index 130be53..1570d7f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
@@ -32,6 +32,7 @@
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.AspectDefinition;
@@ -44,7 +45,6 @@
import com.google.devtools.build.lib.rules.java.Jvm;
import com.google.devtools.build.lib.rules.objc.J2ObjcSource.SourceType;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -83,7 +83,7 @@
private static Label parseLabel(String from) {
try {
return Label.parseAbsolute(from);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalArgumentException(from);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfigurationFragmentFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfigurationFragmentFunction.java
index d19da4b..b48c027 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfigurationFragmentFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfigurationFragmentFunction.java
@@ -22,13 +22,13 @@
import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.analysis.config.PackageProviderForConfigurations;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.skyframe.ConfigurationFragmentValue.ConfigurationFragmentKey;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
@@ -112,7 +112,7 @@
Path result = pkg.getPackageDirectory().getRelative(fileName);
try {
loadedPackageProvider.addDependency(pkg, fileName);
- } catch (IOException | SyntaxException e) {
+ } catch (IOException | LabelSyntaxException e) {
return null;
}
return result;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
index cf0bf4e..95fef27 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
@@ -378,11 +378,11 @@
}
}
- if (packageName.equals(EXTERNAL_PACKAGE_NAME)) {
+ if (packageId.equals(ExternalPackage.PACKAGE_IDENTIFIER)) {
return getExternalPackage(env, packageLookupValue.getRoot());
}
PackageValue externalPackage = (PackageValue) env.getValue(
- PackageValue.key(PackageIdentifier.createInDefaultRepo(EXTERNAL_PACKAGE_NAME)));
+ PackageValue.key(ExternalPackage.PACKAGE_IDENTIFIER));
if (externalPackage == null) {
return null;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
index ad815e1..610971d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
@@ -51,9 +51,10 @@
public SkyValue compute(SkyKey skyKey, Environment env) throws PackageLookupFunctionException {
PathPackageLocator pkgLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
PackageIdentifier packageKey = (PackageIdentifier) skyKey.argument();
- if (!packageKey.getRepository().isDefault()) {
+ if (!packageKey.getRepository().equals(PackageIdentifier.MAIN_REPOSITORY_NAME)
+ && !packageKey.getRepository().isDefault()) {
return computeExternalPackageLookupValue(skyKey, env, packageKey);
- } else if (packageKey.getPackageFragment().equals(new PathFragment(ExternalPackage.NAME))) {
+ } else if (packageKey.equals(ExternalPackage.PACKAGE_IDENTIFIER)) {
return computeWorkspaceLookupValue(env, packageKey);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java
index f90df2d..ade85a7 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java
@@ -18,7 +18,6 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.packages.Package;
-import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -45,11 +44,6 @@
return "<PackageValue name=" + pkg.getName() + ">";
}
- @ThreadSafe
- public static SkyKey key(PathFragment pkgName) {
- return key(PackageIdentifier.createInDefaultRepo(pkgName));
- }
-
public static SkyKey key(PackageIdentifier pkgIdentifier) {
return new SkyKey(SkyFunctions.PACKAGE, pkgIdentifier);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePackageProviderBackedTargetPatternResolver.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePackageProviderBackedTargetPatternResolver.java
index 891a39c..051215d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePackageProviderBackedTargetPatternResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursivePackageProviderBackedTargetPatternResolver.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skyframe;
import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
@@ -87,7 +88,7 @@
return null;
}
return recursivePackageProvider.getTarget(eventHandler, label);
- } catch (Label.SyntaxException | NoSuchThingException e) {
+ } catch (LabelSyntaxException | NoSuchThingException e) {
return null;
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframePackageLoaderWithValueEnvironment.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframePackageLoaderWithValueEnvironment.java
index 64ee756..80ccb13 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframePackageLoaderWithValueEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframePackageLoaderWithValueEnvironment.java
@@ -18,6 +18,7 @@
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.analysis.config.PackageProviderForConfigurations;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
@@ -25,7 +26,6 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor.SkyframePackageLoader;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.MemoizingEvaluator;
import com.google.devtools.build.skyframe.SkyFunction;
@@ -81,7 +81,7 @@
}
@Override
- public void addDependency(Package pkg, String fileName) throws SyntaxException, IOException {
+ public void addDependency(Package pkg, String fileName) throws LabelSyntaxException, IOException {
RootedPath fileRootedPath = RootedPath.toRootedPath(pkg.getSourceRoot(),
pkg.getNameFragment().getRelative(fileName));
FileValue result = (FileValue) env.getValue(FileValue.key(fileRootedPath));
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java
index bcf56c4..d5c6b39 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunction.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skyframe;
import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName;
import com.google.devtools.build.lib.events.Event;
@@ -27,7 +28,6 @@
import com.google.devtools.build.lib.syntax.BuildFileAST;
import com.google.devtools.build.lib.syntax.Environment.Extension;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.syntax.Mutability;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyFunction;
@@ -160,7 +160,7 @@
try {
// This code relies on PackageIdentifier.RepositoryName.toString()
return Label.parseAbsolute(repo + "//" + pkgName.getPathString() + ":" + fileInPkg);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalStateException(e);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java
index 1f665e0..c91d279 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TargetPatternValue.java
@@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
import com.google.devtools.build.lib.cmdline.ResolvedTargets.Builder;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
@@ -26,7 +27,6 @@
import com.google.devtools.build.lib.pkgcache.FilteringPolicies;
import com.google.devtools.build.lib.pkgcache.FilteringPolicy;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -69,7 +69,7 @@
private Label labelFromString(String labelString) {
try {
return Label.parseAbsolute(labelString);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalStateException(e);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
index cdd75d3..bbaf3b0 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java
@@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.hash.HashCode;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
@@ -97,7 +98,7 @@
try {
Label label = Label.parseAbsolute(((StringLiteral) arg).getValue());
result.add(label);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// Ignore. This will be reported when the BUILD file is actually evaluated.
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/CommaSeparatedPackageNameListConverter.java b/src/main/java/com/google/devtools/build/lib/syntax/CommaSeparatedPackageNameListConverter.java
index 5d5c598..78faf36 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/CommaSeparatedPackageNameListConverter.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/CommaSeparatedPackageNameListConverter.java
@@ -16,8 +16,8 @@
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.OptionsParsingException;
@@ -40,7 +40,7 @@
for (String s : SPACE_SPLITTER.split(input)) {
try {
list.add(PackageIdentifier.parse(s));
- } catch (TargetParsingException e) {
+ } catch (LabelSyntaxException e) {
throw new OptionsParsingException(e.getMessage());
}
}
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 c7994d9..6c712c3 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
@@ -15,10 +15,10 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ComparisonChain;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.LabelValidator;
import com.google.devtools.build.lib.cmdline.LabelValidator.BadLabelException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.StringCanonicalizer;
@@ -42,15 +42,6 @@
public final class Label implements Comparable<Label>, Serializable {
/**
- * Thrown by the parsing methods to indicate a bad label.
- */
- public static class SyntaxException extends Exception {
- public SyntaxException(String message) {
- super(message);
- }
- }
-
- /**
* Factory for Labels from absolute string form. e.g.
* <pre>
* //foo/bar
@@ -59,7 +50,7 @@
* {@literal @}foo//bar:baz
* </pre>
*/
- public static Label parseAbsolute(String absName) throws SyntaxException {
+ public static Label parseAbsolute(String absName) throws LabelSyntaxException {
String repo = PackageIdentifier.DEFAULT_REPOSITORY;
int packageStartPos = absName.indexOf("//");
if (packageStartPos > 0) {
@@ -71,8 +62,8 @@
validate(labelParts.getPackageName(), labelParts.getTargetName());
return new Label(new PackageIdentifier(repo, new PathFragment(labelParts.getPackageName())),
labelParts.getTargetName());
- } catch (BadLabelException | TargetParsingException e) {
- throw new SyntaxException(e.getMessage());
+ } catch (BadLabelException e) {
+ throw new LabelSyntaxException(e.getMessage());
}
}
@@ -86,7 +77,7 @@
public static Label parseAbsoluteUnchecked(String absName) {
try {
return parseAbsolute(absName);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
@@ -99,9 +90,9 @@
* {@link LabelValidator#validatePackageName}.
* @param targetName The name of the target within the package. Must be
* valid according to {@link LabelValidator#validateTargetName}.
- * @throws SyntaxException if either of the arguments was invalid.
+ * @throws LabelSyntaxException if either of the arguments was invalid.
*/
- public static Label create(String packageName, String targetName) throws SyntaxException {
+ public static Label create(String packageName, String targetName) throws LabelSyntaxException {
return new Label(packageName, targetName);
}
@@ -110,7 +101,7 @@
* to be created.
*/
public static Label create(PackageIdentifier packageId, String targetName)
- throws SyntaxException {
+ throws LabelSyntaxException {
return new Label(packageId, targetName);
}
@@ -131,10 +122,10 @@
* possible, because it is sometimes necessary to resolve a relative label before the package path
* is setup; in particular, before the tools/defaults package is created.
*
- * @throws SyntaxException if the resulting label is not valid
+ * @throws LabelSyntaxException if the resulting label is not valid
*/
public static Label parseCommandLineLabel(String label, PathFragment workspaceRelativePath)
- throws SyntaxException {
+ throws LabelSyntaxException {
Preconditions.checkArgument(!workspaceRelativePath.isAbsolute());
if (LabelValidator.isAbsolute(label)) {
return parseAbsolute(label);
@@ -154,11 +145,11 @@
* Validates the given target name and returns a canonical String instance if it is valid.
* Otherwise it throws a SyntaxException.
*/
- private static String canonicalizeTargetName(String name) throws SyntaxException {
+ private static String canonicalizeTargetName(String name) throws LabelSyntaxException {
String error = LabelValidator.validateTargetName(name);
if (error != null) {
error = "invalid target name '" + StringUtilities.sanitizeControlChars(name) + "': " + error;
- throw new SyntaxException(error);
+ throw new LabelSyntaxException(error);
}
// TODO(bazel-team): This should be an error, but we can't make it one for legacy reasons.
@@ -173,19 +164,22 @@
* Validates the given package name and returns a canonical PathFragment instance if it is valid.
* Otherwise it throws a SyntaxException.
*/
- private static PathFragment validate(String packageName, String name) throws SyntaxException {
- String error = LabelValidator.validatePackageName(packageName);
- if (error != null) {
- error = "invalid package name '" + packageName + "': " + error;
+ private static PackageIdentifier validate(String packageIdentifier, String name)
+ throws LabelSyntaxException {
+ String error = null;
+ try {
+ return PackageIdentifier.parse(packageIdentifier);
+ } catch (LabelSyntaxException e) {
+ error = e.getMessage();
+ error = "invalid package name '" + packageIdentifier + "': " + error;
// This check is just for a more helpful error message
// i.e. valid target name, invalid package name, colon-free label form
// used => probably they meant "//foo:bar.c" not "//foo/bar.c".
- if (packageName.endsWith("/" + name)) {
+ if (packageIdentifier.endsWith("/" + name)) {
error += " (perhaps you meant \":" + name + "\"?)";
}
- throw new SyntaxException(error);
+ throw new LabelSyntaxException(error);
}
- return new PathFragment(packageName);
}
/** The name and repository of the package. */
@@ -201,32 +195,24 @@
* bazillion tests that use invalid package names (taking advantage of the fact that calling
* Label(PathFragment, String) doesn't validate the package name).
*/
- private Label(String packageName, String name) throws SyntaxException {
- this(validate(packageName, name), name);
- }
-
- /**
- * Constructor from canonical valid package name and a target name. The target
- * name is checked for validity and a SyntaxException is throw if it isn't.
- */
- private Label(PathFragment packageName, String name) throws SyntaxException {
- this(PackageIdentifier.createInDefaultRepo(packageName), name);
+ private Label(String packageIdentifier, String name) throws LabelSyntaxException {
+ this(validate(packageIdentifier, name), name);
}
private Label(PackageIdentifier packageIdentifier, String name)
- throws SyntaxException {
+ throws LabelSyntaxException {
Preconditions.checkNotNull(packageIdentifier);
Preconditions.checkNotNull(name);
try {
this.packageIdentifier = packageIdentifier;
this.name = canonicalizeTargetName(name);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// This check is just for a more helpful error message
// i.e. valid target name, invalid package name, colon-free label form
// used => probably they meant "//foo:bar.c" not "//foo/bar.c".
if (packageIdentifier.getPackageFragment().getPathString().endsWith("/" + name)) {
- throw new SyntaxException(e.getMessage() + " (perhaps you meant \":" + name + "\"?)");
+ throw new LabelSyntaxException(e.getMessage() + " (perhaps you meant \":" + name + "\"?)");
}
throw e;
}
@@ -317,9 +303,9 @@
/**
* Returns a label in the same package as this label with the given target name.
*
- * @throws SyntaxException if {@code targetName} is not a valid target name
+ * @throws LabelSyntaxException if {@code targetName} is not a valid target name
*/
- public Label getLocalTargetLabel(String targetName) throws SyntaxException {
+ public Label getLocalTargetLabel(String targetName) throws LabelSyntaxException {
return new Label(packageIdentifier, targetName);
}
@@ -341,14 +327,14 @@
+ "Label(\"//foo/bar:baz\").relative(\":quux\") == Label(\"//foo/bar:quux\")\n"
+ "Label(\"//foo/bar:baz\").relative(\"//wiz:quux\") == Label(\"//wiz:quux\")\n"
+ "</pre>")
- public Label getRelative(String relName) throws SyntaxException {
+ public Label getRelative(String relName) throws LabelSyntaxException {
if (relName.length() == 0) {
- throw new SyntaxException("empty package-relative label");
+ throw new LabelSyntaxException("empty package-relative label");
}
if (LabelValidator.isAbsolute(relName)) {
return parseAbsolute(relName);
} else if (relName.equals(":")) {
- throw new SyntaxException("':' is not a valid package-relative label");
+ throw new LabelSyntaxException("':' is not a valid package-relative label");
} else if (relName.charAt(0) == ':') {
return getLocalTargetLabel(relName.substring(1));
} else {
@@ -372,7 +358,7 @@
return new Label(
new PackageIdentifier(packageIdentifier.getRepository(), relative.getPackageFragment()),
relative.getName());
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException 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);
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
index 97b04e6..2734e4f 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Parser.java
@@ -23,6 +23,7 @@
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
@@ -646,7 +647,7 @@
Parser parser = new Parser(lexer, eventHandler, locator, parsingMode);
parser.addIncludedFiles(this.includedFiles);
list.addAll(parser.parseFileInput());
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
reportError(location, "Invalid label '" + labelName + "'");
} catch (IOException e) {
reportError(location, "Include of '" + labelName + "' failed: " + e.getMessage());
diff --git a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
index 3a7db34..c5e1eaf 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java
@@ -20,9 +20,9 @@
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomArgv;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomMultiArgv;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.testutil.Scratch;
import org.junit.Before;
@@ -56,7 +56,7 @@
}
@Test
- public void testLabelArgs() throws SyntaxException {
+ public void testLabelArgs() throws LabelSyntaxException {
CustomCommandLine cl = CustomCommandLine.builder().add(Label.parseAbsolute("//a:b")).build();
assertEquals(ImmutableList.of("//a:b"), cl.arguments());
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java b/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java
index 708408f..f574cef 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java
@@ -17,8 +17,8 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.testutil.Suite;
import com.google.devtools.build.lib.testutil.TestSpec;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -88,7 +88,7 @@
/**
* Creates fake label in package "foo".
*/
- private static Label labelFor(String targetName) throws SyntaxException {
+ private static Label labelFor(String targetName) throws LabelSyntaxException {
return Label.create("foo", targetName);
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
index 59a74a8..4e6e041 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
@@ -35,6 +35,7 @@
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigurationFactory;
import com.google.devtools.build.lib.buildtool.BuildRequest.BuildRequestOptions;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.exec.ExecutionOptions;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.Preprocessor;
@@ -53,7 +54,6 @@
import com.google.devtools.build.lib.skyframe.SkyframeExecutor;
import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.testutil.FoundationTestCase;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
@@ -289,7 +289,7 @@
try {
return SkyframeExecutorTestUtils.getExistingTarget(skyframeExecutor,
Label.parseAbsolute(label));
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new AssertionError(e);
}
}
@@ -304,7 +304,7 @@
Label parsedLabel;
try {
parsedLabel = Label.parseAbsolute(label);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new AssertionError(e);
}
return skyframeExecutor.getConfiguredTargetForTesting(parsedLabel, configuration);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
index 641781f..ac9311d 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java
@@ -76,6 +76,7 @@
import com.google.devtools.build.lib.analysis.config.ConfigurationFactory;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.buildtool.BuildRequest;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
@@ -113,7 +114,6 @@
import com.google.devtools.build.lib.skyframe.SequencedSkyframeExecutor;
import com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.testutil.FoundationTestCase;
import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.TestConstants;
@@ -273,7 +273,7 @@
protected Target getTarget(String label)
throws NoSuchPackageException, NoSuchTargetException,
- Label.SyntaxException, InterruptedException {
+ LabelSyntaxException, InterruptedException {
return getTarget(Label.parseAbsolute(label));
}
@@ -569,7 +569,8 @@
}
protected boolean ensureTargetsVisited(String... labels)
- throws InterruptedException, NoSuchTargetException, NoSuchPackageException, SyntaxException {
+ throws InterruptedException, NoSuchTargetException, NoSuchPackageException,
+ LabelSyntaxException {
List<Label> actualLabels = new ArrayList<>();
for (String label : labels) {
actualLabels.add(Label.parseAbsolute(label));
@@ -583,7 +584,7 @@
*/
protected ConfiguredTarget getConfiguredTarget(String label)
throws NoSuchPackageException, NoSuchTargetException,
- Label.SyntaxException, InterruptedException {
+ LabelSyntaxException, InterruptedException {
return getConfiguredTarget(label, targetConfig);
}
@@ -593,7 +594,7 @@
*/
protected ConfiguredTarget getConfiguredTarget(String label, BuildConfiguration config)
throws NoSuchPackageException, NoSuchTargetException,
- Label.SyntaxException, InterruptedException {
+ LabelSyntaxException, InterruptedException {
ensureTargetsVisited(label);
return view.getConfiguredTargetForTesting(getTarget(label), config);
}
@@ -614,7 +615,7 @@
*/
protected FileConfiguredTarget getFileConfiguredTarget(String label)
throws NoSuchPackageException, NoSuchTargetException,
- Label.SyntaxException, InterruptedException {
+ LabelSyntaxException, InterruptedException {
return (FileConfiguredTarget) getConfiguredTarget(label, targetConfig);
}
@@ -624,7 +625,7 @@
*/
protected ConfiguredTarget getHostConfiguredTarget(String label)
throws NoSuchPackageException, NoSuchTargetException,
- Label.SyntaxException, InterruptedException {
+ LabelSyntaxException, InterruptedException {
return getConfiguredTarget(label, getHostConfiguration());
}
@@ -634,7 +635,7 @@
*/
protected FileConfiguredTarget getHostFileConfiguredTarget(String label)
throws NoSuchPackageException, NoSuchTargetException,
- Label.SyntaxException, InterruptedException {
+ LabelSyntaxException, InterruptedException {
return (FileConfiguredTarget) getHostConfiguredTarget(label);
}
@@ -1070,7 +1071,7 @@
private static Label makeLabel(String label) {
try {
return Label.parseAbsolute(label);
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalStateException(e);
}
}
@@ -1328,9 +1329,9 @@
* Utility method for tests. Converts an array of strings into a set of labels.
*
* @param strings the set of strings to be converted to labels.
- * @throws SyntaxException if there are any syntax errors in the strings.
+ * @throws LabelSyntaxException if there are any syntax errors in the strings.
*/
- public static Set<Label> asLabelSet(String... strings) throws SyntaxException {
+ public static Set<Label> asLabelSet(String... strings) throws LabelSyntaxException {
return asLabelSet(ImmutableList.copyOf(strings));
}
@@ -1338,9 +1339,9 @@
* Utility method for tests. Converts an array of strings into a set of labels.
*
* @param strings the set of strings to be converted to labels.
- * @throws SyntaxException if there are any syntax errors in the strings.
+ * @throws LabelSyntaxException if there are any syntax errors in the strings.
*/
- public static Set<Label> asLabelSet(Iterable<String> strings) throws SyntaxException {
+ public static Set<Label> asLabelSet(Iterable<String> strings) throws LabelSyntaxException {
Set<Label> result = Sets.newTreeSet();
for (String s : strings) {
result.add(Label.parseAbsolute(s));
diff --git a/src/test/java/com/google/devtools/build/lib/cmdline/LabelValidatorTest.java b/src/test/java/com/google/devtools/build/lib/cmdline/LabelValidatorTest.java
index f14943d..547851f 100644
--- a/src/test/java/com/google/devtools/build/lib/cmdline/LabelValidatorTest.java
+++ b/src/test/java/com/google/devtools/build/lib/cmdline/LabelValidatorTest.java
@@ -98,6 +98,8 @@
assertEquals(emptyPackage, LabelValidator.validateAbsoluteLabel("@repo//:bar"));
assertEquals(new PackageAndTarget("foo", "bar"),
LabelValidator.validateAbsoluteLabel("@repo//foo:bar"));
+ assertEquals(new PackageAndTarget("foo", "bar"),
+ LabelValidator.validateAbsoluteLabel("@//foo:bar"));
try {
LabelValidator.validateAbsoluteLabel("@foo");
diff --git a/src/test/java/com/google/devtools/build/lib/cmdline/PackageIdentifierTest.java b/src/test/java/com/google/devtools/build/lib/cmdline/PackageIdentifierTest.java
index 86f295b..f5ee2bf 100644
--- a/src/test/java/com/google/devtools/build/lib/cmdline/PackageIdentifierTest.java
+++ b/src/test/java/com/google/devtools/build/lib/cmdline/PackageIdentifierTest.java
@@ -49,6 +49,9 @@
PackageIdentifier plainA = PackageIdentifier.parse("a");
assertThat(plainA.getRepository().strippedName()).isEqualTo("");
assertThat(fooA.getPackageFragment().getPathString()).isEqualTo("a");
+
+ PackageIdentifier mainA = PackageIdentifier.parse("@//a");
+ assertThat(mainA.getRepository()).isEqualTo(PackageIdentifier.MAIN_REPOSITORY_NAME);
}
@Test
@@ -59,45 +62,38 @@
assertEquals("@foo/bar", RepositoryName.create("@foo/bar").toString());
assertEquals("@foo.bar", RepositoryName.create("@foo.bar").toString());
- // Bad:
- try {
- RepositoryName.create("@");
- fail();
- } catch (TargetParsingException expected) {
- assertThat(expected.getMessage()).contains("empty workspace name");
- }
try {
RepositoryName.create("@abc/");
fail();
- } catch (TargetParsingException expected) {
+ } catch (LabelSyntaxException expected) {
assertThat(expected.getMessage()).contains(
"workspace names cannot start nor end with '/'");
}
try {
RepositoryName.create("@/abc");
fail();
- } catch (TargetParsingException expected) {
+ } catch (LabelSyntaxException expected) {
assertThat(expected.getMessage()).contains(
"workspace names cannot start nor end with '/'");
}
try {
RepositoryName.create("@a//////b");
fail();
- } catch (TargetParsingException expected) {
+ } catch (LabelSyntaxException expected) {
assertThat(expected.getMessage()).contains(
"workspace names cannot contain multiple '/'s in a row");
}
try {
RepositoryName.create("@foo@");
fail();
- } catch (TargetParsingException expected) {
+ } catch (LabelSyntaxException expected) {
assertThat(expected.getMessage()).contains(
"workspace names may contain only A-Z, a-z, 0-9, '-', '_', '.', and '/'");
}
try {
RepositoryName.create("x");
fail();
- } catch (TargetParsingException expected) {
+ } catch (LabelSyntaxException expected) {
assertThat(expected.getMessage()).contains("workspace name must start with '@'");
}
}
@@ -132,7 +128,7 @@
try {
new PackageIdentifier("foo", new PathFragment("bar/baz"));
fail("'foo' is not a legal repository name");
- } catch (TargetParsingException expected) {
+ } catch (LabelSyntaxException expected) {
assertThat(expected.getMessage()).contains("workspace name must start with '@'");
}
}
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 f5041d2..9666b02 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
@@ -34,6 +34,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventCollector;
@@ -46,7 +47,6 @@
import com.google.devtools.build.lib.packages.RuleClass.MissingFragmentPolicy;
import com.google.devtools.build.lib.packages.util.PackageLoadingTestCase;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.vfs.Path;
import java.util.ArrayList;
@@ -78,7 +78,7 @@
private static final Predicate<String> PREFERRED_DEPENDENCY_PREDICATE = Predicates.alwaysFalse();
- private static RuleClass createRuleClassA() throws Label.SyntaxException {
+ private static RuleClass createRuleClassA() throws LabelSyntaxException {
return new RuleClass("ruleA", false, false, false, false, false, false,
ImplicitOutputsFunction.NONE, RuleClass.NO_CHANGE,
DUMMY_CONFIGURED_TARGET_FACTORY, PredicatesWithMessage.<Rule>alwaysTrue(),
@@ -650,12 +650,12 @@
}
private Rule createRule(RuleClass ruleClass, String name, Map<String, Object> attributeValues,
- Location location) throws SyntaxException, InterruptedException {
+ Location location) throws LabelSyntaxException, InterruptedException {
Package.Builder pkgBuilder = createDummyPackageBuilder();
Label ruleLabel;
try {
ruleLabel = pkgBuilder.createLabel(name);
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new IllegalArgumentException("Rule has illegal label");
}
return ruleClass.createRuleWithLabel(pkgBuilder, ruleLabel, attributeValues,
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java
index dd44efc..7a73418 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java
@@ -20,6 +20,7 @@
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.ConstantRuleVisibility;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
@@ -38,7 +39,6 @@
import com.google.devtools.build.lib.skyframe.SkyValueDirtinessChecker;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor;
import com.google.devtools.build.lib.syntax.Label;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.testutil.FoundationTestCase;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.util.BlazeClock;
@@ -118,7 +118,7 @@
protected Target getTarget(String label)
throws NoSuchPackageException, NoSuchTargetException,
- Label.SyntaxException, InterruptedException {
+ LabelSyntaxException, InterruptedException {
return getTarget(Label.parseAbsolute(label));
}
@@ -187,9 +187,9 @@
* Utility method for tests. Converts an array of strings into a set of labels.
*
* @param strings the set of strings to be converted to labels.
- * @throws SyntaxException if there are any syntax errors in the strings.
+ * @throws LabelSyntaxException if there are any syntax errors in the strings.
*/
- public static Set<Label> asLabelSet(String... strings) throws SyntaxException {
+ public static Set<Label> asLabelSet(String... strings) throws LabelSyntaxException {
return asLabelSet(ImmutableList.copyOf(strings));
}
@@ -197,9 +197,9 @@
* Utility method for tests. Converts an array of strings into a set of labels.
*
* @param strings the set of strings to be converted to labels.
- * @throws SyntaxException if there are any syntax errors in the strings.
+ * @throws LabelSyntaxException if there are any syntax errors in the strings.
*/
- public static Set<Label> asLabelSet(Iterable<String> strings) throws SyntaxException {
+ public static Set<Label> asLabelSet(Iterable<String> strings) throws LabelSyntaxException {
Set<Label> result = Sets.newTreeSet();
for (String s : strings) {
result.add(Label.parseAbsolute(s));
@@ -208,12 +208,12 @@
}
protected final Set<Target> asTargetSet(String... strLabels)
- throws SyntaxException, NoSuchThingException, InterruptedException {
+ throws LabelSyntaxException, NoSuchThingException, InterruptedException {
return asTargetSet(Arrays.asList(strLabels));
}
protected Set<Target> asTargetSet(Iterable<String> strLabels)
- throws SyntaxException, NoSuchThingException, InterruptedException {
+ throws LabelSyntaxException, NoSuchThingException, InterruptedException {
Set<Target> targets = new HashSet<>();
for (String strLabel : strLabels) {
targets.add(getTarget(strLabel));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java b/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java
index ea964ce..2867ea4 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/util/SkyframeExecutorTestUtils.java
@@ -131,7 +131,7 @@
public static Target getExistingTarget(SkyframeExecutor skyframeExecutor,
Label label) {
PackageValue value = (PackageValue) getExistingValue(skyframeExecutor,
- PackageValue.key(label.getPackageFragment()));
+ PackageValue.key(label.getPackageIdentifier()));
if (value == null) {
return null;
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
index bf9672e..bcad177 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
@@ -20,6 +20,7 @@
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Lists;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,7 +56,7 @@
return new FilesetEntry(Label.parseAbsolute("//foo:bar"),
Lists.<Label>newArrayList(), Lists.newArrayList("xyz"), "",
FilesetEntry.SymlinkBehavior.COPY, ".");
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new RuntimeException("Bad label: ", e);
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java
index 322fb64..2ac874c 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/LabelTest.java
@@ -19,7 +19,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -60,7 +60,7 @@
}
}
- private static String parseCommandLine(String label, String prefix) throws SyntaxException {
+ private static String parseCommandLine(String label, String prefix) throws LabelSyntaxException {
return Label.parseCommandLineLabel(label, new PathFragment(prefix)).toString();
}
@@ -91,7 +91,7 @@
try {
parseCommandLine("//absolute:A+bad%syntax", "");
fail();
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
// Expected exception
}
}
@@ -112,25 +112,25 @@
try {
base.getRelative("/p1/p2:target");
fail();
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
/* ok */
}
try {
base.getRelative("quux:");
fail();
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
/* ok */
}
try {
base.getRelative(":");
fail();
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
/* ok */
}
try {
base.getRelative("::");
fail();
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
/* ok */
}
}
@@ -186,7 +186,7 @@
try {
Label.parseAbsolute(label);
fail("Label '" + label + "' did not contain a syntax error");
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
assertContainsRegex(Pattern.quote(expectedError), e.getMessage());
}
}
@@ -358,7 +358,7 @@
try {
Label.parseAbsolute("foo//bar/baz:bat/boo");
fail();
- } catch (SyntaxException e) {
+ } catch (LabelSyntaxException e) {
assertThat(e).hasMessage("invalid repository name 'foo': workspace name must start with '@'");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
index 21c1de1..63d5236 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/PrinterTest.java
@@ -20,7 +20,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
-import com.google.devtools.build.lib.syntax.Label.SyntaxException;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,7 +52,7 @@
return new FilesetEntry(Label.parseAbsolute("//foo:bar"),
Lists.<Label>newArrayList(), Lists.newArrayList("xyz"), "",
FilesetEntry.SymlinkBehavior.COPY, ".");
- } catch (Label.SyntaxException e) {
+ } catch (LabelSyntaxException e) {
throw new RuntimeException("Bad label: ", e);
}
}
@@ -245,13 +245,13 @@
}
private FilesetEntry createTestFilesetEntry(FilesetEntry.SymlinkBehavior symlinkBehavior)
- throws SyntaxException {
+ throws LabelSyntaxException {
Label label = Label.parseAbsolute("//x");
return new FilesetEntry(
label, Arrays.asList(label), Arrays.<String>asList(), "", symlinkBehavior, ".");
}
- private FilesetEntry createTestFilesetEntry() throws SyntaxException {
+ private FilesetEntry createTestFilesetEntry() throws LabelSyntaxException {
return createTestFilesetEntry(FilesetEntry.SymlinkBehavior.COPY);
}
}
diff --git a/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/Resolver.java b/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/Resolver.java
index 0feebe2..1b90378 100644
--- a/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/Resolver.java
+++ b/src/tools/generate_workspace/src/main/java/com/google/devtools/build/workspace/Resolver.java
@@ -16,8 +16,8 @@
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.bazel.BazelMain;
+import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
@@ -94,7 +94,7 @@
PackageIdentifier.RepositoryName repositoryName;
try {
repositoryName = PackageIdentifier.RepositoryName.create("@" + target.getName());
- } catch (TargetParsingException e) {
+ } catch (LabelSyntaxException e) {
handler.handle(Event.error(location, "Invalid repository name for " + target + ": "
+ e.getMessage()));
return;