Skip to content
Permalink
Browse files

Automated rollback of commit 5d0dde0.

*** Reason for rollback ***

Rollforward to default Bazel to use aapt2, and fix native tests to use aapt2.

Fixes to Windows build failures have rolled out:

fcfe560
unknown commit
unknown commit
unknown commit (Windows test coverage)

*** Original change description ***

Automated rollback of commit b98ad77.

*** Reason for rollback ***

Broke Android build on Windows
#9102

*** Original change description ***

Default Bazel to use aapt2 and fix native tests to use aapt2.

This CL sets --incompatible_use_aapt2_by_default=true and --android_aapt=aapt2. It also adds aapt2 to the mock SDK for Android analysis and integration tests.

For the tests that assume and depend on AAPT, we explicitly pin them to use AAPT....

***

RELNOTES:
PiperOrigin-RevId: 262672156
  • Loading branch information...
jin authored and Copybara-Service committed Aug 10, 2019
1 parent 4e44b35 commit c6022ee3d82c70cf233919b1ced4dcaa81e043c9
@@ -708,7 +708,7 @@ public static AndroidAaptVersion chooseTargetAaptVersion(

@Option(
name = "android_aapt",
defaultValue = "auto",
defaultValue = "aapt2",
documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
effectTags = {
OptionEffectTag.AFFECTS_OUTPUTS,
@@ -968,7 +968,7 @@ public static AndroidAaptVersion chooseTargetAaptVersion(
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
defaultValue = "false",
defaultValue = "true",
help =
"Switch the Android rules to use aapt2 by default for resource processing. "
+ "To resolve issues when migrating your app to build with aapt2, see "
@@ -856,6 +856,9 @@ Do PNG crunching (or not). This is independent of nine-patch processing, which i
.add(attr("manifest_values", STRING_DICT))
/* <!-- #BLAZE_RULE(android_binary).ATTRIBUTE(aapt_version) -->
Select the version of aapt for this rule.<br/>
This attribute only takes effect if you set `--android_aapt=auto`.<br/>
Possible values:
<ul>
<li><code>aapt_version = "aapt"</code>: Use aapt (deprecated).</li>
@@ -348,6 +348,7 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
"android_sdk(",
" name = 'sdk',",
" aapt = ':static_aapt_tool',",
" aapt2 = ':static_aapt2_tool',",
" adb = ':static_adb_tool',",
" aidl = ':static_aidl_tool',",
" android_jar = ':android_runtime_jar',",
@@ -57,9 +57,6 @@ public void testParse() throws Exception {

@Test
public void testParseAapt2() throws Exception {
mockAndroidSdkWithAapt2();
useConfiguration("--android_sdk=//sdk:sdk");

RuleContext ruleContext = getRuleContext();
AndroidAssets assets = getLocalAssets();

@@ -158,9 +155,6 @@ public void testMerge() throws Exception {

@Test
public void testMergeAapt2() throws Exception {
mockAndroidSdkWithAapt2();
useConfiguration("--android_sdk=//sdk:sdk");

RuleContext ruleContext = getRuleContext();
ParsedAndroidAssets parsed =
getLocalAssets().parse(AndroidDataContext.forNative(ruleContext), AndroidAaptVersion.AAPT2);
@@ -877,6 +877,8 @@ private void actualSignerToolTests(String apkSigningMethod, String signV1, Strin

@Test
public void testResourceShrinkingAction() throws Exception {
useConfiguration("--android_aapt=aapt");

scratch.file("java/com/google/android/hello/BUILD",
"android_binary(name = 'hello',",
" srcs = ['Foo.java'],",
@@ -933,8 +935,9 @@ public void testResourceShrinkingAction() throws Exception {
}

@Test
public void testResourceCycleShrinking() throws Exception {
useConfiguration("--experimental_android_resource_cycle_shrinking=true");
public void testResourceCycleShrinkingWithAapt() throws Exception {
useConfiguration("--android_aapt=aapt", "--experimental_android_resource_cycle_shrinking=true");

checkError(
"java/a",
"a",
@@ -1326,6 +1329,9 @@ public void testResourceConfigurationFilters() throws Exception {

@Test
public void testFilteredResourcesInvalidFilter() throws Exception {
// This test is an analysis-time check with aapt.
useConfiguration("--android_aapt=aapt");

String badQualifier = "invalid-qualifier";

checkError(
@@ -1340,6 +1346,9 @@ public void testFilteredResourcesInvalidFilter() throws Exception {

@Test
public void testFilteredResourcesInvalidResourceDir() throws Exception {
// This test is an analysis-time check with aapt.
useConfiguration("--android_aapt=aapt");

String badQualifierDir = "values-invalid-qualifier";

checkError(
@@ -1359,10 +1368,6 @@ public void testFilteredResourcesFilteringAapt2() throws Exception {
ImmutableList.of("res/values/foo.xml", "res/values-en/foo.xml", "res/values-fr/foo.xml");
String dir = "java/r/android";

mockAndroidSdkWithAapt2();

useConfiguration("--android_sdk=//sdk:sdk");

ConfiguredTarget binary =
scratchConfiguredTarget(
dir,
@@ -1390,6 +1395,8 @@ public void testFilteredResourcesFilteringAapt2() throws Exception {

@Test
public void testFilteredResourcesSimple() throws Exception {
useConfiguration("--android_aapt=aapt");

testDirectResourceFiltering(
"en",
/* unexpectedQualifiers= */ ImmutableList.of("fr"),
@@ -1678,6 +1685,8 @@ private void testDirectResourceFiltering(
String folderType,
String suffix)
throws Exception {
// Filtering is done at the analysis time for aapt.
useConfiguration("--android_aapt=aapt");

List<String> unexpectedResources = new ArrayList<>();
for (String qualifier : unexpectedQualifiers) {
@@ -1757,6 +1766,9 @@ private void testDirectResourceFiltering(

@Test
public void testFilteredTransitiveResources() throws Exception {
// Filtering is done at analysis time for aapt.
useConfiguration("--android_aapt=aapt");

String matchingResource = "res/values-en/foo.xml";
String unqualifiedResource = "res/values/foo.xml";
String notMatchingResource = "res/values-fr/foo.xml";
@@ -1799,6 +1811,9 @@ public void testFilteredTransitiveResources() throws Exception {

@Test
public void testFilteredTransitiveResourcesDifferentDensities() throws Exception {
// Filtering is done at analysis time for aapt.
useConfiguration("--android_aapt=aapt");

String dir = "java/r/android";

ConfiguredTarget binary =
@@ -1846,6 +1861,9 @@ public void testFilteredTransitiveResourcesDifferentDensities() throws Exception

@Test
public void testFilteredResourcesAllFilteredOut() throws Exception {
// Filtering is done at analysis time for aapt.
useConfiguration("--android_aapt=aapt");

String dir = "java/r/android";

final String keptBaseDir = "partly_filtered_dir";
@@ -2081,6 +2099,9 @@ public void testUseRClassGeneratorCustomPackage() throws Exception {

@Test
public void testUseRClassGeneratorMultipleDeps() throws Exception {
// This test assumes using aapt.
useConfiguration("--android_aapt=aapt");

scratch.file(
"java/r/android/BUILD",
"android_library(name = 'lib1',",
@@ -2515,6 +2536,7 @@ public void testMainDexListWithAndroidSdk() throws Exception {
"android_sdk(",
" name = 'sdk',",
" aapt = 'aapt',",
" aapt2 = 'aapt2',",
" adb = 'adb',",
" aidl = 'aidl',",
" android_jar = 'android.jar',",
@@ -2553,6 +2575,7 @@ public void testMainDexAaptGenerationSupported() throws Exception {
" name = 'sdk',",
" build_tools_version = '24.0.0',",
" aapt = 'aapt',",
" aapt2 = 'aapt2',",
" adb = 'adb',",
" aidl = 'aidl',",
" android_jar = 'android.jar',",
@@ -3562,40 +3585,8 @@ public void testFeatureFlagPolicyIsNotUsedIfFlagValuesNotUsed() throws Exception
assertContainsEvent("*super* busted package group");
}

@Test
public void testAapt2WithoutAndroidSdk() throws Exception {
useConfiguration("--android_aapt=aapt2");
checkError(
"java/a",
"a",
"aapt2 processing requested but not available on the android_sdk",
"android_binary(",
" name = 'a',",
" srcs = ['A.java'],",
" manifest = 'AndroidManifest.xml',",
" resource_files = [ 'res/values/values.xml' ], ",
" aapt_version = 'aapt2'",
")");
}

@Test
public void testAapt2FlagWithoutAndroidSdk() throws Exception {
useConfiguration("--android_aapt=aapt2");
checkError(
"java/a",
"a",
"aapt2 processing requested but not available on the android_sdk",
"android_binary(",
" name = 'a',",
" srcs = ['A.java'],",
" manifest = 'AndroidManifest.xml',",
" resource_files = [ 'res/values/values.xml' ], ",
")");
}

@Test
public void testAapt2WithAndroidSdk() throws Exception {
mockAndroidSdkWithAapt2();
scratch.file(
"java/a/BUILD",
"android_binary(",
@@ -3606,17 +3597,20 @@ public void testAapt2WithAndroidSdk() throws Exception {
" aapt_version = 'aapt2'",
")");

useConfiguration("--android_sdk=//sdk:sdk");
ConfiguredTarget a = getConfiguredTarget("//java/a:a");
Artifact apk = getImplicitOutputArtifact(a, AndroidRuleClasses.ANDROID_RESOURCES_APK);

assertThat(getGeneratingSpawnActionArgs(apk))
.containsAtLeast("--aapt2", "sdk/aapt2", "--tool", "AAPT2_PACKAGE");
.containsAtLeast(
"--aapt2",
// The path to aapt2 is different between Blaze and Bazel, so we omit it here.
// It's safe to do so as we've already checked for the `--aapt2` flag.
"--tool",
"AAPT2_PACKAGE");
}

@Test
public void testAapt2WithAndroidSdkAndDependencies() throws Exception {
mockAndroidSdkWithAapt2();
scratch.file(
"java/b/BUILD",
"android_library(",
@@ -3637,7 +3631,6 @@ public void testAapt2WithAndroidSdkAndDependencies() throws Exception {
" aapt_version = 'aapt2'",
")");

useConfiguration("--android_sdk=//sdk:sdk");
ConfiguredTarget a = getConfiguredTarget("//java/a:a");
ConfiguredTarget b = getDirectPrerequisite(a, "//java/b:b");

@@ -3648,7 +3641,12 @@ public void testAapt2WithAndroidSdkAndDependencies() throws Exception {

SpawnAction apkAction = getGeneratingSpawnAction(apk);
assertThat(getGeneratingSpawnActionArgs(apk))
.containsAtLeast("--aapt2", "sdk/aapt2", "--tool", "AAPT2_PACKAGE");
.containsAtLeast(
"--aapt2",
// The path to aapt2 is different between Blaze and Bazel, so we omit it here.
// It's safe to do so as we've already checked for the `--aapt2` flag.
"--tool",
"AAPT2_PACKAGE");

assertThat(apkAction.getInputs())
.contains(
@@ -3662,7 +3660,6 @@ public void testAapt2WithAndroidSdkAndDependencies() throws Exception {

@Test
public void testAapt2ResourceShrinkingAction() throws Exception {
mockAndroidSdkWithAapt2();
scratch.file(
"java/com/google/android/hello/BUILD",
"android_binary(name = 'hello',",
@@ -3674,7 +3671,6 @@ public void testAapt2ResourceShrinkingAction() throws Exception {
" shrink_resources = 1,",
" proguard_specs = ['proguard-spec.pro'],)");

useConfiguration("--android_sdk=//sdk:sdk");
ConfiguredTargetAndData targetAndData =
getConfiguredTargetAndData("//java/com/google/android/hello:hello");
ConfiguredTarget binary = targetAndData.getConfiguredTarget();
@@ -3726,9 +3722,7 @@ public void testAapt2ResourceShrinkingAction() throws Exception {

@Test
public void testAapt2ResourceCycleShrinking() throws Exception {
mockAndroidSdkWithAapt2();
useConfiguration(
"--android_sdk=//sdk:sdk", "--experimental_android_resource_cycle_shrinking=true");
useConfiguration("--experimental_android_resource_cycle_shrinking=true");
scratch.file(
"java/com/google/android/hello/BUILD",
"android_binary(name = 'hello',",
@@ -3759,9 +3753,7 @@ public void testAapt2ResourceCycleShrinking() throws Exception {

@Test
public void testAapt2ResourceCycleShinkingWithoutResourceShrinking() throws Exception {
mockAndroidSdkWithAapt2();
useConfiguration(
"--android_sdk=//sdk:sdk", "--experimental_android_resource_cycle_shrinking=true");
useConfiguration("--experimental_android_resource_cycle_shrinking=true");
checkError(
"java/a",
"a",
@@ -4324,7 +4316,6 @@ public void testConfigurableProguardSpecs() throws Exception {

@Test
public void testSkipParsingActionFlagGetsPropagated() throws Exception {
mockAndroidSdkWithAapt2();
scratch.file(
"java/b/BUILD",
"android_library(",
@@ -4345,7 +4336,7 @@ public void testSkipParsingActionFlagGetsPropagated() throws Exception {
" aapt_version = 'aapt2'",
")");

useConfiguration("--android_sdk=//sdk:sdk", "--experimental_skip_parsing_action");
useConfiguration("--experimental_skip_parsing_action");
ConfiguredTarget a = getConfiguredTarget("//java/a:a");
ConfiguredTarget b = getDirectPrerequisite(a, "//java/b:b");

@@ -4368,7 +4359,6 @@ public void testSkipParsingActionFlagGetsPropagated() throws Exception {

@Test
public void alwaysSkipParsingActionWithAapt2() throws Exception {
mockAndroidSdkWithAapt2();
scratch.file(
"java/b/BUILD",
"android_library(",
@@ -4389,7 +4379,6 @@ public void alwaysSkipParsingActionWithAapt2() throws Exception {
" aapt_version = 'aapt2'",
")");

useConfiguration("--android_sdk=//sdk:sdk");
ConfiguredTarget a = getConfiguredTarget("//java/a:a");
ConfiguredTarget b = getDirectPrerequisite(a, "//java/b:b");

@@ -4412,7 +4401,6 @@ public void alwaysSkipParsingActionWithAapt2() throws Exception {

@Test
public void testAapt1BuildsWithAapt2Sdk() throws Exception {
mockAndroidSdkWithAapt2();
scratch.file(
"java/b/BUILD",
"android_library(",
@@ -4433,7 +4421,7 @@ public void testAapt1BuildsWithAapt2Sdk() throws Exception {
" aapt_version = 'aapt'",
")");

useConfiguration("--android_sdk=//sdk:sdk", "--experimental_skip_parsing_action");
useConfiguration("--android_aapt=aapt", "--experimental_skip_parsing_action");
ConfiguredTarget a = getConfiguredTarget("//java/a:a");
ConfiguredTarget b = getDirectPrerequisite(a, "//java/b:b");

0 comments on commit c6022ee

Please sign in to comment.
You can’t perform that action at this time.