diff options
| author | 2023-05-05 15:43:30 +0000 | |
|---|---|---|
| committer | 2023-05-05 15:43:30 +0000 | |
| commit | 0e27ed29b3d56e20cb12baaaa7494edea0f41d61 (patch) | |
| tree | 33550e99cc8adc4515254906c663b6b11c26e488 | |
| parent | d8d6ce336f4d32a74b6c26c9cf66c2b44d73d117 (diff) | |
| parent | 07287be17bd4209a81f27684c9ed3b567f9e8bc5 (diff) | |
Merge "Add --no-compile-sdk-metadata switch to AAPT2" into udc-dev
| -rw-r--r-- | tools/aapt2/cmd/Link.h | 5 | ||||
| -rw-r--r-- | tools/aapt2/link/ManifestFixer.cpp | 5 | ||||
| -rw-r--r-- | tools/aapt2/link/ManifestFixer.h | 8 | ||||
| -rw-r--r-- | tools/aapt2/link/ManifestFixer_test.cpp | 29 |
4 files changed, 42 insertions, 5 deletions
diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h index 2ce2167c1bf3..1b1e93bd480a 100644 --- a/tools/aapt2/cmd/Link.h +++ b/tools/aapt2/cmd/Link.h @@ -209,6 +209,11 @@ class LinkCommand : public Command { AddOptionalFlag("--compile-sdk-version-name", "Version name to inject into the AndroidManifest.xml if none is present.", &options_.manifest_fixer_options.compile_sdk_version_codename); + AddOptionalSwitch( + "--no-compile-sdk-metadata", + "Suppresses output of compile SDK-related attributes in AndroidManifest.xml,\n" + "including android:compileSdkVersion and platformBuildVersion.", + &options_.manifest_fixer_options.no_compile_sdk_metadata); AddOptionalFlagList("--fingerprint-prefix", "Fingerprint prefix to add to install constraints.", &options_.manifest_fixer_options.fingerprint_prefixes); AddOptionalSwitch("--shared-lib", "Generates a shared Android runtime library.", diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp index 53f0abee1cf2..c4f6e70c0cc9 100644 --- a/tools/aapt2/link/ManifestFixer.cpp +++ b/tools/aapt2/link/ManifestFixer.cpp @@ -719,7 +719,7 @@ bool ManifestFixer::Consume(IAaptContext* context, xml::XmlResource* doc) { root->InsertChild(0, std::move(uses_sdk)); } - if (options_.compile_sdk_version) { + if (!options_.no_compile_sdk_metadata && options_.compile_sdk_version) { xml::Attribute* attr = root->FindOrCreateAttribute(xml::kSchemaAndroid, "compileSdkVersion"); // Make sure we un-compile the value if it was set to something else. @@ -731,10 +731,9 @@ bool ManifestFixer::Consume(IAaptContext* context, xml::XmlResource* doc) { // Make sure we un-compile the value if it was set to something else. attr->compiled_value = {}; attr->value = options_.compile_sdk_version.value(); - } - if (options_.compile_sdk_version_codename) { + if (!options_.no_compile_sdk_metadata && options_.compile_sdk_version_codename) { xml::Attribute* attr = root->FindOrCreateAttribute(xml::kSchemaAndroid, "compileSdkVersionCodename"); diff --git a/tools/aapt2/link/ManifestFixer.h b/tools/aapt2/link/ManifestFixer.h index 175ab6f1cd7b..42938a4f8176 100644 --- a/tools/aapt2/link/ManifestFixer.h +++ b/tools/aapt2/link/ManifestFixer.h @@ -67,11 +67,12 @@ struct ManifestFixerOptions { std::optional<std::string> revision_code_default; // The version of the framework being compiled against to set for 'android:compileSdkVersion' in - // the <manifest> tag. + // the <manifest> tag. Not used if no_compile_sdk_metadata is set. std::optional<std::string> compile_sdk_version; // The version codename of the framework being compiled against to set for - // 'android:compileSdkVersionCodename' in the <manifest> tag. + // 'android:compileSdkVersionCodename' in the <manifest> tag. Not used if no_compile_sdk_metadata + // is set. std::optional<std::string> compile_sdk_version_codename; // The fingerprint prefixes to be added to the <install-constraints> tag. @@ -87,6 +88,9 @@ struct ManifestFixerOptions { // Whether to replace the manifest version with the the command line version bool replace_version = false; + + // Whether to suppress `android:compileSdkVersion*` and `platformBuildVersion*` attributes. + bool no_compile_sdk_metadata = false; }; // Verifies that the manifest is correctly formed and inserts defaults where specified with diff --git a/tools/aapt2/link/ManifestFixer_test.cpp b/tools/aapt2/link/ManifestFixer_test.cpp index 1b8f05b957a7..6151a8e910d9 100644 --- a/tools/aapt2/link/ManifestFixer_test.cpp +++ b/tools/aapt2/link/ManifestFixer_test.cpp @@ -892,6 +892,35 @@ TEST_F(ManifestFixerTest, InsertCompileSdkVersions) { EXPECT_THAT(attr->value, StrEq("P")); } +TEST_F(ManifestFixerTest, DoNotInsertCompileSdkVersions) { + std::string input = R"(<manifest package="com.pkg" />)"; + ManifestFixerOptions options; + options.no_compile_sdk_metadata = true; + options.compile_sdk_version = {"28"}; + options.compile_sdk_version_codename = {"P"}; + + std::unique_ptr<xml::XmlResource> manifest = VerifyWithOptions(input, options); + ASSERT_THAT(manifest, NotNull()); + + // There should be a declaration of kSchemaAndroid, even when the input + // didn't have one. + EXPECT_EQ(manifest->root->namespace_decls.size(), 1); + EXPECT_EQ(manifest->root->namespace_decls[0].prefix, "android"); + EXPECT_EQ(manifest->root->namespace_decls[0].uri, xml::kSchemaAndroid); + + xml::Attribute* attr = manifest->root->FindAttribute(xml::kSchemaAndroid, "compileSdkVersion"); + ASSERT_THAT(attr, IsNull()); + + attr = manifest->root->FindAttribute(xml::kSchemaAndroid, "compileSdkVersionCodename"); + ASSERT_THAT(attr, IsNull()); + + attr = manifest->root->FindAttribute("", "platformBuildVersionCode"); + ASSERT_THAT(attr, IsNull()); + + attr = manifest->root->FindAttribute("", "platformBuildVersionName"); + ASSERT_THAT(attr, IsNull()); +} + TEST_F(ManifestFixerTest, OverrideCompileSdkVersions) { std::string input = R"( <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android" |