Set --package_path=%workspace% by default and remove Constants.DEFAULT_PACKAGE_PATH.
--
MOS_MIGRATED_REVID=118666575
diff --git a/src/main/java/com/google/devtools/build/lib/Constants.java b/src/main/java/com/google/devtools/build/lib/Constants.java
index 149977f..8103f50 100644
--- a/src/main/java/com/google/devtools/build/lib/Constants.java
+++ b/src/main/java/com/google/devtools/build/lib/Constants.java
@@ -28,9 +28,6 @@
// Google's internal name for Bazel is 'Blaze', and it will take some more time to change that.
public static final String PRODUCT_NAME = "bazel";
- // Default value for the --package_path flag if not otherwise set.
- public static final ImmutableList<String> DEFAULT_PACKAGE_PATH = ImmutableList.of("%workspace%");
-
// Native Java deps are all linked into a single file, which is named with this value + ".so".
public static final String NATIVE_DEPS_LIB_SUFFIX = "_nativedeps";
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java b/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java
index 04039f1..1c39014 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/PackageCacheOptions.java
@@ -18,7 +18,6 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import com.google.devtools.build.lib.Constants;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.packages.ConstantRuleVisibility;
@@ -35,25 +34,6 @@
* Options for configuring the PackageCache.
*/
public class PackageCacheOptions extends OptionsBase {
- /**
- * A converter for package path that defaults to {@code Constants.DEFAULT_PACKAGE_PATH} if the
- * option is not given.
- *
- * <p>Required because you cannot specify a non-constant value in annotation attributes.
- */
- public static class PackagePathConverter implements Converter<List<String>> {
- @Override
- public List<String> convert(String input) throws OptionsParsingException {
- return input.isEmpty()
- ? Constants.DEFAULT_PACKAGE_PATH
- : new Converters.ColonSeparatedOptionListConverter().convert(input);
- }
-
- @Override
- public String getTypeDescription() {
- return "a string";
- }
- }
/**
* Converter for the {@code --default_visibility} option.
@@ -78,9 +58,9 @@
}
@Option(name = "package_path",
- defaultValue = "",
+ defaultValue = "%workspace%",
category = "package loading",
- converter = PackagePathConverter.class,
+ converter = Converters.ColonSeparatedOptionListConverter.class,
help = "A colon-separated list of where to look for packages. "
+ "Elements beginning with '%workspace%' are relative to the enclosing "
+ "workspace. If omitted or empty, the default is the output of "
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java
index f9b217d..fd5adcbc 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java
@@ -18,7 +18,6 @@
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
-import com.google.devtools.build.lib.Constants;
import com.google.devtools.build.lib.analysis.BlazeVersionInfo;
import com.google.devtools.build.lib.analysis.NoBuildEvent;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
@@ -344,7 +343,7 @@
return getBuildLanguageDefinition(runtime.getRuleClassProvider());
case DEFAULT_PACKAGE_PATH:
- return Joiner.on(":").join(Constants.DEFAULT_PACKAGE_PATH);
+ return Joiner.on(":").join(options.getOptions(PackageCacheOptions.class).packagePath);
default:
throw new IllegalArgumentException("missing implementation for " + key);
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index 3bced18..6fef013 100644
--- a/src/test/java/com/google/devtools/build/lib/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/BUILD
@@ -604,6 +604,7 @@
":test_runner",
"//src/main/java/com/google/devtools/build/lib:bazel-rules",
"//src/main/java/com/google/devtools/build/lib:build-base",
+ "//src/main/java/com/google/devtools/build/lib:flags",
"//src/main/java/com/google/devtools/build/lib:io",
"//src/main/java/com/google/devtools/build/lib:packages",
"//src/main/java/com/google/devtools/build/skyframe",
diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java
index 56ab203..6436e64 100644
--- a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java
@@ -31,6 +31,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.events.Event;
+import com.google.devtools.build.lib.flags.InvocationPolicyEnforcer;
import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.NoSuchTargetException;
@@ -56,6 +57,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.OptionsParser;
+import com.google.devtools.common.options.OptionsParsingException;
import org.junit.Before;
import org.junit.Test;
@@ -115,6 +117,15 @@
OptionsParser parser = OptionsParser.newOptionsParser(PackageCacheOptions.class);
parser.parse(new String[] { "--default_visibility=public" });
parser.parse(options);
+
+ InvocationPolicyEnforcer optionsPolicyEnforcer =
+ new InvocationPolicyEnforcer(TestConstants.TEST_INVOCATION_POLICY);
+ try {
+ optionsPolicyEnforcer.enforce(parser);
+ } catch (OptionsParsingException e) {
+ throw new IllegalStateException(e);
+ }
+
return parser.getOptions(PackageCacheOptions.class);
}