diff options
author | 2015-07-31 22:08:32 +0000 | |
---|---|---|
committer | 2015-08-04 09:07:13 +0000 | |
commit | d75bf4da5748b251f09d73e0f977e35698e779df (patch) | |
tree | 210c8e824f87f28940580574900adf17354ba920 /src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java | |
parent | b8ab7b46c3871c453e7fb678d9537fc53c2460c2 (diff) |
Add test methods to check BuildConfiguration and ConfiguredTarget equality checking that are compatible with upcoming dynamic configurations (https://docs.google.com/document/d/1uoU8t7loTOu6uyzez-ilhcYgEXg4xjViJu0aqrf69TY/edit#heading=h.xsc8wmorka3u).
With today's configuration machinery, configuration equality means reference equality. With dynamic configurations, that won't necessarily be the case. This is primarily for two reasons:
1) Fragment-limited configurations means that a target's configuration only includes fragments needed by the target and its transitive closure. So if a java_library depends on a cc_library with the same configuration, the cc_library's instance won't contain the JavaConfiguration fragment.
2) The (upcoming) first pass of dynamic configurations uses old-style configurations for top-level targets, and dynamic configs for everything underneath. This can impact test calls that request a configured target both directly and as a dependency of another target. This distinction will eventually go away, but not yet.
Configurations that share the same options and fragments will continue to be reference-equal because of Skyframe caching.
--
MOS_MIGRATED_REVID=99610132
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java | 41 |
1 files changed, 41 insertions, 0 deletions
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 21251cf9a0..46f4e4daab 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 @@ -394,6 +394,47 @@ 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) { + 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 + * configurations that may no longer be true (for example, they may have the same values but not + * the same {@link BuildConfiguration.Fragment}s. So this method abstracts the + * "configuration equivalency" checking into one place, where the implementation logic can evolve + * as needed. + */ + protected void assertConfigurationsEqual(BuildConfiguration config1, BuildConfiguration config2) { + // BuildOptions and crosstool files determine a configuration's content. Within the context + // of these tests only the former actually change. + assertEquals(config1.cloneOptions(), config2.cloneOptions()); + } + + /** * Creates and returns a rule context that is equivalent to the one that was used to create the * given configured target. */ |