From db69c9fb66ab0b9979205585044a3b7f516a7b39 Mon Sep 17 00:00:00 2001 From: jcater Date: Thu, 28 Jan 2021 11:47:27 -0800 Subject: [PATCH] Refactor tests to not assume the target configuration. Future changes to Android rules will result in dependencies not being in the top-level target configuration, this change is to future-proof the tests. PiperOrigin-RevId: 354359631 --- .../lib/analysis/util/BuildViewTestCase.java | 5 +++++ .../lib/rules/android/AndroidBinaryTest.java | 20 +++++++++++++------ .../devtools/build/lib/rules/android/BUILD | 1 + 3 files changed, 20 insertions(+), 6 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 59172610654442..84d6e939a3ff37 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 @@ -1883,6 +1883,11 @@ private BuildConfiguration getConfiguration(String label) { return config; } + protected final BuildConfiguration getConfiguration( + BuildConfigurationValue.Key configurationKey) { + return skyframeExecutor.getConfiguration(reporter, configurationKey); + } + protected final BuildConfiguration getConfiguration(ConfiguredTarget ct) { return skyframeExecutor.getConfiguration(reporter, ct.getConfigurationKey()); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java index 0df719774fd8f7..b8caa2f681265a 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java @@ -44,6 +44,7 @@ import com.google.devtools.build.lib.analysis.RequiredConfigFragmentsProvider; import com.google.devtools.build.lib.analysis.actions.FileWriteAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.packages.BuildType; @@ -4474,15 +4475,22 @@ public void androidManifestMergerOrderAlphabetical_MergeesSortedByExecPath() thr " exports_manifest = 1,", " resource_files = ['theme/res/values/values.xml'],", ")"); - Artifact androidCoreManifest = getLibraryManifest(getConfiguredTarget("//java/android:core")); + ConfiguredTarget application = getConfiguredTarget("//java/binary:application"); + BuildConfiguration appConfiguration = getConfiguration(application); + Artifact androidCoreManifest = + getLibraryManifest(getConfiguredTarget("//java/android:core", appConfiguration)); Artifact androidUtilityManifest = - getLibraryManifest(getConfiguredTarget("//java/android:utility")); + getLibraryManifest(getConfiguredTarget("//java/android:utility", appConfiguration)); Artifact binaryLibraryManifest = - getLibraryManifest(getConfiguredTarget("//java/binary:library")); - Artifact commonManifest = getLibraryManifest(getConfiguredTarget("//java/common:common")); - Artifact commonThemeManifest = getLibraryManifest(getConfiguredTarget("//java/common:theme")); + getLibraryManifest(getConfiguredTarget("//java/binary:library", appConfiguration)); + Artifact commonManifest = + getLibraryManifest(getConfiguredTarget("//java/common:common", appConfiguration)); + Artifact commonThemeManifest = + getLibraryManifest(getConfiguredTarget("//java/common:theme", appConfiguration)); - assertThat(getBinaryMergeeManifests(getConfiguredTarget("//java/binary:application"))) + assertThat( + getBinaryMergeeManifests( + getConfiguredTarget("//java/binary:application", appConfiguration))) .containsExactlyEntriesIn( ImmutableMap.of( androidCoreManifest.getExecPath().toString(), "//java/android:core", diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD index fd1115a9c85179..db78a329d71478 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD @@ -113,6 +113,7 @@ java_test( "//src/main/java/com/google/devtools/build/lib/actions", "//src/main/java/com/google/devtools/build/lib/actions:artifacts", "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster", + "//src/main/java/com/google/devtools/build/lib/analysis:config/build_configuration", "//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:required_config_fragments_provider",