diff options
author | 2017-09-14 00:47:27 +0200 | |
---|---|---|
committer | 2017-09-14 18:47:05 +0200 | |
commit | 408bfe47a4c692d06d68192dd460a37367ce8245 (patch) | |
tree | 922654640d390402c480878d6f755da5dc0b756c | |
parent | da362c2b3f6ddfd502c9eb5c7896aa528a625db9 (diff) |
Lots more cleanup of "dynamic configurations" comments and test code.
PiperOrigin-RevId: 168607439
15 files changed, 116 insertions, 201 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java index de5f998a8f..57ba8e0e14 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java @@ -888,7 +888,7 @@ public class BuildView { nodes.add(new TargetAndConfiguration(target, target.isConfigurable() ? config : null)); } } - return ImmutableList.copyOf(getDynamicConfigurations(nodes, eventHandler)); + return ImmutableList.copyOf(getConfigurations(nodes, eventHandler)); } /** @@ -908,7 +908,7 @@ public class BuildView { */ // TODO(bazel-team): error out early for targets that fail - untrimmed configurations should // never make it through analysis (and especially not seed ConfiguredTargetValues) - private LinkedHashSet<TargetAndConfiguration> getDynamicConfigurations( + private LinkedHashSet<TargetAndConfiguration> getConfigurations( Iterable<TargetAndConfiguration> inputs, ExtendedEventHandler eventHandler) throws InterruptedException { Map<Label, Target> labelsToTargets = new LinkedHashMap<>(); @@ -931,7 +931,7 @@ public class BuildView { } } - // Maps <target, originalConfig> pairs to <target, dynamicConfig> pairs for targets that + // Maps <target, originalConfig> pairs to <target, finalConfig> pairs for targets that // could be successfully Skyframe-evaluated. Map<TargetAndConfiguration, TargetAndConfiguration> successfullyEvaluatedTargets = new LinkedHashMap<>(); @@ -1003,17 +1003,17 @@ public class BuildView { /** - * Gets a dynamic configuration for the given target. + * Gets a configuration for the given target. * * <p>If {@link BuildConfiguration.Options#trimConfigurations()} is true, the configuration only * includes the fragments needed by the fragment and its transitive closure. Else unconditionally * includes all fragments. */ @VisibleForTesting - public BuildConfiguration getDynamicConfigurationForTesting( + public BuildConfiguration getConfigurationForTesting( Target target, BuildConfiguration config, ExtendedEventHandler eventHandler) throws InterruptedException { - return Iterables.getOnlyElement(getDynamicConfigurations( + return Iterables.getOnlyElement(getConfigurations( ImmutableList.<TargetAndConfiguration>of(new TargetAndConfiguration(target, config)), eventHandler)).getConfiguration(); } @@ -1217,10 +1217,11 @@ public class BuildView { } /** - * Returns a configured target for the specified target and configuration. If dynamic - * configurations are activated, and the target in question has a top-level rule class transition, - * that transition is applied in the returned ConfiguredTarget. Returns {@code null} if something - * goes wrong. + * Returns a configured target for the specified target and configuration. If the target in + * question has a top-level rule class transition, that transition is applied in the returned + * ConfiguredTarget. + * + * <p>Returns {@code null} if something goes wrong. */ @VisibleForTesting public ConfiguredTarget getConfiguredTargetForTesting( 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 c865a0dbc3..9774cb7a56 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 @@ -957,33 +957,32 @@ public final class BuildConfiguration implements BuildEvent { /** * Values for --experimental_dynamic_configs. */ - public enum DynamicConfigsMode { - /** Use dynamic configurations, including only the fragments each rule needs. */ + public enum ConfigsMode { + /** Only include the configuration fragments each rule needs. */ ON, - /** Use dynamic configurations, always including all fragments known to Blaze. */ + /** Always including all fragments known to Blaze. */ NOTRIM, } /** * Converter for --experimental_dynamic_configs. */ - public static class DynamicConfigsConverter extends EnumConverter<DynamicConfigsMode> { - public DynamicConfigsConverter() { - super(DynamicConfigsMode.class, "dynamic configurations mode"); + public static class ConfigsModeConverter extends EnumConverter<ConfigsMode> { + public ConfigsModeConverter() { + super(ConfigsMode.class, "configurations mode"); } } @Option( name = "experimental_dynamic_configs", defaultValue = "notrim", - converter = DynamicConfigsConverter.class, + converter = ConfigsModeConverter.class, documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.UNKNOWN}, help = - "Dynamically instantiates build configurations instead of using the default " - + "static globally defined ones" + "Instantiates build configurations with the specified properties" ) - public DynamicConfigsMode useDynamicConfigurations; + public ConfigsMode configsMode; @Option( name = "experimental_enable_runfiles", @@ -1021,7 +1020,7 @@ public final class BuildConfiguration implements BuildEvent { host.outputDirectoryName = "host"; host.compilationMode = CompilationMode.OPT; host.isHost = true; - host.useDynamicConfigurations = useDynamicConfigurations; + host.configsMode = configsMode; host.enableRunfiles = enableRunfiles; host.buildPythonZip = buildPythonZip; host.windowsExeLauncher = windowsExeLauncher; @@ -1209,9 +1208,9 @@ public final class BuildConfiguration implements BuildEvent { * Returns true if this configuration is semantically equal to the other, with * the possible exception that the other has fewer fragments. * - * <p>This is useful for dynamic configurations - as the same configuration gets "trimmed" while - * going down a dependency chain, it's still the same configuration but loses some of its - * fragments. So we need a more nuanced concept of "equality" than simple reference equality. + * <p>This is useful for trimming: as the same configuration gets "trimmed" while going down a + * dependency chain, it's still the same configuration but loses some of its fragments. So we need + * a more nuanced concept of "equality" than simple reference equality. */ public boolean equalsOrIsSupersetOf(BuildConfiguration other) { return this.equals(other) @@ -1354,9 +1353,6 @@ public final class BuildConfiguration implements BuildEvent { /** * Constructs a new BuildConfiguration instance. - * - * <p>Callers that pass null for {@code dynamicTransitionMapper} should not use dynamic - * configurations. */ public BuildConfiguration(BlazeDirectories directories, Map<Class<? extends Fragment>, Fragment> fragmentsMap, @@ -1975,11 +1971,11 @@ public final class BuildConfiguration implements BuildEvent { } /** - * Returns whether we should trim dynamic configurations to only include the fragments needed - * to correctly analyze a rule. + * Returns whether we should trim configurations to only include the fragments needed to correctly + * analyze a rule. */ public boolean trimConfigurations() { - return options.useDynamicConfigurations == Options.DynamicConfigsMode.ON; + return options.configsMode == Options.ConfigsMode.ON; } /** @@ -2006,9 +2002,9 @@ public final class BuildConfiguration implements BuildEvent { * <p><b>Be very careful using this method.</b> Options classes are mutable - no caller * should ever call this method if there's any change the reference might be written to. * This method only exists because {@link #cloneOptions} can be expensive when applied to - * every edge in a dependency graph, which becomes possible with dynamic configurations. + * every edge in a dependency graph. * - * <p>Do not use this method without careful review with other Bazel developers.. + * <p>Do not use this method without careful review with other Bazel developers. */ public BuildOptions getOptions() { return buildOptions; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationCollection.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationCollection.java index b8b03b6930..1780b1e4c5 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationCollection.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationCollection.java @@ -59,10 +59,9 @@ public final class BuildConfigurationCollection { /** * Returns the host configuration for this collection. * - * <p>Don't use this method. It's limited in that it assumes a single host configuration for - * the entire collection. This may not be true in the future and more flexible interfaces based - * on dynamic configurations will likely supplant this interface anyway. Its main utility is - * to keep Bazel working while dynamic configuration progress is under way. + * <p>Don't use this method. It's limited in that it assumes a single host configuration for the + * entire collection. This may not be true in the future and more flexible interfaces will likely + * supplant this interface anyway. */ public BuildConfiguration getHostConfiguration() { return hostConfiguration; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/PatchTransition.java b/src/main/java/com/google/devtools/build/lib/analysis/config/PatchTransition.java index 33362b1dac..80091e05b9 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/PatchTransition.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/PatchTransition.java @@ -16,7 +16,7 @@ package com.google.devtools.build.lib.analysis.config; import com.google.devtools.build.lib.packages.Attribute; /** - * Interface for a configuration transition using dynamic configurations. + * Interface for a configuration transition. * * <p>The concept is simple: given the input configuration's build options, the * transition does whatever it wants to them and returns the modified result. diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index 663312d433..390aa32254 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -102,16 +102,9 @@ public class CppRuleClasses { /** * Rule transition factory that enables LIPO on the LIPO context binary (i.e. applies a DATA -> * TARGET transition). - * - * <p>This is how dynamic configurations enable LIPO on the LIPO context. */ public static final RuleTransitionFactory LIPO_ON_DEMAND = - new RuleTransitionFactory() { - @Override - public Attribute.Transition buildTransitionFor(Rule rule) { - return new EnableLipoTransition(rule.getLabel()); - } - }; + (rule) -> new EnableLipoTransition(rule.getLabel()); /** * Label of a pseudo-filegroup that contains all crosstool and libcfiles for all configurations, diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetCycleReporter.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetCycleReporter.java index 4e0b959674..9cd2302ee5 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetCycleReporter.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetCycleReporter.java @@ -58,15 +58,9 @@ class ConfiguredTargetCycleReporter extends AbstractLabelCycleReporter { return false; } Iterable<SkyKey> cycleKeys = Iterables.concat(cycleInfo.getPathToCycle(), cycleInfo.getCycle()); - // Static configurations expect all keys to be ConfiguredTargetValue keys. Dynamic - // configurations expect the top-level key to be a ConfiguredTargetValue key, but cycles and - // paths to them can travel through TransitiveTargetValue keys because ConfiguredTargetFunction + // The top-level key should be a ConfiguredTargetValue key, but cycles and paths to it can + // travel through TransitiveTargetValue keys because ConfiguredTargetFunction visits // visits TransitiveTargetFunction as a part of dynamic configuration computation. - // - // Unfortunately this class can't easily figure out if we're in static or dynamic configuration - // mode, so we loosely permit both cases. - // - // TODO: remove the static-style checking once dynamic configurations fully replace them return Iterables.all(cycleKeys, Predicates.<SkyKey>or(IS_CONFIGURED_TARGET_SKY_KEY, IS_TRANSITIVE_TARGET_SKY_KEY)); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index ba926d5fbc..53fe489816 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java @@ -1406,9 +1406,8 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { ArrayListMultimap.<Dependency, BuildConfiguration>create(); Set<Dependency> depsToEvaluate = new HashSet<>(); - // Check: if !Configuration.useDynamicConfigs then just return the original configs. Set<Class<? extends BuildConfiguration.Fragment>> allFragments = null; - if (useUntrimmedDynamicConfigs(fromOptions)) { + if (useUntrimmedConfigs(fromOptions)) { allFragments = ((ConfiguredRuleClassProvider) ruleClassProvider).getAllFragments(); } @@ -1419,7 +1418,7 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { for (Dependency key : keys) { if (key.hasExplicitConfiguration()) { builder.put(key, key.getConfiguration()); - } else if (useUntrimmedDynamicConfigs(fromOptions)) { + } else if (useUntrimmedConfigs(fromOptions)) { fragmentsMap.put(key.getLabel(), allFragments); } else { depsToEvaluate.add(key); @@ -1484,12 +1483,12 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { } /** - * Returns whether dynamic configurations should trim their fragments to only those needed by + * Returns whether configurations should trim their fragments to only those needed by * targets and their transitive dependencies. */ - private static boolean useUntrimmedDynamicConfigs(BuildOptions options) { - return options.get(BuildConfiguration.Options.class).useDynamicConfigurations - == BuildConfiguration.Options.DynamicConfigsMode.NOTRIM; + private static boolean useUntrimmedConfigs(BuildOptions options) { + return options.get(BuildConfiguration.Options.class).configsMode + == BuildConfiguration.Options.ConfigsMode.NOTRIM; } /** diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java index 00130f8282..1a7e353385 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java @@ -34,7 +34,7 @@ import com.google.devtools.build.lib.analysis.BuildView.AnalysisResult; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.analysis.util.BuildViewTestBase; -import com.google.devtools.build.lib.analysis.util.ExpectedDynamicConfigurationErrors; +import com.google.devtools.build.lib.analysis.util.ExpectedTrimmedConfigurationErrors; import com.google.devtools.build.lib.analysis.util.MockRule; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.Attribute; @@ -527,10 +527,9 @@ public class BuildViewTest extends BuildViewTestBase { assertContainsEvent("and referenced by '//foo:bad'"); assertContainsEvent("in sh_library rule //foo"); assertContainsEvent("cycle in dependency graph"); - // Dynamic configurations trigger this error both in configuration trimming (which visits - // the transitive target closure) and in the normal configured target cycle detection path. - // So we get an additional instance of this check (which varies depending on whether Skyframe - // loading phase is enabled). + // This error is triggered both in configuration trimming (which visits the transitive target + // closure) and in the normal configured target cycle detection path. So we get an additional + // instance of this check (which varies depending on whether Skyframe loading phase is enabled). // TODO(gregce): Fix above and uncomment the below. Note that the duplicate doesn't make it into // real user output (it only affects tests). // assertEventCount(3, eventCollector); @@ -924,10 +923,9 @@ public class BuildViewTest extends BuildViewTestBase { @Test public void testCycleDueToJavaLauncherConfiguration() throws Exception { - if (defaultFlags().contains(Flag.DYNAMIC_CONFIGURATIONS)) { - // Dynamic configurations don't yet support late-bound attributes. Development testing already - // runs all tests with dynamic configurations enabled, so this will still fail for developers - // and won't get lost in the fog. + if (defaultFlags().contains(Flag.TRIMMED_CONFIGURATIONS)) { + // Trimmed configurations don't yet support late-bound attributes. + // TODO(gregce): re-enable this when ready. return; } scratch.file("foo/BUILD", @@ -936,7 +934,7 @@ public class BuildViewTest extends BuildViewTestBase { // Everything is fine - the dependency graph is acyclic. update("//foo:java", "//foo:cpp"); if (getTargetConfiguration().trimConfigurations()) { - fail(ExpectedDynamicConfigurationErrors.LATE_BOUND_ATTRIBUTES_UNSUPPORTED); + fail(ExpectedTrimmedConfigurationErrors.LATE_BOUND_ATTRIBUTES_UNSUPPORTED); } // Now there will be an analysis-phase cycle because the java_binary now has an implicit dep on // the cc_binary launcher. @@ -1231,7 +1229,7 @@ public class BuildViewTest extends BuildViewTestBase { } @Test - public void testTopLevelTargetsAreTrimmedWithDynamicConfigurations() throws Exception { + public void testTopLevelTargetsAreTrimmedWithTrimmedConfigurations() throws Exception { scratch.file("foo/BUILD", "sh_library(name='x', ", " srcs=['x.sh'])"); @@ -1389,13 +1387,13 @@ public class BuildViewTest extends BuildViewTestBase { } } - /** Runs the same test with dynamic configurations. */ + /** Runs the same test with trimmed configurations. */ @TestSpec(size = Suite.SMALL_TESTS) @RunWith(JUnit4.class) - public static class WithDynamicConfigurations extends BuildViewTest { + public static class WithTrimmedConfigurations extends BuildViewTest { @Override protected FlagBuilder defaultFlags() { - return super.defaultFlags().with(Flag.DYNAMIC_CONFIGURATIONS); + return super.defaultFlags().with(Flag.TRIMMED_CONFIGURATIONS); } } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java b/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java index af37c8b78f..11e04e9537 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java @@ -205,23 +205,13 @@ public class DependencyResolverTest extends AnalysisTestCase { assertThat(dep.getConfiguration()).isNull(); } - /** Runs the same test with trimmed dynamic configurations. */ + /** Runs the same test with trimmed configurations. */ @TestSpec(size = Suite.SMALL_TESTS) @RunWith(JUnit4.class) - public static class WithDynamicConfigurations extends DependencyResolverTest { + public static class WithTrimmedConfigurations extends DependencyResolverTest { @Override protected FlagBuilder defaultFlags() { - return super.defaultFlags().with(Flag.DYNAMIC_CONFIGURATIONS); - } - } - - /** Runs the same test with untrimmed dynamic configurations. */ - @TestSpec(size = Suite.SMALL_TESTS) - @RunWith(JUnit4.class) - public static class WithDynamicConfigurationsNoTrim extends DependencyResolverTest { - @Override - protected FlagBuilder defaultFlags() { - return super.defaultFlags().with(Flag.DYNAMIC_CONFIGURATIONS_NOTRIM); + return super.defaultFlags().with(Flag.TRIMMED_CONFIGURATIONS); } } } 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 2235d0bb8b..0cdc4a3975 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 @@ -96,10 +96,8 @@ public abstract class AnalysisTestCase extends FoundationTestCase { public enum Flag { KEEP_GOING, SKYFRAME_LOADING_PHASE, - // Dynamic configurations that only include the fragments a target needs to properly analyze. - DYNAMIC_CONFIGURATIONS, - // Dynamic configurations that always include all fragments even when targets don't need them. - DYNAMIC_CONFIGURATIONS_NOTRIM + // Configurations that only include the fragments a target needs to properly analyze. + TRIMMED_CONFIGURATIONS } /** Helper class to make it easy to enable and disable flags. */ @@ -227,10 +225,8 @@ public abstract class AnalysisTestCase extends FoundationTestCase { ruleClassProvider.getConfigurationOptions())); optionsParser.parse(new String[] {"--default_visibility=public" }); optionsParser.parse(args); - if (defaultFlags().contains(Flag.DYNAMIC_CONFIGURATIONS)) { + if (defaultFlags().contains(Flag.TRIMMED_CONFIGURATIONS)) { optionsParser.parse("--experimental_dynamic_configs=on"); - } else if (defaultFlags().contains(Flag.DYNAMIC_CONFIGURATIONS_NOTRIM)) { - optionsParser.parse("--experimental_dynamic_configs=notrim"); } InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer(); @@ -264,30 +260,10 @@ public abstract class AnalysisTestCase extends FoundationTestCase { /** * Returns the target configuration for the most recent build, as created in Blaze's - * master configuration creation phase. Most significantly, this is never a dynamic - * configuration. + * master configuration creation phase. */ protected BuildConfiguration getTargetConfiguration() throws InterruptedException { - return getTargetConfiguration(false); - } - - /** - * Returns the target configuration for the most recent build. If useDynamicVersionIfEnabled is - * true and dynamic configurations are enabled, returns the dynamic version. Else returns the - * static version. - */ - // TODO(gregce): force getTargetConfiguration() to getTargetConfiguration(true) once we know - // all callers can handle the dynamic version - protected BuildConfiguration getTargetConfiguration(boolean useDynamicVersionIfEnabled) - throws InterruptedException { - BuildConfiguration targetConfig = - Iterables.getOnlyElement(masterConfig.getTargetConfigurations()); - if (useDynamicVersionIfEnabled) { - return skyframeExecutor.getConfigurationForTesting( - reporter, targetConfig.fragmentClasses(), targetConfig.getOptions()); - } else { - return targetConfig; - } + return Iterables.getOnlyElement(masterConfig.getTargetConfigurations()); } protected BuildConfiguration getHostConfiguration() { 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 7c9fea4311..3d0b1d2317 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 @@ -75,7 +75,7 @@ import com.google.devtools.build.lib.analysis.actions.SymlinkTreeAction; import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoKey; import com.google.devtools.build.lib.analysis.config.BinTools; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Options.DynamicConfigsMode; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Options.ConfigsMode; import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.PatchTransition; @@ -182,7 +182,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { protected BuildConfigurationCollection masterConfig; protected BuildConfiguration targetConfig; // "target" or "build" config private List<String> configurationArgs; - private DynamicConfigsMode dynamicConfigsMode = DynamicConfigsMode.NOTRIM; + private ConfigsMode configsMode = ConfigsMode.NOTRIM; protected OptionsParser optionsParser; private PackageCacheOptions packageCacheOptions; @@ -414,12 +414,12 @@ public abstract class BuildViewTestCase extends FoundationTestCase { ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); if (alsoConfigs) { try { - // Also invalidate all configurations. This is important for dynamic configurations: by - // invalidating all files we invalidate CROSSTOOL, which invalidates CppConfiguration (and - // a few other fragments). So we need to invalidate the - // {@link SkyframeBuildView#hostConfigurationCache} as well. Otherwise we end up - // with old CppConfiguration instances. Even though they're logically equal to the new ones, - // CppConfiguration has no .equals() method and some production code expects equality. + // Also invalidate all configurations. This is important: by invalidating all files we + // invalidate CROSSTOOL, which invalidates CppConfiguration (and a few other fragments). So + // we need to invalidate the {@link SkyframeBuildView#hostConfigurationCache} as well. + // Otherwise we end up with old CppConfiguration instances. Even though they're logically + // equal to the new ones, CppConfiguration has no .equals() method and some production code + // expects equality. useConfiguration(configurationArgs.toArray(new String[0])); } catch (Exception e) { // There are enough dependers on this method that don't handle Exception that just passing @@ -441,7 +441,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { String[] actualArgs; actualArgs = Arrays.copyOf(args, args.length + 1); actualArgs[args.length] = "--experimental_dynamic_configs=" - + dynamicConfigsMode.toString().toLowerCase(); + + configsMode.toString().toLowerCase(); masterConfig = createConfigurations(actualArgs); targetConfig = getTargetConfiguration(); configurationArgs = Arrays.asList(actualArgs); @@ -449,11 +449,11 @@ public abstract class BuildViewTestCase extends FoundationTestCase { } /** - * Makes subsequent {@link #useConfiguration} calls automatically enable dynamic configurations - * in the specified mode. + * Makes subsequent {@link #useConfiguration} calls automatically use the specified style for + * configurations. */ - protected final void useDynamicConfigurations(DynamicConfigsMode mode) { - dynamicConfigsMode = mode; + protected final void useConfigurationMode(ConfigsMode mode) { + configsMode = mode; } /** @@ -510,33 +510,6 @@ public abstract class BuildViewTestCase extends FoundationTestCase { } /** - * Asserts that a target's prerequisites contain the given dependency. - */ - // TODO(bazel-team): replace this method with assertThat(iterable).contains(target). - // That doesn't work now because dynamic configurations aren't yet applied to top-level targets. - // This means that getConfiguredTarget("//go:two") returns a different configuration than - // requesting "//go:two" as a dependency. So the configured targets aren't considered "equal". - // Once we apply dynamic configs to top-level targets this discrepancy will go away. - protected void assertDirectPrerequisitesContain(ConfiguredTarget target, ConfiguredTarget dep) - throws Exception { - Iterable<ConfiguredTarget> prereqs = getDirectPrerequisites(target); - BuildConfiguration depConfig = dep.getConfiguration(); - for (ConfiguredTarget contained : prereqs) { - if (contained.getLabel().equals(dep.getLabel())) { - BuildConfiguration containedConfig = contained.getConfiguration(); - if (containedConfig == null && depConfig == null) { - return; - } else if (containedConfig != null - && depConfig != null - && containedConfig.cloneOptions().equals(depConfig.cloneOptions())) { - return; - } - } - } - fail("Cannot find " + target.toString() + " in " + prereqs.toString()); - } - - /** * Asserts that two configurations are the same. * * <p>Historically this meant they contained the same object reference. But with upcoming dynamic @@ -1154,12 +1127,12 @@ public abstract class BuildViewTestCase extends FoundationTestCase { } /** - * Strips the C++-contributed prefix out of an output path when tests are run with dynamic + * Strips the C++-contributed prefix out of an output path when tests are run with trimmed * configurations. e.g. turns "bazel-out/gcc-X-glibc-Y-k8-fastbuild/ to "bazel-out/fastbuild/". * * <p>This should be used for targets use configurations with C++ fragments. */ - protected String stripCppPrefixForDynamicConfigs(String outputPath) { + protected String stripCppPrefixForTrimmedConfigs(String outputPath) { return targetConfig.trimConfigurations() ? AnalysisTestUtil.OUTPUT_PATH_CPP_PREFIX_PATTERN.matcher(outputPath).replaceFirst("") : outputPath; @@ -1302,7 +1275,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { BuildConfiguration config; try { config = getConfiguredTarget(label).getConfiguration(); - config = view.getDynamicConfigurationForTesting(getTarget(label), config, reporter); + config = view.getConfigurationForTesting(getTarget(label), config, reporter); } catch (LabelSyntaxException e) { throw new IllegalArgumentException(e); } catch (Exception e) { @@ -1497,8 +1470,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { } /** - * Returns the configuration created by applying the given transition to the source - * configuration. Works for both static and dynamic configuration tests. + * Returns the configuration created by applying the given transition to the source configuration. */ protected BuildConfiguration getConfiguration(BuildConfiguration fromConfig, Attribute.Transition transition) throws InterruptedException { diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/ExpectedDynamicConfigurationErrors.java b/src/test/java/com/google/devtools/build/lib/analysis/util/ExpectedTrimmedConfigurationErrors.java index fb9fecf174..ca1c0bb5e6 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/ExpectedDynamicConfigurationErrors.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/ExpectedTrimmedConfigurationErrors.java @@ -14,12 +14,16 @@ package com.google.devtools.build.lib.analysis.util; /** - * Reference point for expected test failures when dynamic configurations are enabled. + * Reference point for expected test failures when trimmed configurations are enabled. * - * <p>Every Bazel test should either succeed with --experimental_dynamic_configs or + * <p>Every Bazel test should either succeed with --experimental_dynamic_configs=on or * fail with a clear reason due to known features gaps. */ -public class ExpectedDynamicConfigurationErrors { +public class ExpectedTrimmedConfigurationErrors { public static final String LATE_BOUND_ATTRIBUTES_UNSUPPORTED = - "dynamic configurations don't yet support fragments from late-bound dependencies"; + "trimmed configurations don't yet support fragments from late-bound dependencies"; + + public static final String MAKE_VARIABLE_FRAGMENTS_UNSUPPORTED = + "Trimmed configurations don't yet support fragments required by make variables. See " + + "b/25768144"; } diff --git a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java index fbe81326ea..a856424046 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java @@ -37,7 +37,7 @@ import org.junit.runners.JUnit4; public final class ConfigFeatureFlagTest extends SkylarkTestCase { @Before - public void useDynamicConfigurations() throws Exception { + public void useTrimmedConfigurations() throws Exception { useConfiguration("--experimental_dynamic_configs=on"); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java index 10ad309133..edba22433d 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java @@ -290,39 +290,32 @@ public class ConfigurationsForTargetsTest extends AnalysisTestCase { assertThat(toolDep.getConfiguration().isHostConfiguration()).isTrue(); } - /** Runs the same test with untrimmed dynamic configurations. */ - @TestSpec(size = Suite.SMALL_TESTS) - @RunWith(JUnit4.class) - public static class WithDynamicConfigurationsNoTrim extends ConfigurationsForTargetsTest { - @Override - protected FlagBuilder defaultFlags() { - return super.defaultFlags().with(Flag.DYNAMIC_CONFIGURATIONS_NOTRIM); - } - + @Test + public void splitDeps() throws Exception { // This test does not pass with trimming because android_binary applies an aspect and aspects // are not yet correctly supported with trimming. - @Test - public void splitDeps() throws Exception { - scratch.file( - "java/a/BUILD", - "cc_library(name = 'lib', srcs = ['lib.cc'])", - "android_binary(name='a', manifest = 'AndroidManifest.xml', deps = [':lib'])"); - useConfiguration("--fat_apk_cpu=k8,armeabi-v7a"); - List<ConfiguredTarget> deps = getConfiguredDeps("//java/a:a", "deps"); - assertThat(deps).hasSize(2); - ConfiguredTarget dep1 = deps.get(0); - ConfiguredTarget dep2 = deps.get(1); - assertThat( - ImmutableList.<String>of( - dep1.getConfiguration().getCpu(), - dep2.getConfiguration().getCpu())) - .containsExactly("armeabi-v7a", "k8"); - // We don't care what order split deps are listed, but it must be deterministic. - assertThat( - ConfiguredTargetFunction.DYNAMIC_SPLIT_DEP_ORDERING.compare( - Dependency.withConfiguration(dep1.getLabel(), dep1.getConfiguration()), - Dependency.withConfiguration(dep2.getLabel(), dep2.getConfiguration()))) - .isLessThan(0); + if (defaultFlags().contains(Flag.TRIMMED_CONFIGURATIONS)) { + return; } + scratch.file( + "java/a/BUILD", + "cc_library(name = 'lib', srcs = ['lib.cc'])", + "android_binary(name='a', manifest = 'AndroidManifest.xml', deps = [':lib'])"); + useConfiguration("--fat_apk_cpu=k8,armeabi-v7a"); + List<ConfiguredTarget> deps = getConfiguredDeps("//java/a:a", "deps"); + assertThat(deps).hasSize(2); + ConfiguredTarget dep1 = deps.get(0); + ConfiguredTarget dep2 = deps.get(1); + assertThat( + ImmutableList.<String>of( + dep1.getConfiguration().getCpu(), + dep2.getConfiguration().getCpu())) + .containsExactly("armeabi-v7a", "k8"); + // We don't care what order split deps are listed, but it must be deterministic. + assertThat( + ConfiguredTargetFunction.DYNAMIC_SPLIT_DEP_ORDERING.compare( + Dependency.withConfiguration(dep1.getLabel(), dep1.getConfiguration()), + Dependency.withConfiguration(dep2.getLabel(), dep2.getConfiguration()))) + .isLessThan(0); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithDynamicConfigurationsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithTrimmedConfigurationsTest.java index 54d8e55d02..d398c10427 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithDynamicConfigurationsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsWithTrimmedConfigurationsTest.java @@ -52,10 +52,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Runs an expanded set of ConfigurationsForTargetsTest with trimmed dynamic configurations. */ +/** Runs an expanded set of ConfigurationsForTargetsTest with trimmed configurations. */ @TestSpec(size = Suite.SMALL_TESTS) @RunWith(JUnit4.class) -public class ConfigurationsForTargetsWithDynamicConfigurationsTest +public class ConfigurationsForTargetsWithTrimmedConfigurationsTest extends ConfigurationsForTargetsTest { private ConfigurationResolver configResolver; @@ -67,7 +67,7 @@ public class ConfigurationsForTargetsWithDynamicConfigurationsTest @Override protected FlagBuilder defaultFlags() { - return super.defaultFlags().with(Flag.DYNAMIC_CONFIGURATIONS); + return super.defaultFlags().with(Flag.TRIMMED_CONFIGURATIONS); } private static class EmptySplitTransition implements SplitTransition<BuildOptions> { @@ -430,7 +430,7 @@ public class ConfigurationsForTargetsWithDynamicConfigurationsTest ConfiguredTarget target = getView().getConfiguredTargetForTesting( reporter, Label.parseAbsoluteUnchecked("@//a:factory"), - getTargetConfiguration(true)); + getTargetConfiguration()); assertThat(target.getConfiguration().getFragment(TestConfiguration.class).getTestFilter()) .isEqualTo("SET ON COMMAND LINE: original and best"); } |