Skip to content

Commit

Permalink
Use default methods in PackageSettings.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 532451426
Change-Id: I946fc358ee85ae8d0ce551ed95df8ef6e1709812
  • Loading branch information
justinhorvitz authored and copybara-github committed May 16, 2023
1 parent 277d05f commit 6c1487c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 33 deletions.
27 changes: 6 additions & 21 deletions src/main/java/com/google/devtools/build/lib/packages/Package.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable;
import com.google.devtools.build.lib.packages.License.DistributionType;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
Expand Down Expand Up @@ -900,7 +899,7 @@ public static Builder newExternalPackageBuilderForBzlmod(
PackageIdentifier basePackageId,
RepositoryMapping repoMapping) {
return new Builder(
DefaultPackageSettings.INSTANCE,
PackageSettings.DEFAULTS,
basePackageId,
DUMMY_WORKSPACE_NAME_FOR_BZLMOD_PACKAGES,
/* associatedModuleName= */ Optional.empty(),
Expand Down Expand Up @@ -943,30 +942,16 @@ public interface PackageSettings {
* thrown from {@link #getTarget}. Useful for toning down verbosity in situations where it can
* be less helpful.
*/
boolean succinctTargetNotFoundErrors();

/**
* Reports whether to record the set of Modules loaded by this package, which enables richer
* modes of blaze query.
*/
boolean recordLoadedModules();
}

/** Default {@link PackageSettings}. */
public static class DefaultPackageSettings implements PackageSettings {
public static final DefaultPackageSettings INSTANCE = new DefaultPackageSettings();

private DefaultPackageSettings() {}

@Override
public boolean succinctTargetNotFoundErrors() {
default boolean succinctTargetNotFoundErrors() {
return false;
}

@Override
public boolean recordLoadedModules() {
/** Reports whether to record the set of Modules loaded by this package. */
default boolean recordLoadedModules() {
return true;
}

PackageSettings DEFAULTS = new PackageSettings() {};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import com.google.devtools.build.lib.events.OutputFilter;
import com.google.devtools.build.lib.exec.BinTools;
import com.google.devtools.build.lib.jni.JniLoader;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.PackageLoadingListener;
Expand Down Expand Up @@ -1644,7 +1643,7 @@ private static PackageSettings getPackageSettings(List<BlazeModule> blazeModules
.collect(toImmutableList());
Preconditions.checkState(
packageSettingss.size() <= 1, "more than one module defines a PackageSettings");
return Iterables.getFirst(packageSettingss, DefaultPackageSettings.INSTANCE);
return Iterables.getFirst(packageSettingss, PackageSettings.DEFAULTS);
}

private static PackageValidator getPackageValidator(List<BlazeModule> blazeModules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.google.devtools.build.lib.packages.CachingPackageLocator;
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings;
import com.google.devtools.build.lib.packages.Package.ConfigSettingVisibilityPolicy;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.PackageLoadingListener;
Expand Down Expand Up @@ -286,7 +286,7 @@ public final PackageLoader build() {
new PackageFactory(
ruleClassProvider,
forkJoinPoolForNonSkyframeGlobbing,
DefaultPackageSettings.INSTANCE,
PackageSettings.DEFAULTS,
PackageValidator.NOOP_VALIDATOR,
PackageOverheadEstimator.NOOP_ESTIMATOR,
PackageLoadingListener.NOOP_LISTENER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.google.devtools.build.lib.events.ExtendedEventHandler;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
Expand Down Expand Up @@ -135,7 +135,7 @@ private void setUpContextForRule(
throws Exception {
Package.Builder packageBuilder =
Package.newExternalPackageBuilder(
DefaultPackageSettings.INSTANCE,
PackageSettings.DEFAULTS,
RootedPath.toRootedPath(root, workspaceFile),
"runfiles",
RepositoryMapping.ALWAYS_FALLBACK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.events.StoredEventHandler;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
Expand Down Expand Up @@ -160,7 +160,7 @@ public void testBuildPartialPopulatesImplicitTestSuiteValueIdempotently() throws
private Package.Builder pkgBuilder(String name) {
Package.Builder result =
new Package.Builder(
DefaultPackageSettings.INSTANCE,
PackageSettings.DEFAULTS,
PackageIdentifier.createInMainRepo(name),
"workspace",
Optional.empty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Root;
Expand Down Expand Up @@ -65,7 +65,7 @@ void parse(String... args) {
// execute
builder =
Package.newExternalPackageBuilder(
DefaultPackageSettings.INSTANCE,
PackageSettings.DEFAULTS,
RootedPath.toRootedPath(root, workspaceFilePath),
"",
RepositoryMapping.ALWAYS_FALLBACK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.packages.BuilderFactoryForTesting;
import com.google.devtools.build.lib.packages.Package.Builder.DefaultPackageSettings;
import com.google.devtools.build.lib.packages.Package.Builder.PackageSettings;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.PackageLoadingListener;
import com.google.devtools.build.lib.packages.RuleClassProvider;
Expand Down Expand Up @@ -52,7 +52,7 @@ public PackageFactory build(RuleClassProvider ruleClassProvider, FileSystem fs)
return new PackageFactory(
ruleClassProvider,
PackageFactory.makeDefaultSizedForkJoinPoolForGlobbing(),
DefaultPackageSettings.INSTANCE,
PackageSettings.DEFAULTS,
packageValidator,
packageOverheadEstimator,
doChecksForTesting
Expand Down

0 comments on commit 6c1487c

Please sign in to comment.