From 1816cde8ce37037a5c5f4e9b1df437f3cc577321 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 10 Apr 2024 10:58:21 +0100 Subject: [PATCH] java_sdk_library: Use WriteFileRule for writing permissions.xml Use the `WriteFileRule` to write the permissions file for shared libraries instead of generating a custom bash rule. Test: TH Change-Id: I904cf0742bfec46ed45ec7801bb9bd3dc3047185 --- apex/apex_test.go | 5 ++-- java/sdk_library.go | 52 +++++++++++++++++++--------------------- java/sdk_library_test.go | 35 ++++++++++++++------------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 1e75948af..819870721 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -7114,8 +7114,9 @@ func TestJavaSDKLibrary(t *testing.T) { "etc/permissions/foo.xml", }) // Permission XML should point to the activated path of impl jar of java_sdk_library - sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") - ensureMatches(t, sdkLibrary.RuleParams.Command, `\n`, - `\n`, - `\n`, + "\n", + "\n", + "\n", libraryTag, libNameAttr, filePathAttr, @@ -3292,8 +3292,9 @@ func (module *sdkLibraryXml) permissionsContents(ctx android.ModuleContext) stri minSdkAttr, maxSdkAttr, dependenciesAttr, - ` />\n`, - `\n`}, "") + " />\n", + "\n", + }, "") } func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -3305,12 +3306,7 @@ func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleConte xmlContent := module.permissionsContents(ctx) module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath - rule := android.NewRuleBuilder(pctx, ctx) - rule.Command(). - Text("/bin/bash -c \"echo -e '" + xmlContent + "'\" > "). - Output(module.outputFilePath) - - rule.Build("java_sdk_xml", "Permission XML") + android.WriteFileRuleVerbatim(ctx, module.outputFilePath, xmlContent) module.installDirPath = android.PathForModuleInstall(ctx, "etc", module.SubDir()) } diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index a19d3829f..5fac2556d 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -227,19 +227,21 @@ func TestJavaSdkLibrary_UpdatableLibrary(t *testing.T) { `) // test that updatability attributes are passed on correctly - fooUpdatable := result.ModuleForTests("fooUpdatable.xml", "android_common").Rule("java_sdk_xml") - android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `on-bootclasspath-since=\"U\"`) - android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `on-bootclasspath-before=\"V\"`) - android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `min-device-sdk=\"W\"`) - android.AssertStringDoesContain(t, "fooUpdatable.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `max-device-sdk=\"X\"`) + fooUpdatable := result.ModuleForTests("fooUpdatable.xml", "android_common").Output("fooUpdatable.xml") + fooUpdatableContents := android.ContentFromFileRuleForTests(t, result.TestContext, fooUpdatable) + android.AssertStringDoesContain(t, "fooUpdatable.xml contents", fooUpdatableContents, `on-bootclasspath-since="U"`) + android.AssertStringDoesContain(t, "fooUpdatable.xml contents", fooUpdatableContents, `on-bootclasspath-before="V"`) + android.AssertStringDoesContain(t, "fooUpdatable.xml contents", fooUpdatableContents, `min-device-sdk="W"`) + android.AssertStringDoesContain(t, "fooUpdatable.xml contents", fooUpdatableContents, `max-device-sdk="X"`) // double check that updatability attributes are not written if they don't exist in the bp file // the permissions file for the foo library defined above - fooPermissions := result.ModuleForTests("foo.xml", "android_common").Rule("java_sdk_xml") - android.AssertStringDoesNotContain(t, "foo.xml java_sdk_xml command", fooPermissions.RuleParams.Command, `on-bootclasspath-since`) - android.AssertStringDoesNotContain(t, "foo.xml java_sdk_xml command", fooPermissions.RuleParams.Command, `on-bootclasspath-before`) - android.AssertStringDoesNotContain(t, "foo.xml java_sdk_xml command", fooPermissions.RuleParams.Command, `min-device-sdk`) - android.AssertStringDoesNotContain(t, "foo.xml java_sdk_xml command", fooPermissions.RuleParams.Command, `max-device-sdk`) + fooPermissions := result.ModuleForTests("foo.xml", "android_common").Output("foo.xml") + fooPermissionsContents := android.ContentFromFileRuleForTests(t, result.TestContext, fooPermissions) + android.AssertStringDoesNotContain(t, "foo.xml contents", fooPermissionsContents, `on-bootclasspath-since`) + android.AssertStringDoesNotContain(t, "foo.xml contents", fooPermissionsContents, `on-bootclasspath-before`) + android.AssertStringDoesNotContain(t, "foo.xml contents", fooPermissionsContents, `min-device-sdk`) + android.AssertStringDoesNotContain(t, "foo.xml contents", fooPermissionsContents, `max-device-sdk`) } func TestJavaSdkLibrary_UpdatableLibrary_Validation_ValidVersion(t *testing.T) { @@ -370,9 +372,10 @@ func TestJavaSdkLibrary_UpdatableLibrary_usesNewTag(t *testing.T) { } `) // test that updatability attributes are passed on correctly - fooUpdatable := result.ModuleForTests("foo.xml", "android_common").Rule("java_sdk_xml") - android.AssertStringDoesContain(t, "foo.xml java_sdk_xml command", fooUpdatable.RuleParams.Command, `