summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/droiddoc.go3
-rw-r--r--java/java.go114
-rw-r--r--java/java_test.go7
-rw-r--r--java/sdk_library.go240
-rw-r--r--java/testing.go1
5 files changed, 262 insertions, 103 deletions
diff --git a/java/droiddoc.go b/java/droiddoc.go
index ff3f10a99..f62f5f901 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -34,6 +34,9 @@ func init() {
android.RegisterSdkMemberType(&droidStubsSdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
PropertyName: "stubs_sources",
+ // stubs_sources can be used with sdk to provide the source stubs for APIs provided by
+ // the APEX.
+ SupportsSdk: true,
},
})
}
diff --git a/java/java.go b/java/java.go
index d0bf9d731..a48b5a300 100644
--- a/java/java.go
+++ b/java/java.go
@@ -41,6 +41,7 @@ func init() {
librarySdkMemberType{
android.SdkMemberTypeBase{
PropertyName: "java_header_libs",
+ SupportsSdk: true,
},
},
})
@@ -52,6 +53,12 @@ func init() {
},
},
})
+
+ android.RegisterSdkMemberType(&testSdkMemberType{
+ SdkMemberTypeBase: android.SdkMemberTypeBase{
+ PropertyName: "java_tests",
+ },
+ })
}
func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
@@ -65,6 +72,7 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("java_test", TestFactory)
ctx.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
ctx.RegisterModuleType("java_test_host", TestHostFactory)
+ ctx.RegisterModuleType("java_test_import", JavaTestImportFactory)
ctx.RegisterModuleType("java_import", ImportFactory)
ctx.RegisterModuleType("java_import_host", ImportFactoryHost)
ctx.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
@@ -1764,14 +1772,19 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
}
const (
- aidlIncludeDir = "aidl"
- javaDir = "java"
- jarFileSuffix = ".jar"
+ aidlIncludeDir = "aidl"
+ javaDir = "java"
+ jarFileSuffix = ".jar"
+ testConfigSuffix = "-AndroidTest.xml"
)
// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
-func (j *Library) sdkSnapshotFilePathForJar() string {
- return filepath.Join(javaDir, j.Name()+jarFileSuffix)
+func sdkSnapshotFilePathForJar(member android.SdkMember) string {
+ return sdkSnapshotFilePathForMember(member, jarFileSuffix)
+}
+
+func sdkSnapshotFilePathForMember(member android.SdkMember, suffix string) string {
+ return filepath.Join(javaDir, member.Name()+suffix)
}
type librarySdkMemberType struct {
@@ -1804,7 +1817,7 @@ func (mt *librarySdkMemberType) buildSnapshot(
j := variant.(*Library)
exportedJar := jarToExportGetter(j)
- snapshotRelativeJavaLibPath := j.sdkSnapshotFilePathForJar()
+ snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
for _, dir := range j.AidlIncludeDirs() {
@@ -1931,6 +1944,16 @@ type testHelperLibraryProperties struct {
Test_suites []string `android:"arch_variant"`
}
+type prebuiltTestProperties struct {
+ // list of compatibility suites (for example "cts", "vts") that the module should be
+ // installed into.
+ Test_suites []string `android:"arch_variant"`
+
+ // the name of the test configuration (for example "AndroidTest.xml") that should be
+ // installed with the module.
+ Test_config *string `android:"path,arch_variant"`
+}
+
type Test struct {
Library
@@ -1946,6 +1969,14 @@ type TestHelperLibrary struct {
testHelperLibraryProperties testHelperLibraryProperties
}
+type JavaTestImport struct {
+ Import
+
+ prebuiltTestProperties prebuiltTestProperties
+
+ testConfig android.Path
+}
+
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
@@ -1958,6 +1989,53 @@ func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContex
j.Library.GenerateAndroidBuildActions(ctx)
}
+func (j *JavaTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.prebuiltTestProperties.Test_config, nil,
+ j.prebuiltTestProperties.Test_suites, nil)
+
+ j.Import.GenerateAndroidBuildActions(ctx)
+}
+
+type testSdkMemberType struct {
+ android.SdkMemberTypeBase
+}
+
+func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) {
+ mctx.AddVariationDependencies(nil, dependencyTag, names...)
+}
+
+func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
+ _, ok := module.(*Test)
+ return ok
+}
+
+func (mt *testSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
+ variants := member.Variants()
+ if len(variants) != 1 {
+ sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
+ for _, variant := range variants {
+ sdkModuleContext.ModuleErrorf(" %q", variant)
+ }
+ }
+ variant := variants[0]
+ j := variant.(*Test)
+
+ implementationJars := j.ImplementationJars()
+ if len(implementationJars) != 1 {
+ panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
+ }
+
+ snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(member)
+ builder.CopyToSnapshot(implementationJars[0], snapshotRelativeJavaLibPath)
+
+ snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(member, testConfigSuffix)
+ builder.CopyToSnapshot(j.testConfig, snapshotRelativeTestConfigPath)
+
+ module := builder.AddPrebuiltModule(member, "java_test_import")
+ module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
+ module.AddProperty("test_config", snapshotRelativeTestConfigPath)
+}
+
// java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
// creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
//
@@ -2001,6 +2079,30 @@ func TestHelperLibraryFactory() android.Module {
return module
}
+// java_test_import imports one or more `.jar` files into the build graph as if they were built by a java_test module
+// and makes sure that it is added to the appropriate test suite.
+//
+// By default, a java_test_import has a single variant that expects a `.jar` file containing `.class` files that were
+// compiled against an Android classpath.
+//
+// Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
+// for host modules.
+func JavaTestImportFactory() android.Module {
+ module := &JavaTestImport{}
+
+ module.AddProperties(
+ &module.Import.properties,
+ &module.prebuiltTestProperties)
+
+ module.Import.properties.Installable = proptools.BoolPtr(true)
+
+ android.InitPrebuiltModule(module, &module.properties.Jars)
+ android.InitApexModule(module)
+ android.InitSdkAwareModule(module)
+ InitJavaModule(module, android.HostAndDeviceSupported)
+ return module
+}
+
// java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
// allow running the test with `atest` or a `TEST_MAPPING` file.
//
diff --git a/java/java_test.go b/java/java_test.go
index 2f67cdaaa..30a8ca682 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -486,6 +486,13 @@ func TestPrebuilts(t *testing.T) {
name: "stubs-source",
srcs: ["stubs/sources"],
}
+
+ java_test_import {
+ name: "test",
+ jars: ["a.jar"],
+ test_suites: ["cts"],
+ test_config: "AndroidTest.xml",
+ }
`)
fooModule := ctx.ModuleForTests("foo", "android_common")
diff --git a/java/sdk_library.go b/java/sdk_library.go
index def2753b8..4492e3fae 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -16,7 +16,6 @@ package java
import (
"android/soong/android"
- "android/soong/genrule"
"fmt"
"io"
"path"
@@ -25,7 +24,6 @@ import (
"strings"
"sync"
- "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -35,32 +33,26 @@ const (
sdkTestApiSuffix = ".test"
sdkDocsSuffix = ".docs"
sdkXmlFileSuffix = ".xml"
- permissionTemplate = `<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<permissions>
- <library name="%s" file="%s"/>
-</permissions>
-`
+ permissionsTemplate = `<?xml version="1.0" encoding="utf-8"?>\n` +
+ `<!-- Copyright (C) 2018 The Android Open Source Project\n` +
+ `\n` +
+ ` Licensed under the Apache License, Version 2.0 (the "License");\n` +
+ ` you may not use this file except in compliance with the License.\n` +
+ ` You may obtain a copy of the License at\n` +
+ `\n` +
+ ` http://www.apache.org/licenses/LICENSE-2.0\n` +
+ `\n` +
+ ` Unless required by applicable law or agreed to in writing, software\n` +
+ ` distributed under the License is distributed on an "AS IS" BASIS,\n` +
+ ` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n` +
+ ` See the License for the specific language governing permissions and\n` +
+ ` limitations under the License.\n` +
+ `-->\n` +
+ `<permissions>\n` +
+ ` <library name="%s" file="%s"/>\n` +
+ `</permissions>\n`
)
-type stubsLibraryDependencyTag struct {
- blueprint.BaseDependencyTag
- name string
-}
-
var (
publicApiStubsTag = dependencyTag{name: "public"}
systemApiStubsTag = dependencyTag{name: "system"}
@@ -105,12 +97,22 @@ type sdkLibraryProperties struct {
// List of Java libraries that will be in the classpath when building stubs
Stub_only_libs []string `android:"arch_variant"`
- // list of package names that will be documented and publicized as API
+ // list of package names that will be documented and publicized as API.
+ // This allows the API to be restricted to a subset of the source files provided.
+ // If this is unspecified then all the source files will be treated as being part
+ // of the API.
Api_packages []string
// list of package names that must be hidden from the API
Hidden_api_packages []string
+ // the relative path to the directory containing the api specification files.
+ // Defaults to "api".
+ Api_dir *string
+
+ // If set to true there is no runtime library.
+ Api_only *bool
+
// local files that are used within user customized droiddoc options.
Droiddoc_option_files []string
@@ -133,6 +135,9 @@ type sdkLibraryProperties struct {
// don't create dist rules.
No_dist *bool `blueprint:"mutated"`
+ // indicates whether system and test apis should be managed.
+ Has_system_and_test_apis bool `blueprint:"mutated"`
+
// TODO: determines whether to create HTML doc or not
//Html_doc *bool
}
@@ -154,7 +159,7 @@ type SdkLibrary struct {
systemApiFilePath android.Path
testApiFilePath android.Path
- permissionFile android.Path
+ permissionsFile android.Path
}
var _ Dependency = (*SdkLibrary)(nil)
@@ -168,8 +173,7 @@ func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
}
ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
- sdkDep := decodeSdkDep(ctx, sdkContext(&module.Library))
- if sdkDep.hasStandardLibs() {
+ if module.sdkLibraryProperties.Has_system_and_test_apis {
if useBuiltStubs {
ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
@@ -182,12 +186,13 @@ func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
}
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- module.Library.GenerateAndroidBuildActions(ctx)
-
- if module.ApexName() != "" {
- module.buildPermissionFile(ctx)
+ // Don't build an implementation library if this is api only.
+ if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
+ module.Library.GenerateAndroidBuildActions(ctx)
}
+ module.buildPermissionsFile(ctx)
+
// 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,
// the recorded paths will be returned depending on the link type of the caller.
@@ -223,22 +228,34 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
})
}
-func (module *SdkLibrary) buildPermissionFile(ctx android.ModuleContext) {
- xmlContent := strings.ReplaceAll(fmt.Sprintf(permissionTemplate, module.BaseModuleName(), module.implPath()), "\n", "\\n")
- permissionFile := android.PathForModuleOut(ctx, module.xmlFileName())
+func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) {
+ xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath())
+ permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName())
- rule := android.NewRuleBuilder()
- rule.Command().Text("echo -e ").Text(proptools.ShellEscape(xmlContent)).Text(">").Output(permissionFile)
- rule.Build(pctx, ctx, "gen_permission_xml", "Generate permission")
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.WriteFile,
+ 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 {
- return module.permissionFile
+func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) {
+ switch tag {
+ case ".xml":
+ return android.Paths{module.permissionsFile}, nil
+ }
+ return module.Library.OutputFiles(tag)
}
func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
+ if proptools.Bool(module.sdkLibraryProperties.Api_only) {
+ return nil
+ }
entriesList := module.Library.AndroidMkEntries()
entries := &entriesList[0]
entries.Required = append(entries.Required, module.xmlFileName())
@@ -357,7 +374,7 @@ func (module *SdkLibrary) xmlFileName() string {
// SDK version that the stubs library is built against. Note that this is always
// *current. Older stubs library built with a numberd SDK version is created from
// the prebuilt jar.
-func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
+func (module *SdkLibrary) sdkVersionForScope(apiScope apiScope) string {
switch apiScope {
case apiScopePublic:
return "current"
@@ -370,6 +387,18 @@ func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
}
}
+// Get the sdk version for use when compiling the stubs library.
+func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.BaseModuleContext, apiScope apiScope) string {
+ sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
+ if sdkDep.hasStandardLibs() {
+ // If building against a standard sdk then use the sdk version appropriate for the scope.
+ return module.sdkVersionForScope(apiScope)
+ } else {
+ // Otherwise, use no system module.
+ return "none"
+ }
+}
+
// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
// api file for the current source
// TODO: remove this when apicheck is done in soong
@@ -417,14 +446,15 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
props := struct {
Name *string
Srcs []string
+ Installable *bool
Sdk_version *string
+ System_modules *string
Libs []string
Soc_specific *bool
Device_specific *bool
Product_specific *bool
System_ext_specific *bool
Compile_dex *bool
- System_modules *string
Java_version *string
Product_variables struct {
Unbundled_build struct {
@@ -440,23 +470,19 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
}
}{}
- sdkVersion := module.sdkVersion(apiScope)
- sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
- if !sdkDep.hasStandardLibs() {
- sdkVersion = "none"
- }
-
props.Name = proptools.StringPtr(module.stubsName(apiScope))
// sources are generated from the droiddoc
props.Srcs = []string{":" + module.docsName(apiScope)}
+ sdkVersion := module.sdkVersionForStubsLibrary(mctx, apiScope)
props.Sdk_version = proptools.StringPtr(sdkVersion)
+ props.System_modules = module.Library.Module.deviceProperties.System_modules
+ props.Installable = proptools.BoolPtr(false)
props.Libs = module.sdkLibraryProperties.Stub_only_libs
// Unbundled apps will use the prebult one from /prebuilts/sdk
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
}
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
- props.System_modules = module.Library.Module.deviceProperties.System_modules
props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs
props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags
props.Java_version = module.Library.Module.properties.Java_version
@@ -479,12 +505,13 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
// Creates a droiddoc module that creates stubs source files from the given full source
// files
-func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
+func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope apiScope) {
props := struct {
Name *string
Srcs []string
Installable *bool
Sdk_version *string
+ System_modules *string
Libs []string
Arg_files []string
Args *string
@@ -506,6 +533,8 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS
}{}
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
+ // Use the platform API if standard libraries were requested, otherwise use
+ // no default libraries.
sdkVersion := ""
if !sdkDep.hasStandardLibs() {
sdkVersion = "none"
@@ -514,6 +543,7 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS
props.Name = proptools.StringPtr(module.docsName(apiScope))
props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
props.Sdk_version = proptools.StringPtr(sdkVersion)
+ props.System_modules = module.Library.Module.deviceProperties.System_modules
props.Installable = proptools.BoolPtr(false)
// A droiddoc module has only one Libs property and doesn't distinguish between
// shared libs and static libs. So we need to add both of these libs to Libs property.
@@ -526,21 +556,36 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS
props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
- droiddocArgs := " --stub-packages " + strings.Join(module.sdkLibraryProperties.Api_packages, ":") +
- " " + android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ") +
- " " + android.JoinWithPrefix(module.sdkLibraryProperties.Droiddoc_options, " ") +
- " --hide MissingPermission --hide BroadcastBehavior " +
- "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
- "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
+ droiddocArgs := []string{}
+ if len(module.sdkLibraryProperties.Api_packages) != 0 {
+ droiddocArgs = append(droiddocArgs, "--stub-packages "+strings.Join(module.sdkLibraryProperties.Api_packages, ":"))
+ }
+ if len(module.sdkLibraryProperties.Hidden_api_packages) != 0 {
+ droiddocArgs = append(droiddocArgs,
+ android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package "))
+ }
+ droiddocArgs = append(droiddocArgs, module.sdkLibraryProperties.Droiddoc_options...)
+ disabledWarnings := []string{
+ "MissingPermission",
+ "BroadcastBehavior",
+ "HiddenSuperclass",
+ "DeprecationMismatch",
+ "UnavailableSymbol",
+ "SdkConstant",
+ "HiddenTypeParameter",
+ "Todo",
+ "Typo",
+ }
+ droiddocArgs = append(droiddocArgs, android.JoinWithPrefix(disabledWarnings, "--hide "))
switch apiScope {
case apiScopeSystem:
- droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
+ droiddocArgs = append(droiddocArgs, "-showAnnotation android.annotation.SystemApi")
case apiScopeTest:
- droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
+ droiddocArgs = append(droiddocArgs, " -showAnnotation android.annotation.TestApi")
}
props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
- props.Args = proptools.StringPtr(droiddocArgs)
+ props.Args = proptools.StringPtr(strings.Join(droiddocArgs, " "))
// List of APIs identified from the provided source files are created. They are later
// compared against to the not-yet-released (a.k.a current) list of APIs and to the
@@ -555,8 +600,9 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS
currentApiFileName = "test-" + currentApiFileName
removedApiFileName = "test-" + removedApiFileName
}
- currentApiFileName = path.Join("api", currentApiFileName)
- removedApiFileName = path.Join("api", removedApiFileName)
+ apiDir := module.getApiDir()
+ currentApiFileName = path.Join(apiDir, currentApiFileName)
+ removedApiFileName = path.Join(apiDir, removedApiFileName)
// TODO(jiyong): remove these three props
props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
props.Api_filename = proptools.StringPtr(currentApiFileName)
@@ -578,21 +624,6 @@ func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiS
// Creates the xml file that publicizes the runtime library
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
// <partition>/etc/permissions
etcProps := struct {
@@ -605,7 +636,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
System_ext_specific *bool
}{}
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")
if module.SocSpecific() {
etcProps.Soc_specific = proptools.BoolPtr(true)
@@ -686,6 +717,10 @@ func javaSdkLibraries(config android.Config) *[]string {
}).(*[]string)
}
+func (module *SdkLibrary) getApiDir() string {
+ return proptools.StringDefault(module.sdkLibraryProperties.Api_dir, "api")
+}
+
// For a java_sdk_library module, create internal modules for stubs, docs,
// runtime libs and xml file. If requested, the stubs and docs are created twice
// once for public API level and once for system API level
@@ -695,16 +730,25 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
return
}
- if len(module.sdkLibraryProperties.Api_packages) == 0 {
- mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
- return
+ // If this builds against standard libraries (i.e. is not part of the core libraries)
+ // then assume it provides both system and test apis. Otherwise, assume it does not and
+ // also assume it does not contribute to the dist build.
+ sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
+ hasSystemAndTestApis := sdkDep.hasStandardLibs()
+ module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis
+ module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
+
+ scopes := []string{""}
+ if hasSystemAndTestApis {
+ scopes = append(scopes, "system-", "test-")
}
missing_current_api := false
- for _, scope := range []string{"", "system-", "test-"} {
+ apiDir := module.getApiDir()
+ for _, scope := range scopes {
for _, api := range []string{"current.txt", "removed.txt"} {
- path := path.Join(mctx.ModuleDir(), "api", scope+api)
+ path := path.Join(mctx.ModuleDir(), apiDir, scope+api)
p := android.ExistentPathForSource(mctx, path)
if !p.Valid() {
mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
@@ -723,33 +767,35 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
mctx.ModuleErrorf("One or more current api files are missing. "+
"You can update them by:\n"+
- "%s %q && m update-api", script, mctx.ModuleDir())
+ "%s %q %s && m update-api",
+ script, filepath.Join(mctx.ModuleDir(), apiDir), strings.Join(scopes, " "))
return
}
// for public API stubs
module.createStubsLibrary(mctx, apiScopePublic)
- module.createDocs(mctx, apiScopePublic)
+ module.createStubsSources(mctx, apiScopePublic)
- sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
- if sdkDep.hasStandardLibs() {
+ if hasSystemAndTestApis {
// for system API stubs
module.createStubsLibrary(mctx, apiScopeSystem)
- module.createDocs(mctx, apiScopeSystem)
+ module.createStubsSources(mctx, apiScopeSystem)
// for test API stubs
module.createStubsLibrary(mctx, apiScopeTest)
- module.createDocs(mctx, apiScopeTest)
+ module.createStubsSources(mctx, apiScopeTest)
+ }
+ if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
// for runtime
module.createXmlFile(mctx)
- }
- // record java_sdk_library modules so that they are exported to make
- javaSdkLibraries := javaSdkLibraries(mctx.Config())
- javaSdkLibrariesLock.Lock()
- defer javaSdkLibrariesLock.Unlock()
- *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
+ // record java_sdk_library modules so that they are exported to make
+ javaSdkLibraries := javaSdkLibraries(mctx.Config())
+ javaSdkLibrariesLock.Lock()
+ defer javaSdkLibrariesLock.Unlock()
+ *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
+ }
}
func (module *SdkLibrary) InitSdkLibraryProperties() {
diff --git a/java/testing.go b/java/testing.go
index e157dd0d4..ab3af6576 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -34,6 +34,7 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string
"GENRULE_NOTICE": nil,
"LIB_NOTICE": nil,
"TOOL_NOTICE": nil,
+ "AndroidTest.xml": nil,
"java-res/a/a": nil,
"java-res/b/b": nil,
"java-res2/a": nil,