Skip to content

Commit

Permalink
Remove default build options.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 372371075
  • Loading branch information
justinhorvitz authored and copybara-github committed May 6, 2021
1 parent 80c2da2 commit 1e803ab
Show file tree
Hide file tree
Showing 46 changed files with 188 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses;
import com.google.devtools.build.lib.bazel.rules.sh.BazelShRuleClasses;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
Expand All @@ -44,9 +43,9 @@
import java.io.IOException;

/** Module implementing the rule set of Bazel. */
public class BazelRulesModule extends BlazeModule {
public final class BazelRulesModule extends BlazeModule {
/** This is where deprecated options go to die. */
public static class GraveyardOptions extends OptionsBase {
public static final class GraveyardOptions extends OptionsBase {
@Option(
name = "incompatible_load_python_rules_from_bzl",
defaultValue = "false",
Expand Down Expand Up @@ -535,12 +534,6 @@ public void workspaceInit(
CcSkyframeFdoSupportValue.SKYFUNCTION, new CcSkyframeFdoSupportFunction(directories));
}

@Override
public BuildOptions getDefaultBuildOptions(BlazeRuntime blazeRuntime) {
return BuildOptions.getDefaultBuildOptionsForFragments(
blazeRuntime.getRuleClassProvider().getConfigurationOptions());
}

@Override
public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command) {
return "build".equals(command.name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation",
"//src/main/java/com/google/devtools/build/lib/rules/java:java-rules",
"//src/main/java/com/google/devtools/build/lib/shell",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/util",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/util:custom_exit_code_publisher",
"//src/main/java/com/google/devtools/build/lib/util:custom_failure_detail_publisher",
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
"//src/main/java/com/google/devtools/build/lib/util:exit_code",
"//src/main/java/com/google/devtools/build/lib/util:logging",
"//third_party:flogger",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public void buildArtifacts(
options,
actionCacheChecker,
topDownActionCache,
null,
topLevelArtifactContext);
detailedExitCode =
processResult(
Expand Down Expand Up @@ -253,7 +252,7 @@ public void buildArtifacts(
* <li>{@code null}, if {@code result} had no errors
* <li>{@code e} if result had errors and one of them specified a {@link DetailedExitCode} value
* {@code e}
* <li>a {@link DetailedExitCode} with {@link Code.NON_ACTION_EXECUTION_FAILURE} if result had
* <li>a {@link DetailedExitCode} with {@link Code#NON_ACTION_EXECUTION_FAILURE} if result had
* errors but none specified a {@link DetailedExitCode} value
* </ol>
*
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/google/devtools/build/lib/exec/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ java_library(
srcs = ["SpawnExecException.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
"//src/main/java/com/google/devtools/build/lib/util:exit_code",
"//src/main/protobuf:failure_details_java_proto",
"//third_party:guava",
],
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/google/devtools/build/lib/profiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ java_library(
]),
deps = [
":profiler",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:var_int",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//third_party:auto_value",
"//third_party:gson",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/common/options",
"//src/main/java/net/starlark/java/eval",
"//src/main/java/net/starlark/java/syntax",
"//third_party/allocation_instrumenter",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/actions:file_metadata",
"//src/main/java/com/google/devtools/build/lib/profiler",
"//src/main/java/com/google/devtools/build/lib/remote/common",
"//src/main/java/com/google/devtools/build/lib/remote/util",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:config/invalid_configuration_exception",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/apple",
"//src/main/java/com/google/devtools/common/options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/rules/proto",
"//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_and_data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:config/core_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:config/invalid_configuration_exception",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/cmdline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/split_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/transition_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/analysis:file_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:platform_options",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/analysis:test/instrumented_files_info",
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/google/devtools/build/lib/rules/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:config/invalid_configuration_exception",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/analysis:file_provider",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_collection",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_provider",
Expand All @@ -45,7 +42,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec",
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi",
"//src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto",
Expand All @@ -54,7 +50,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/common/options",
"//src/main/java/net/starlark/java/syntax",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,6 @@ public Iterable<Class<? extends OptionsBase>> getCommonCommandOptions() {
return ImmutableList.of();
}

/**
* Returns an instance of BuildOptions to be used to create {@link
* BuildOptions.OptionsDiffForReconstruction} with. Only one installed Module should override
* this.
*/
public BuildOptions getDefaultBuildOptions(BlazeRuntime runtime) {
return null;
}

/**
* Called after Bazel analyzes the build's top-level targets. This is called once per build if
* --analyze is enabled. Modules can override this to perform extra checks on analysis results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -237,7 +238,7 @@ private BlazeRuntime(
retainedHeapLimiter = RetainedHeapLimiter.create(bugReporter);

CommandNameCache.CommandNameCacheInstance.INSTANCE.setCommandNameCache(
new CommandNameCacheImpl(getCommandMap()));
new CommandNameCacheImpl(commandMap));
this.productName = productName;
this.buildEventArtifactUploaderFactoryMap = buildEventArtifactUploaderFactoryMap;
this.authHeadersProviderMap =
Expand All @@ -253,8 +254,7 @@ public BlazeWorkspace initWorkspace(BlazeDirectories directories, BinTools binTo
for (BlazeModule module : blazeModules) {
module.workspaceInit(this, directories, builder);
}
this.workspace =
builder.build(this, packageFactory, ruleClassProvider, eventBusExceptionHandler);
this.workspace = builder.build(this, packageFactory, eventBusExceptionHandler);
return workspace;
}

Expand Down Expand Up @@ -287,7 +287,7 @@ private void addCommand(BlazeCommand command) {
}

@VisibleForTesting
public final void overrideCommands(Iterable<BlazeCommand> commands) {
public void overrideCommands(Iterable<BlazeCommand> commands) {
commandMap.clear();
for (BlazeCommand command : commands) {
addCommand(command);
Expand All @@ -301,7 +301,7 @@ public InvocationPolicy getModuleInvocationPolicy() {

private BuildEventArtifactUploader newUploader(
CommandEnvironment env, String buildEventUploadStrategy) throws IOException {
return getBuildEventArtifactUploaderFactoryMap().select(buildEventUploadStrategy).create(env);
return buildEventArtifactUploaderFactoryMap.select(buildEventUploadStrategy).create(env);
}

/** Configure profiling based on the provided options. */
Expand Down Expand Up @@ -452,7 +452,7 @@ public ActionKeyContext getActionKeyContext() {

/** The directory in which blaze stores the server state - that is, the socket file and a log. */
private Path getServerDirectory() {
return getWorkspace().getDirectories().getOutputBase().getChild("server");
return workspace.getDirectories().getOutputBase().getChild("server");
}

/**
Expand Down Expand Up @@ -490,25 +490,6 @@ public Iterable<BlazeModule> getBlazeModules() {
return blazeModules;
}

public BuildOptions getDefaultBuildOptions() {
BuildOptions options = null;
for (BlazeModule module : blazeModules) {
BuildOptions optionsFromModule = module.getDefaultBuildOptions(this);
if (optionsFromModule != null) {
if (options == null) {
options = optionsFromModule;
} else {
throw new IllegalArgumentException(
"Two or more bazel modules contained default build options.");
}
}
}
if (options == null) {
throw new IllegalArgumentException("No default build options specified in any Bazel module");
}
return options;
}

/**
* Returns the first module that is an instance of a given class or interface.
*
Expand Down Expand Up @@ -860,10 +841,10 @@ static CommandLineOptions splitStartupOptions(Iterable<BlazeModule> modules, Str
}

private static InterruptSignalHandler captureSigint() {
final Thread mainThread = Thread.currentThread();
final AtomicInteger numInterrupts = new AtomicInteger();
Thread mainThread = Thread.currentThread();
AtomicInteger numInterrupts = new AtomicInteger();

final Runnable interruptWatcher =
Runnable interruptWatcher =
() -> {
int count = 0;
// Not an actual infinite loop because it's run in a daemon thread.
Expand Down Expand Up @@ -912,9 +893,7 @@ private static int batchMain(Iterable<BlazeModule> modules, String[] args) {
runtime = newRuntime(modules, commandLineOptions.getStartupArgs(), null);
policy =
InvocationPolicyParser.parsePolicy(
runtime
.getStartupOptionsProvider()
.getOptions(BlazeServerStartupOptions.class)
runtime.startupOptionsProvider.getOptions(BlazeServerStartupOptions.class)
.invocationPolicy);
} catch (OptionsParsingException e) {
OutErr.SYSTEM_OUT_ERR.printErrLn(e.getMessage());
Expand Down Expand Up @@ -944,7 +923,7 @@ private static int batchMain(Iterable<BlazeModule> modules, String[] args) {
OutErr.SYSTEM_OUT_ERR,
LockingMode.ERROR_OUT,
"batch client",
runtime.getClock().currentTimeMillis(),
runtime.clock.currentTimeMillis(),
Optional.of(startupOptionsFromCommandLine.build()),
/*commandExtensions=*/ ImmutableList.of());
if (result.getExecRequest() == null) {
Expand Down Expand Up @@ -1024,13 +1003,13 @@ private static int serverMain(Iterable<BlazeModule> modules, OutErr outErr, Stri

BlazeCommandDispatcher dispatcher = new BlazeCommandDispatcher(runtime, serverPid);
BlazeServerStartupOptions startupOptions =
runtime.getStartupOptionsProvider().getOptions(BlazeServerStartupOptions.class);
runtime.startupOptionsProvider.getOptions(BlazeServerStartupOptions.class);
RPCServer rpcServer =
GrpcServerImpl.create(
dispatcher,
shutdownHooks,
pidFileWatcher,
runtime.getClock(),
runtime.clock,
startupOptions.commandPort,
runtime.getServerDirectory(),
serverPid,
Expand Down Expand Up @@ -1598,8 +1577,8 @@ public Builder setActionKeyContext(ActionKeyContext actionKeyContext) {
private static PackageSettings getPackageSettings(List<BlazeModule> blazeModules) {
List<PackageSettings> packageSettingss =
blazeModules.stream()
.map(module -> module.getPackageSettings())
.filter(settings -> settings != null)
.map(BlazeModule::getPackageSettings)
.filter(Objects::nonNull)
.collect(toImmutableList());
Preconditions.checkState(
packageSettingss.size() <= 1, "more than one module defines a PackageSettings");
Expand All @@ -1609,8 +1588,8 @@ private static PackageSettings getPackageSettings(List<BlazeModule> blazeModules
private static PackageValidator getPackageValidator(List<BlazeModule> blazeModules) {
List<PackageValidator> packageValidators =
blazeModules.stream()
.map(module -> module.getPackageValidator())
.filter(validator -> validator != null)
.map(BlazeModule::getPackageValidator)
.filter(Objects::nonNull)
.collect(toImmutableList());
Preconditions.checkState(
packageValidators.size() <= 1, "more than one module defined a PackageValidator");
Expand All @@ -1622,7 +1601,7 @@ private static PackageOverheadEstimator getPackageOverheadEstimator(
List<PackageOverheadEstimator> packageOverheadEstimators =
blazeModules.stream()
.map(BlazeModule::getPackageOverheadEstimator)
.filter(estimator -> estimator != null)
.filter(Objects::nonNull)
.collect(toImmutableList());
Preconditions.checkState(
packageOverheadEstimators.size() <= 1,
Expand All @@ -1641,7 +1620,7 @@ private static PackageLoadingListener getPackageLoadingListener(
.map(
module ->
module.getPackageLoadingListener(packageBuilderHelper, ruleClassProvider, fs))
.filter(validator -> validator != null)
.filter(Objects::nonNull)
.collect(toImmutableList());
return PackageLoadingListener.create(listeners);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.eventbus.SubscriberExceptionHandler;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.WorkspaceStatusAction;
import com.google.devtools.build.lib.exec.BinTools;
import com.google.devtools.build.lib.packages.PackageFactory;
Expand Down Expand Up @@ -63,12 +62,10 @@ public final class WorkspaceBuilder {
BlazeWorkspace build(
BlazeRuntime runtime,
PackageFactory packageFactory,
ConfiguredRuleClassProvider ruleClassProvider,
SubscriberExceptionHandler eventBusExceptionHandler) throws AbruptExitException {
// Set default values if none are set.
if (skyframeExecutorFactory == null) {
skyframeExecutorFactory =
new SequencedSkyframeExecutorFactory(runtime.getDefaultBuildOptions());
skyframeExecutorFactory = new SequencedSkyframeExecutorFactory();
}

SkyframeExecutor skyframeExecutor =
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/pkgcache",
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
],
Expand Down Expand Up @@ -2449,7 +2448,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/pkgcache",
"//src/main/java/com/google/devtools/build/lib/supplier",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//third_party:guava",
Expand Down
Loading

0 comments on commit 1e803ab

Please sign in to comment.