From cf2dca1271e8d853616f72f2dd078d1e97613056 Mon Sep 17 00:00:00 2001 From: gregce Date: Thu, 17 Aug 2017 16:58:33 +0200 Subject: Remove ConfigurationCollectionFactory as part of the static config cleanup. PiperOrigin-RevId: 165578449 --- .../analysis/ConfigurationCollectionFactory.java | 51 ----- .../lib/analysis/ConfiguredRuleClassProvider.java | 21 --- .../bazel/rules/BazelConfigurationCollection.java | 210 --------------------- .../lib/bazel/rules/BazelRuleClassProvider.java | 1 - .../lib/skyframe/BuildConfigurationFunction.java | 3 - 5 files changed, 286 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/analysis/ConfigurationCollectionFactory.java delete mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfigurationCollectionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfigurationCollectionFactory.java deleted file mode 100644 index 8d93d05614..0000000000 --- a/src/main/java/com/google/devtools/build/lib/analysis/ConfigurationCollectionFactory.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2014 The Bazel Authors. 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.analysis; - -import com.google.common.cache.Cache; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -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.events.EventHandler; -import javax.annotation.Nullable; - -/** - * A factory for configuration collection creation. - */ -public interface ConfigurationCollectionFactory { - /** - * Creates the top-level configuration for a build. - * - *

Also it may create a set of BuildConfigurations and define a transition table over them. All - * configurations during a build should be accessible from this top-level configuration via - * configuration transitions. - * - * @param cache a cache for BuildConfigurations - * @param loadedPackageProvider the package provider - * @param buildOptions top-level build options representing the command-line - * @param errorEventListener the event listener for errors - * @param mainRepositoryName the workspace name of the main repository - * @return the top-level configuration - * @throws InvalidConfigurationException - */ - @Nullable - BuildConfiguration createConfigurations( - Cache cache, - PackageProviderForConfigurations loadedPackageProvider, - BuildOptions buildOptions, - EventHandler errorEventListener, - String mainRepositoryName) - throws InvalidConfigurationException, InterruptedException; -} 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 f46145a5e7..b929b99ec5 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 @@ -213,7 +213,6 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { private final Map, RuleClass> ruleMap = new HashMap<>(); private final Digraph> dependencyGraph = new Digraph<>(); - private ConfigurationCollectionFactory configurationCollectionFactory; private ImmutableMap.Builder dynamicTransitionMaps = ImmutableMap.builder(); private Class universalFragment; @@ -325,11 +324,6 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { return this; } - public Builder setConfigurationCollectionFactory(ConfigurationCollectionFactory factory) { - this.configurationCollectionFactory = factory; - return this; - } - public Builder addDynamicTransitionMaps(Map maps) { dynamicTransitionMaps.putAll(maps); return this; @@ -443,7 +437,6 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { ImmutableList.copyOf(buildInfoFactories), ImmutableList.copyOf(configurationOptions), ImmutableList.copyOf(configurationFragmentFactories), - configurationCollectionFactory, new DynamicTransitionMapper(dynamicTransitionMaps.build()), universalFragment, prerequisiteValidator, @@ -547,11 +540,6 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { /** The set of configuration fragment factories. */ private final ImmutableList configurationFragmentFactories; - /** - * The factory that creates the configuration collection. - */ - private final ConfigurationCollectionFactory configurationCollectionFactory; - /** * The dynamic configuration transition mapper. */ @@ -582,7 +570,6 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { ImmutableList buildInfoFactories, ImmutableList> configurationOptions, ImmutableList configurationFragments, - ConfigurationCollectionFactory configurationCollectionFactory, DynamicTransitionMapper dynamicTransitionMapper, Class universalFragment, PrerequisiteValidator prerequisiteValidator, @@ -600,7 +587,6 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { this.buildInfoFactories = buildInfoFactories; this.configurationOptions = configurationOptions; this.configurationFragmentFactories = configurationFragments; - this.configurationCollectionFactory = configurationCollectionFactory; this.dynamicTransitionMapper = dynamicTransitionMapper; this.universalFragment = universalFragment; this.prerequisiteValidator = prerequisiteValidator; @@ -673,13 +659,6 @@ public class ConfiguredRuleClassProvider implements RuleClassProvider { return ruleDefinitionMap.get(ruleClassName); } - /** - * Returns the configuration collection creator. - */ - public ConfigurationCollectionFactory getConfigurationCollectionFactory() { - return configurationCollectionFactory; - } - /** * Returns the dynamic configuration transition mapper. */ diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java deleted file mode 100644 index d740102ac8..0000000000 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelConfigurationCollection.java +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2014 The Bazel Authors. 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.bazel.rules; - -import com.google.common.cache.Cache; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Table; -import com.google.devtools.build.lib.analysis.ConfigurationCollectionFactory; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection; -import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection.ConfigurationHolder; -import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection.Transitions; -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.events.EventHandler; -import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition; -import com.google.devtools.build.lib.packages.Attribute.SplitTransition; -import com.google.devtools.build.lib.packages.Attribute.Transition; -import com.google.devtools.build.lib.rules.cpp.CppRuleClasses.LipoTransition; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import javax.annotation.Nullable; - -/** - * Configuration collection used by the rules Bazel knows for statically configured builds. - * - *

Dynamically configured builds should never touch this file. - */ -public class BazelConfigurationCollection implements ConfigurationCollectionFactory { - @Override - @Nullable - public BuildConfiguration createConfigurations( - Cache cache, - PackageProviderForConfigurations packageProvider, - BuildOptions buildOptions, - EventHandler eventHandler, - String mainRepositoryName) - throws InvalidConfigurationException, InterruptedException { - // Target configuration - // Dead code: being removed. The original value used a class that's already been deleted. - BuildConfiguration targetConfiguration = null; - if (targetConfiguration == null) { - return null; - } - - BuildConfiguration dataConfiguration = targetConfiguration; - - // Host configuration - // Note that this passes in the dataConfiguration, not the target - // configuration. This is intentional. - BuildConfiguration hostConfiguration = getHostConfigurationFromRequest( - packageProvider, dataConfiguration, buildOptions, cache, mainRepositoryName); - if (hostConfiguration == null) { - return null; - } - - ListMultimap, BuildConfiguration> splitTransitionsTable = - ArrayListMultimap.create(); - for (SplitTransition transition : buildOptions.getPotentialSplitTransitions()) { - for (BuildOptions splitOptions : transition.split(buildOptions)) { - // Dead code: being removed. The original value used a class that's already been deleted. - BuildConfiguration splitConfig = null; - splitTransitionsTable.put(transition, splitConfig); - } - } - if (packageProvider.valuesMissing()) { - return null; - } - BuildConfiguration result = setupTransitions( - targetConfiguration, dataConfiguration, hostConfiguration, splitTransitionsTable); - result.reportInvalidOptions(eventHandler); - return result; - } - - private static class BazelTransitions extends BuildConfigurationCollection.Transitions { - public BazelTransitions(BuildConfiguration configuration, - Map transitionTable, - ListMultimap, BuildConfiguration> splitTransitionTable) { - super(configuration, transitionTable, splitTransitionTable); - } - - @Override - @Deprecated - public Transition getDynamicTransition(Transition configurationTransition) { - // Keep this interface for now because some other dead code is still calling it. - throw new UnsupportedOperationException( - "This interface is no longer supported and will be removed soon."); - } - } - - /** - * Gets the correct host configuration for this build. The behavior depends on the value of the - * --distinct_host_configuration flag. - * - *

With --distinct_host_configuration=false, we use identical configurations for the host and - * target, and you can ignore everything below. But please note: if you're cross-compiling for k8 - * on a piii machine, your build will fail. This is a stopgap measure. - * - *

Currently, every build is (in effect) a cross-compile, in the strict sense that host and - * target configurations are unequal, thus we do not issue a "cross-compiling" warning. (Perhaps - * we should?) * - * - * @param requestConfig the requested target (not host!) configuration for this build. - * @param buildOptions the configuration options used for the target configuration - */ - @Nullable - private static BuildConfiguration getHostConfigurationFromRequest( - PackageProviderForConfigurations loadedPackageProvider, - BuildConfiguration requestConfig, - BuildOptions buildOptions, - Cache cache, - String repositoryName) - throws InvalidConfigurationException, InterruptedException { - BuildConfiguration.Options commonOptions = buildOptions.get(BuildConfiguration.Options.class); - if (!commonOptions.useDistinctHostConfiguration) { - return requestConfig; - } else { - // Dead code: being removed. The original value used a class that's already been deleted. - BuildConfiguration hostConfig = null; - if (hostConfig == null) { - return null; - } - return hostConfig; - } - } - - static BuildConfiguration setupTransitions(BuildConfiguration targetConfiguration, - BuildConfiguration dataConfiguration, BuildConfiguration hostConfiguration, - ListMultimap, BuildConfiguration> splitTransitionsTable) { - Set allConfigurations = new LinkedHashSet<>(); - allConfigurations.add(targetConfiguration); - allConfigurations.add(dataConfiguration); - allConfigurations.add(hostConfiguration); - allConfigurations.addAll(splitTransitionsTable.values()); - - Table transitionBuilder = - HashBasedTable.create(); - for (BuildConfiguration from : allConfigurations) { - for (ConfigurationTransition transition : ConfigurationTransition.values()) { - BuildConfiguration to; - if (transition == ConfigurationTransition.HOST) { - to = hostConfiguration; - } else if (transition == ConfigurationTransition.DATA && from == targetConfiguration) { - to = dataConfiguration; - } else { - to = from; - } - transitionBuilder.put(from, transition, new ConfigurationHolder(to)); - } - } - - // TODO(bazel-team): This makes LIPO totally not work. Just a band-aid until we get around to - // implementing a way for the C++ rules to contribute this transition to the configuration - // collection. - for (BuildConfiguration config : allConfigurations) { - transitionBuilder.put(config, LipoTransition.LIPO_COLLECTOR, - new ConfigurationHolder(config)); - transitionBuilder.put(config, LipoTransition.TARGET_CONFIG_FOR_LIPO, - new ConfigurationHolder(config.isHostConfiguration() ? null : config)); - } - - for (BuildConfiguration config : allConfigurations) { - // We allow host configurations to be shared between target configurations. In that case, the - // transitions may already be set. - // TODO(bazel-team): Check that the transitions are identical, or even better, change the - // code to set the host configuration transitions before we even create the target - // configuration. - if (config.isHostConfiguration() && config.getTransitions() != null) { - continue; - } - boolean isSplitConfig = splitTransitionsTable.values().contains(config); - // When --experimental_multi_cpu is set, we create multiple target configurations that only - // differ by --cpu. We may therefore end up with multiple identical split configurations, if - // the split transition overwrites the cpu, which it usually does. - if (isSplitConfig && config.getTransitions() != null) { - continue; - } - Transitions outgoingTransitions = - new BazelTransitions( - config, - transitionBuilder.row(config), - // Split transitions must not have their own split transitions because then they - // would be applied twice due to a quirk in DependencyResolver. See the comment in - // DependencyResolver.resolveLateBoundAttributes(). - isSplitConfig - ? ImmutableListMultimap., BuildConfiguration>of() - : splitTransitionsTable); - config.setConfigurationTransitions(outgoingTransitions); - } - - return targetConfiguration; - } -} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 87de50cd52..520272edc4 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -209,7 +209,6 @@ public class BazelRuleClassProvider { public void init(Builder builder) { builder .setProductName("bazel") - .setConfigurationCollectionFactory(new BazelConfigurationCollection()) .setPrelude("//tools/build_rules:prelude_bazel") .setNativeLauncherLabel("//tools/launcher:launcher") .setRunfilesPrefix(Label.DEFAULT_REPOSITORY_DIRECTORY) diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationFunction.java index b6b6565dec..266b320fe7 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationFunction.java @@ -19,7 +19,6 @@ import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.MutableClassToInstanceMap; import com.google.devtools.build.lib.analysis.BlazeDirectories; -import com.google.devtools.build.lib.analysis.ConfigurationCollectionFactory; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; @@ -40,13 +39,11 @@ public class BuildConfigurationFunction implements SkyFunction { private final BlazeDirectories directories; private final ConfiguredRuleClassProvider ruleClassProvider; - private final ConfigurationCollectionFactory collectionFactory; public BuildConfigurationFunction(BlazeDirectories directories, RuleClassProvider ruleClassProvider) { this.directories = directories; this.ruleClassProvider = (ConfiguredRuleClassProvider) ruleClassProvider; - collectionFactory = this.ruleClassProvider.getConfigurationCollectionFactory(); } @Override -- cgit v1.2.3