Dedup generating xml file for java_sdk_library
Permission XML file for java_sdk_library is generated by java_sdk_library itself now. And, build rule is switched to android.WriteFile since "echo -e" is not supported from build server. (-e is printed to output) Bug: 145474221 Test: m com.android.cronet and check its permissions xml file also, m org.chromium.net.cronet.xml (created dynamically) Change-Id: Iffb119151c49bc4fe6c4386fa267cca193f37dbc
This commit is contained in:
@@ -1024,12 +1024,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
}
|
}
|
||||||
filesInfo = append(filesInfo, af)
|
filesInfo = append(filesInfo, af)
|
||||||
|
|
||||||
pf := sdkLib.PermissionFile()
|
pf, _ := sdkLib.OutputFiles(".xml")
|
||||||
if pf == nil {
|
if len(pf) != 1 {
|
||||||
ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
|
ctx.PropertyErrorf("java_libs", "%q failed to generate permission XML", depName)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
filesInfo = append(filesInfo, newApexFile(ctx, pf, pf.Base(), "etc/permissions", etc, nil))
|
filesInfo = append(filesInfo, newApexFile(ctx, pf[0], pf[0].Base(), "etc/permissions", etc, nil))
|
||||||
return true // track transitive dependencies
|
return true // track transitive dependencies
|
||||||
} else {
|
} else {
|
||||||
ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
|
ctx.PropertyErrorf("java_libs", "%q of type %q is not supported", depName, ctx.OtherModuleType(child))
|
||||||
|
@@ -3288,8 +3288,8 @@ func TestJavaSDKLibrary(t *testing.T) {
|
|||||||
"etc/permissions/foo.xml",
|
"etc/permissions/foo.xml",
|
||||||
})
|
})
|
||||||
// Permission XML should point to the activated path of impl jar of java_sdk_library
|
// Permission XML should point to the activated path of impl jar of java_sdk_library
|
||||||
genXMLCommand := ctx.ModuleForTests("foo", "android_common_myapex").Output("foo.xml").RuleParams.Command
|
xml := ctx.ModuleForTests("foo", "android_common_myapex").Output("foo.xml")
|
||||||
ensureContains(t, genXMLCommand, `<library name="foo" file="/apex/myapex/javalib/foo.jar"`)
|
ensureContains(t, xml.Args["content"], `<library name="foo" file="/apex/myapex/javalib/foo.jar"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRejectNonInstallableJavaLibrary(t *testing.T) {
|
func TestRejectNonInstallableJavaLibrary(t *testing.T) {
|
||||||
|
@@ -16,7 +16,6 @@ package java
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/genrule"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
@@ -35,25 +34,24 @@ const (
|
|||||||
sdkTestApiSuffix = ".test"
|
sdkTestApiSuffix = ".test"
|
||||||
sdkDocsSuffix = ".docs"
|
sdkDocsSuffix = ".docs"
|
||||||
sdkXmlFileSuffix = ".xml"
|
sdkXmlFileSuffix = ".xml"
|
||||||
permissionTemplate = `<?xml version="1.0" encoding="utf-8"?>
|
permissionsTemplate = `<?xml version="1.0" encoding="utf-8"?>\n` +
|
||||||
<!-- Copyright (C) 2018 The Android Open Source Project
|
`<!-- Copyright (C) 2018 The Android Open Source Project\n` +
|
||||||
|
`\n` +
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
` Licensed under the Apache License, Version 2.0 (the "License");\n` +
|
||||||
you may not use this file except in compliance with the License.
|
` you may not use this file except in compliance with the License.\n` +
|
||||||
You may obtain a copy of the License at
|
` You may obtain a copy of the License at\n` +
|
||||||
|
`\n` +
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
` http://www.apache.org/licenses/LICENSE-2.0\n` +
|
||||||
|
`\n` +
|
||||||
Unless required by applicable law or agreed to in writing, software
|
` Unless required by applicable law or agreed to in writing, software\n` +
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
` distributed under the License is distributed on an "AS IS" BASIS,\n` +
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
|
||||||
See the License for the specific language governing permissions and
|
` See the License for the specific language governing permissions and\n` +
|
||||||
limitations under the License.
|
` limitations under the License.\n` +
|
||||||
-->
|
`-->\n` +
|
||||||
<permissions>
|
`<permissions>\n` +
|
||||||
<library name="%s" file="%s"/>
|
` <library name="%s" file="%s"/>\n` +
|
||||||
</permissions>
|
`</permissions>\n`
|
||||||
`
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type stubsLibraryDependencyTag struct {
|
type stubsLibraryDependencyTag struct {
|
||||||
@@ -154,7 +152,7 @@ type SdkLibrary struct {
|
|||||||
systemApiFilePath android.Path
|
systemApiFilePath android.Path
|
||||||
testApiFilePath android.Path
|
testApiFilePath android.Path
|
||||||
|
|
||||||
permissionFile android.Path
|
permissionsFile android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Dependency = (*SdkLibrary)(nil)
|
var _ Dependency = (*SdkLibrary)(nil)
|
||||||
@@ -184,9 +182,7 @@ func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
module.Library.GenerateAndroidBuildActions(ctx)
|
module.Library.GenerateAndroidBuildActions(ctx)
|
||||||
|
|
||||||
if module.ApexName() != "" {
|
module.buildPermissionsFile(ctx)
|
||||||
module.buildPermissionFile(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Record the paths to the header jars of the library (stubs and impl).
|
// Record the paths to the header jars of the library (stubs and impl).
|
||||||
// When this java_sdk_library is dependened from others via "libs" property,
|
// When this java_sdk_library is dependened from others via "libs" property,
|
||||||
@@ -223,19 +219,28 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (module *SdkLibrary) buildPermissionFile(ctx android.ModuleContext) {
|
func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) {
|
||||||
xmlContent := strings.ReplaceAll(fmt.Sprintf(permissionTemplate, module.BaseModuleName(), module.implPath()), "\n", "\\n")
|
xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath())
|
||||||
permissionFile := android.PathForModuleOut(ctx, module.xmlFileName())
|
permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName())
|
||||||
|
|
||||||
rule := android.NewRuleBuilder()
|
ctx.Build(pctx, android.BuildParams{
|
||||||
rule.Command().Text("echo -e ").Text(proptools.ShellEscape(xmlContent)).Text(">").Output(permissionFile)
|
Rule: android.WriteFile,
|
||||||
rule.Build(pctx, ctx, "gen_permission_xml", "Generate permission")
|
Output: permissionsFile,
|
||||||
|
Description: "Generating " + module.BaseModuleName() + " permissions",
|
||||||
|
Args: map[string]string{
|
||||||
|
"content": xmlContent,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
module.permissionFile = permissionFile
|
module.permissionsFile = permissionsFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func (module *SdkLibrary) PermissionFile() android.Path {
|
func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
|
||||||
return module.permissionFile
|
switch tag {
|
||||||
|
case ".xml":
|
||||||
|
return android.Paths{module.permissionsFile}, nil
|
||||||
|
}
|
||||||
|
return module.Library.OutputFiles(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
|
func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
|
||||||
@@ -578,21 +583,6 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS
|
|||||||
|
|
||||||
// Creates the xml file that publicizes the runtime library
|
// Creates the xml file that publicizes the runtime library
|
||||||
func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
|
func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
|
||||||
|
|
||||||
// genrule to generate the xml file content from the template above
|
|
||||||
// TODO: preserve newlines in the generate xml file. Newlines are being squashed
|
|
||||||
// in the ninja file. Do we need to have an external tool for this?
|
|
||||||
xmlContent := fmt.Sprintf(permissionTemplate, module.BaseModuleName(), module.implPath())
|
|
||||||
genruleProps := struct {
|
|
||||||
Name *string
|
|
||||||
Cmd *string
|
|
||||||
Out []string
|
|
||||||
}{}
|
|
||||||
genruleProps.Name = proptools.StringPtr(module.xmlFileName() + "-gen")
|
|
||||||
genruleProps.Cmd = proptools.StringPtr("echo '" + xmlContent + "' > $(out)")
|
|
||||||
genruleProps.Out = []string{module.xmlFileName()}
|
|
||||||
mctx.CreateModule(genrule.GenRuleFactory, &genruleProps)
|
|
||||||
|
|
||||||
// creates a prebuilt_etc module to actually place the xml file under
|
// creates a prebuilt_etc module to actually place the xml file under
|
||||||
// <partition>/etc/permissions
|
// <partition>/etc/permissions
|
||||||
etcProps := struct {
|
etcProps := struct {
|
||||||
@@ -605,7 +595,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
|
|||||||
System_ext_specific *bool
|
System_ext_specific *bool
|
||||||
}{}
|
}{}
|
||||||
etcProps.Name = proptools.StringPtr(module.xmlFileName())
|
etcProps.Name = proptools.StringPtr(module.xmlFileName())
|
||||||
etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
|
etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}")
|
||||||
etcProps.Sub_dir = proptools.StringPtr("permissions")
|
etcProps.Sub_dir = proptools.StringPtr("permissions")
|
||||||
if module.SocSpecific() {
|
if module.SocSpecific() {
|
||||||
etcProps.Soc_specific = proptools.BoolPtr(true)
|
etcProps.Soc_specific = proptools.BoolPtr(true)
|
||||||
|
Reference in New Issue
Block a user