summaryrefslogtreecommitdiff
path: root/java/sdk_library.go
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2019-04-17 11:11:46 -0700
committer Colin Cross <ccross@android.com> 2019-04-17 11:28:34 -0700
commit79c7c26d8a1987b4c60256d05e2cc52588ccddc0 (patch)
tree62fc0a614f73c1d1ef2dcdb1952a9c1be49845c0 /java/sdk_library.go
parent587fb4de9ac6972625534b7461634c3538c2231f (diff)
Add support for prebuilt java_sdk_library modules
Add java_sdk_library_import for use when a java_sdk_library may be used by unbundled branches that do not have the project that contains the original java_sdk_library module. Bug: 130287656 Test: m checkbuild Change-Id: I62df4bccc0da95ed6c8b31dab8f2c32cc3215e9e
Diffstat (limited to 'java/sdk_library.go')
-rw-r--r--java/sdk_library.go110
1 files changed, 110 insertions, 0 deletions
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 3bda9c7b8..c60a8a00e 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -75,6 +75,7 @@ var (
func init() {
android.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
+ android.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
javaSdkLibraries := javaSdkLibraries(ctx.Config())
@@ -731,3 +732,112 @@ func SdkLibraryFactory() android.Module {
android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
return module
}
+
+//
+// SDK library prebuilts
+//
+
+type sdkLibraryImportProperties struct {
+ Jars []string `android:"path"`
+
+ Sdk_version *string
+
+ Installable *bool
+
+ // List of shared java libs that this module has dependencies to
+ Libs []string
+
+ // List of files to remove from the jar file(s)
+ Exclude_files []string
+
+ // List of directories to remove from the jar file(s)
+ Exclude_dirs []string
+}
+
+type sdkLibraryImport struct {
+ android.ModuleBase
+ android.DefaultableModuleBase
+ prebuilt android.Prebuilt
+
+ properties sdkLibraryImportProperties
+
+ stubsPath android.Paths
+}
+
+var _ SdkLibraryDependency = (*sdkLibraryImport)(nil)
+
+func sdkLibraryImportFactory() android.Module {
+ module := &sdkLibraryImport{}
+
+ module.AddProperties(&module.properties)
+
+ android.InitPrebuiltModule(module, &module.properties.Jars)
+ InitJavaModule(module, android.HostAndDeviceSupported)
+
+ android.AddLoadHook(module, func(mctx android.LoadHookContext) { module.createInternalModules(mctx) })
+ return module
+}
+
+func (module *sdkLibraryImport) Prebuilt() *android.Prebuilt {
+ return &module.prebuilt
+}
+
+func (module *sdkLibraryImport) Name() string {
+ return module.prebuilt.Name(module.ModuleBase.Name())
+}
+
+func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) {
+ // Creates a java import for the jar with ".stubs" suffix
+ props := struct {
+ Name *string
+ Soc_specific *bool
+ Device_specific *bool
+ Product_specific *bool
+ }{}
+
+ props.Name = proptools.StringPtr(module.BaseModuleName() + sdkStubsLibrarySuffix)
+
+ if module.SocSpecific() {
+ props.Soc_specific = proptools.BoolPtr(true)
+ } else if module.DeviceSpecific() {
+ props.Device_specific = proptools.BoolPtr(true)
+ } else if module.ProductSpecific() {
+ props.Product_specific = proptools.BoolPtr(true)
+ }
+
+ mctx.CreateModule(android.ModuleFactoryAdaptor(ImportFactory), &props, &module.properties)
+
+ javaSdkLibraries := javaSdkLibraries(mctx.Config())
+ javaSdkLibrariesLock.Lock()
+ defer javaSdkLibrariesLock.Unlock()
+ *javaSdkLibraries = append(*javaSdkLibraries, module.BaseModuleName())
+}
+
+func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
+ // Add dependencies to the prebuilt stubs library
+ ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
+}
+
+func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ // Record the paths to the prebuilt stubs library.
+ ctx.VisitDirectDeps(func(to android.Module) {
+ tag := ctx.OtherModuleDependencyTag(to)
+
+ switch tag {
+ case publicApiStubsTag:
+ module.stubsPath = to.(Dependency).HeaderJars()
+ }
+ })
+}
+
+// to satisfy SdkLibraryDependency interface
+func (module *sdkLibraryImport) SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths {
+ // This module is just a wrapper for the prebuilt stubs.
+ return module.stubsPath
+}
+
+// to satisfy SdkLibraryDependency interface
+func (module *sdkLibraryImport) SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths {
+ // This module is just a wrapper for the stubs.
+ return module.stubsPath
+}