aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Cal Peyser <cpeyser@google.com>2017-03-24 15:44:24 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2017-03-27 11:35:07 +0000
commit8a638d58259b4251c52cd9561588573911db0c1f (patch)
tree9f39576aef91c2ade9b6ecd71691390c7203be02 /src/test/java/com
parent74e90608de56759247c12f0eabfdcf26b0cfd19f (diff)
Unit tests respect top-level rule-class transitions.
-- PiperOrigin-RevId: 151129669 MOS_MIGRATED_REVID=151129669
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java62
1 files changed, 32 insertions, 30 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 20e767b1b2..e8271372d2 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
@@ -677,7 +677,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
/**
* Returns the ConfiguredTarget for the specified label, configured for the "build" (aka "target")
- * configuration.
+ * configuration. If the label corresponds to a target with a top-level configuration transition,
+ * that transition is applied to the given config in the returned ConfiguredTarget.
*/
public ConfiguredTarget getConfiguredTarget(String label)
throws LabelSyntaxException {
@@ -685,8 +686,9 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
}
/**
- * Returns the ConfiguredTarget for the specified label, using the
- * given build configuration.
+ * Returns the ConfiguredTarget for the specified label, using the given build configuration. If
+ * the label corresponds to a target with a top-level configuration transition, that transition is
+ * applied to the given config in the returned ConfiguredTarget.
*/
protected ConfiguredTarget getConfiguredTarget(String label, BuildConfiguration config)
throws LabelSyntaxException {
@@ -695,7 +697,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
/**
* Returns the ConfiguredTarget for the specified label, using the
- * given build configuration.
+ * given build configuration. If the label corresponds to a target with a top-level configuration
+ * transition, that transition is applied to the given config in the returned ConfiguredTarget.
*
* <p>If the evaluation of the SkyKey corresponding to the configured target fails, this
* method may return null. In that case, use a debugger to inspect the {@link ErrorInfo}
@@ -704,8 +707,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
* {@link SkyframeExecutor#getConfiguredTargetForTesting}. See also b/26382502.
*/
protected ConfiguredTarget getConfiguredTarget(Label label, BuildConfiguration config) {
- return view.getConfiguredTargetForTesting(
- reporter, BlazeTestUtils.convertLabel(label), config);
+ return view.getConfiguredTargetForTesting(reporter, BlazeTestUtils.convertLabel(label), config);
}
/**
@@ -969,7 +971,11 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
* be "foo.o".
*/
protected Artifact getBinArtifact(String packageRelativePath, String owner) {
- return getBinArtifact(packageRelativePath, makeLabelAndConfiguration(owner));
+ ConfiguredTargetKey config = makeLabelAndConfiguration(owner);
+ return getPackageRelativeDerivedArtifact(
+ packageRelativePath,
+ config.getConfiguration().getBinDirectory(RepositoryName.MAIN),
+ config);
}
/**
@@ -1025,18 +1031,6 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
}
/**
- * Gets a derived Artifact for testing in the subdirectory of the {@link
- * BuildConfiguration#getBinDirectory} corresponding to the package of {@code owner}. So
- * to specify a file foo/foo.o owned by target //foo:foo, {@code packageRelativePath} should just
- * be "foo.o".
- */
- private Artifact getBinArtifact(String packageRelativePath, ArtifactOwner owner) {
- return getPackageRelativeDerivedArtifact(packageRelativePath,
- targetConfig.getBinDirectory(RepositoryName.MAIN),
- owner);
- }
-
- /**
* Gets a derived Artifact for testing in the {@link BuildConfiguration#getGenfilesDirectory}.
* This method should only be used for tests that do no analysis, and so there is no
* ConfiguredTarget to own this artifact. If the test runs the analysis phase, {@link
@@ -1055,7 +1049,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
* just be "foo.o".
*/
protected Artifact getGenfilesArtifact(String packageRelativePath, String owner) {
- return getGenfilesArtifact(packageRelativePath, makeLabelAndConfiguration(owner));
+ ConfiguredTargetKey configKey = makeLabelAndConfiguration(owner);
+ return getGenfilesArtifact(packageRelativePath, configKey, configKey.getConfiguration());
}
/**
@@ -1065,7 +1060,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
* just be "foo.o".
*/
protected Artifact getGenfilesArtifact(String packageRelativePath, ConfiguredTarget owner) {
- return getGenfilesArtifact(packageRelativePath, new ConfiguredTargetKey(owner));
+ ConfiguredTargetKey configKey = new ConfiguredTargetKey(owner);
+ return getGenfilesArtifact(packageRelativePath, configKey, configKey.getConfiguration());
}
/**
@@ -1114,14 +1110,14 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
/**
* Gets a derived Artifact for testing in the subdirectory of the {@link
- * BuildConfiguration#getGenfilesDirectory} corresponding to the package of {@code owner}.
- * So to specify a file foo/foo.o owned by target //foo:foo, {@code packageRelativePath} should
- * just be "foo.o".
+ * BuildConfiguration#getGenfilesDirectory} corresponding to the package of {@code owner}. So to
+ * specify a file foo/foo.o owned by target //foo:foo, {@code packageRelativePath} should just be
+ * "foo.o".
*/
- private Artifact getGenfilesArtifact(String packageRelativePath, ArtifactOwner owner) {
- return getPackageRelativeDerivedArtifact(packageRelativePath,
- targetConfig.getGenfilesDirectory(RepositoryName.MAIN),
- owner);
+ private Artifact getGenfilesArtifact(
+ String packageRelativePath, ArtifactOwner owner, BuildConfiguration config) {
+ return getPackageRelativeDerivedArtifact(
+ packageRelativePath, config.getGenfilesDirectory(RepositoryName.MAIN), owner);
}
/**
@@ -1246,11 +1242,17 @@ public abstract class BuildViewTestCase extends FoundationTestCase {
}
private ConfiguredTargetKey makeLabelAndConfiguration(String label) {
- BuildConfiguration config = targetConfig;
+ BuildConfiguration config;
+ try {
+ config = getConfiguredTarget(label).getConfiguration();
+ } catch (LabelSyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
if (targetConfig.useDynamicConfigurations()) {
try {
- config = view.getDynamicConfigurationForTesting(getTarget(label), targetConfig, reporter);
+ config = view.getDynamicConfigurationForTesting(getTarget(label), config, reporter);
} catch (Exception e) {
+ //TODO(b/36585204): Clean this up
throw new RuntimeException(e);
}
}