2018-04-10 06:07:10 +02:00
|
|
|
// Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/genrule"
|
|
|
|
"fmt"
|
2018-04-23 14:41:26 +02:00
|
|
|
"io"
|
2018-04-10 06:07:10 +02:00
|
|
|
"path"
|
2018-10-19 06:46:09 +02:00
|
|
|
"path/filepath"
|
2018-04-23 14:41:26 +02:00
|
|
|
"sort"
|
2018-04-10 06:07:10 +02:00
|
|
|
"strings"
|
2018-04-23 14:41:26 +02:00
|
|
|
"sync"
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
sdkStubsLibrarySuffix = ".stubs"
|
|
|
|
sdkSystemApiSuffix = ".system"
|
2018-04-27 09:29:21 +02:00
|
|
|
sdkTestApiSuffix = ".test"
|
2018-04-10 06:07:10 +02:00
|
|
|
sdkDocsSuffix = ".docs"
|
|
|
|
sdkXmlFileSuffix = ".xml"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stubsLibraryDependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
publicApiStubsTag = dependencyTag{name: "public"}
|
|
|
|
systemApiStubsTag = dependencyTag{name: "system"}
|
2018-04-27 09:29:21 +02:00
|
|
|
testApiStubsTag = dependencyTag{name: "test"}
|
2018-07-24 04:19:26 +02:00
|
|
|
publicApiFileTag = dependencyTag{name: "publicApi"}
|
|
|
|
systemApiFileTag = dependencyTag{name: "systemApi"}
|
|
|
|
testApiFileTag = dependencyTag{name: "testApi"}
|
2018-04-27 09:29:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type apiScope int
|
|
|
|
|
|
|
|
const (
|
|
|
|
apiScopePublic apiScope = iota
|
|
|
|
apiScopeSystem
|
|
|
|
apiScopeTest
|
2018-04-10 06:07:10 +02:00
|
|
|
)
|
|
|
|
|
2018-04-23 14:41:26 +02:00
|
|
|
var (
|
|
|
|
javaSdkLibrariesLock sync.Mutex
|
|
|
|
)
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// java_sdk_library is to make a Java library that implements optional platform APIs to apps.
|
|
|
|
// It is actually a wrapper of several modules: 1) stubs library that clients are linked against
|
|
|
|
// to, 2) droiddoc module that internally generates API stubs source files, 3) the real runtime
|
|
|
|
// shared library that implements the APIs, and 4) XML file for adding the runtime lib to the
|
|
|
|
// classpath at runtime if requested via <uses-library>.
|
|
|
|
//
|
|
|
|
// TODO: these are big features that are currently missing
|
2018-05-28 11:02:19 +02:00
|
|
|
// 1) disallowing linking to the runtime shared lib
|
|
|
|
// 2) HTML generation
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
func init() {
|
2019-02-08 13:00:45 +01:00
|
|
|
android.RegisterModuleType("java_sdk_library", SdkLibraryFactory)
|
2019-04-17 20:11:46 +02:00
|
|
|
android.RegisterModuleType("java_sdk_library_import", sdkLibraryImportFactory)
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2018-04-23 14:41:26 +02:00
|
|
|
android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
|
|
|
|
javaSdkLibraries := javaSdkLibraries(ctx.Config())
|
|
|
|
sort.Strings(*javaSdkLibraries)
|
|
|
|
ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
|
|
|
|
})
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type sdkLibraryProperties struct {
|
2018-05-01 18:35:27 +02:00
|
|
|
// list of optional source files that are part of API but not part of runtime library.
|
|
|
|
Api_srcs []string `android:"arch_variant"`
|
|
|
|
|
2018-06-25 09:04:37 +02:00
|
|
|
// List of Java libraries that will be in the classpath when building stubs
|
|
|
|
Stub_only_libs []string `android:"arch_variant"`
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// list of package names that will be documented and publicized as API
|
|
|
|
Api_packages []string
|
|
|
|
|
2018-05-01 15:25:41 +02:00
|
|
|
// list of package names that must be hidden from the API
|
|
|
|
Hidden_api_packages []string
|
|
|
|
|
2019-02-11 16:55:17 +01:00
|
|
|
// local files that are used within user customized droiddoc options.
|
|
|
|
Droiddoc_option_files []string
|
|
|
|
|
|
|
|
// additional droiddoc options
|
|
|
|
// Available variables for substitution:
|
|
|
|
//
|
|
|
|
// $(location <label>): the path to the droiddoc_option_files with name <label>
|
2018-07-31 10:19:11 +02:00
|
|
|
Droiddoc_options []string
|
|
|
|
|
2019-01-08 08:32:12 +01:00
|
|
|
// the java library (in classpath) for documentation that provides java srcs and srcjars.
|
|
|
|
Srcs_lib *string
|
|
|
|
|
|
|
|
// the base dirs under srcs_lib will be scanned for java srcs.
|
|
|
|
Srcs_lib_whitelist_dirs []string
|
|
|
|
|
2018-07-31 10:19:11 +02:00
|
|
|
// the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
|
|
|
|
// Defaults to "android.annotation".
|
|
|
|
Srcs_lib_whitelist_pkgs []string
|
|
|
|
|
2018-10-19 06:46:09 +02:00
|
|
|
// a list of top-level directories containing files to merge qualifier annotations
|
|
|
|
// (i.e. those intended to be included in the stubs written) from.
|
|
|
|
Merge_annotations_dirs []string
|
|
|
|
|
|
|
|
// a list of top-level directories containing Java stub files to merge show/hide annotations from.
|
|
|
|
Merge_inclusion_annotations_dirs []string
|
|
|
|
|
|
|
|
// If set to true, the path of dist files is apistubs/core. Defaults to false.
|
|
|
|
Core_lib *bool
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// TODO: determines whether to create HTML doc or not
|
|
|
|
//Html_doc *bool
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
type SdkLibrary struct {
|
2018-10-19 06:46:09 +02:00
|
|
|
Library
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2018-10-19 06:46:09 +02:00
|
|
|
sdkLibraryProperties sdkLibraryProperties
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
publicApiStubsPath android.Paths
|
|
|
|
systemApiStubsPath android.Paths
|
2018-04-27 09:29:21 +02:00
|
|
|
testApiStubsPath android.Paths
|
2018-07-13 09:16:44 +02:00
|
|
|
|
|
|
|
publicApiStubsImplPath android.Paths
|
|
|
|
systemApiStubsImplPath android.Paths
|
|
|
|
testApiStubsImplPath android.Paths
|
2018-07-24 04:19:26 +02:00
|
|
|
|
|
|
|
publicApiFilePath android.Path
|
|
|
|
systemApiFilePath android.Path
|
|
|
|
testApiFilePath android.Path
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
var _ Dependency = (*SdkLibrary)(nil)
|
|
|
|
var _ SdkLibraryDependency = (*SdkLibrary)(nil)
|
2019-02-11 23:03:51 +01:00
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
2018-04-10 06:07:10 +02:00
|
|
|
// Add dependencies to the stubs library
|
2018-08-29 23:10:52 +02:00
|
|
|
ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
|
|
|
|
ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
|
2018-10-19 06:46:09 +02:00
|
|
|
|
|
|
|
if !Bool(module.properties.No_standard_libs) {
|
|
|
|
ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
|
|
|
|
ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
|
|
|
|
ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
|
|
|
|
ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
|
|
|
|
}
|
|
|
|
|
|
|
|
module.Library.deps(ctx)
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2018-10-19 06:46:09 +02:00
|
|
|
module.Library.GenerateAndroidBuildActions(ctx)
|
|
|
|
|
2018-07-06 04:20:23 +02:00
|
|
|
// Record the paths to the header jars of the library (stubs and impl).
|
2018-04-10 06:07:10 +02:00
|
|
|
// 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.
|
|
|
|
ctx.VisitDirectDeps(func(to android.Module) {
|
|
|
|
otherName := ctx.OtherModuleName(to)
|
|
|
|
tag := ctx.OtherModuleDependencyTag(to)
|
|
|
|
|
2018-07-06 04:20:23 +02:00
|
|
|
if lib, ok := to.(Dependency); ok {
|
2018-04-10 06:07:10 +02:00
|
|
|
switch tag {
|
|
|
|
case publicApiStubsTag:
|
2018-07-06 04:20:23 +02:00
|
|
|
module.publicApiStubsPath = lib.HeaderJars()
|
2018-07-13 09:16:44 +02:00
|
|
|
module.publicApiStubsImplPath = lib.ImplementationJars()
|
2018-04-10 06:07:10 +02:00
|
|
|
case systemApiStubsTag:
|
2018-07-06 04:20:23 +02:00
|
|
|
module.systemApiStubsPath = lib.HeaderJars()
|
2018-07-13 09:16:44 +02:00
|
|
|
module.systemApiStubsImplPath = lib.ImplementationJars()
|
2018-04-27 09:29:21 +02:00
|
|
|
case testApiStubsTag:
|
2018-07-06 04:20:23 +02:00
|
|
|
module.testApiStubsPath = lib.HeaderJars()
|
2018-07-13 09:16:44 +02:00
|
|
|
module.testApiStubsImplPath = lib.ImplementationJars()
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-24 04:19:26 +02:00
|
|
|
if doc, ok := to.(ApiFilePath); ok {
|
|
|
|
switch tag {
|
|
|
|
case publicApiFileTag:
|
|
|
|
module.publicApiFilePath = doc.ApiFilePath()
|
|
|
|
case systemApiFileTag:
|
|
|
|
module.systemApiFilePath = doc.ApiFilePath()
|
|
|
|
case testApiFileTag:
|
|
|
|
module.testApiFilePath = doc.ApiFilePath()
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) AndroidMk() android.AndroidMkData {
|
2018-10-19 06:46:09 +02:00
|
|
|
data := module.Library.AndroidMk()
|
|
|
|
data.Required = append(data.Required, module.xmlFileName())
|
|
|
|
|
|
|
|
data.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
|
|
|
|
android.WriteAndroidMkData(w, data)
|
|
|
|
|
|
|
|
module.Library.AndroidMkHostDex(w, name, data)
|
|
|
|
// Create a phony module that installs the impl library, for the case when this lib is
|
|
|
|
// in PRODUCT_PACKAGES.
|
|
|
|
owner := module.ModuleBase.Owner()
|
|
|
|
if owner == "" {
|
|
|
|
if Bool(module.sdkLibraryProperties.Core_lib) {
|
|
|
|
owner = "core"
|
|
|
|
} else {
|
2018-08-31 11:01:37 +02:00
|
|
|
owner = "android"
|
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
}
|
|
|
|
// Create dist rules to install the stubs libs to the dist dir
|
|
|
|
if len(module.publicApiStubsPath) == 1 {
|
|
|
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
|
|
|
module.publicApiStubsImplPath.Strings()[0]+
|
|
|
|
":"+path.Join("apistubs", owner, "public",
|
|
|
|
module.BaseModuleName()+".jar")+")")
|
|
|
|
}
|
|
|
|
if len(module.systemApiStubsPath) == 1 {
|
|
|
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
|
|
|
module.systemApiStubsImplPath.Strings()[0]+
|
|
|
|
":"+path.Join("apistubs", owner, "system",
|
|
|
|
module.BaseModuleName()+".jar")+")")
|
|
|
|
}
|
|
|
|
if len(module.testApiStubsPath) == 1 {
|
|
|
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
|
|
|
module.testApiStubsImplPath.Strings()[0]+
|
|
|
|
":"+path.Join("apistubs", owner, "test",
|
|
|
|
module.BaseModuleName()+".jar")+")")
|
|
|
|
}
|
|
|
|
if module.publicApiFilePath != nil {
|
|
|
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
|
|
|
module.publicApiFilePath.String()+
|
|
|
|
":"+path.Join("apistubs", owner, "public", "api",
|
|
|
|
module.BaseModuleName()+".txt")+")")
|
|
|
|
}
|
|
|
|
if module.systemApiFilePath != nil {
|
|
|
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
|
|
|
module.systemApiFilePath.String()+
|
|
|
|
":"+path.Join("apistubs", owner, "system", "api",
|
|
|
|
module.BaseModuleName()+".txt")+")")
|
|
|
|
}
|
|
|
|
if module.testApiFilePath != nil {
|
|
|
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
|
|
|
module.testApiFilePath.String()+
|
|
|
|
":"+path.Join("apistubs", owner, "test", "api",
|
|
|
|
module.BaseModuleName()+".txt")+")")
|
|
|
|
}
|
2018-04-23 14:41:26 +02:00
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
return data
|
2018-04-23 14:41:26 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// Module name of the stubs library
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) stubsName(apiScope apiScope) string {
|
2018-04-10 06:07:10 +02:00
|
|
|
stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
|
2018-04-27 09:29:21 +02:00
|
|
|
switch apiScope {
|
|
|
|
case apiScopeSystem:
|
2018-04-10 06:07:10 +02:00
|
|
|
stubsName = stubsName + sdkSystemApiSuffix
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeTest:
|
|
|
|
stubsName = stubsName + sdkTestApiSuffix
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
return stubsName
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module name of the docs
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) docsName(apiScope apiScope) string {
|
2018-04-10 06:07:10 +02:00
|
|
|
docsName := module.BaseModuleName() + sdkDocsSuffix
|
2018-04-27 09:29:21 +02:00
|
|
|
switch apiScope {
|
|
|
|
case apiScopeSystem:
|
2018-04-10 06:07:10 +02:00
|
|
|
docsName = docsName + sdkSystemApiSuffix
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeTest:
|
|
|
|
docsName = docsName + sdkTestApiSuffix
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
return docsName
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module name of the runtime implementation library
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) implName() string {
|
2018-10-19 06:46:09 +02:00
|
|
|
return module.BaseModuleName()
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// File path to the runtime implementation library
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) implPath() string {
|
2018-04-10 06:07:10 +02:00
|
|
|
partition := "system"
|
|
|
|
if module.SocSpecific() {
|
|
|
|
partition = "vendor"
|
|
|
|
} else if module.DeviceSpecific() {
|
|
|
|
partition = "odm"
|
|
|
|
} else if module.ProductSpecific() {
|
|
|
|
partition = "product"
|
|
|
|
}
|
|
|
|
return "/" + partition + "/framework/" + module.implName() + ".jar"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module name of the XML file for the lib
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) xmlFileName() string {
|
2018-04-10 06:07:10 +02:00
|
|
|
return module.BaseModuleName() + sdkXmlFileSuffix
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) sdkVersion(apiScope apiScope) string {
|
2018-04-27 09:29:21 +02:00
|
|
|
switch apiScope {
|
|
|
|
case apiScopePublic:
|
|
|
|
return "current"
|
|
|
|
case apiScopeSystem:
|
2018-04-10 06:07:10 +02:00
|
|
|
return "system_current"
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeTest:
|
|
|
|
return "test_current"
|
|
|
|
default:
|
2018-04-10 06:07:10 +02:00
|
|
|
return "current"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
|
|
|
|
// api file for the current source
|
|
|
|
// TODO: remove this when apicheck is done in soong
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
|
2018-04-10 06:07:10 +02:00
|
|
|
apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
|
2018-04-27 09:29:21 +02:00
|
|
|
switch apiScope {
|
|
|
|
case apiScopeSystem:
|
2018-04-10 06:07:10 +02:00
|
|
|
apiTagName = apiTagName + "_SYSTEM"
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeTest:
|
|
|
|
apiTagName = apiTagName + "_TEST"
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
return apiTagName
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
|
2018-05-12 15:29:12 +02:00
|
|
|
name := ":" + module.BaseModuleName() + ".api."
|
2018-04-27 09:29:21 +02:00
|
|
|
switch apiScope {
|
2018-05-12 15:29:12 +02:00
|
|
|
case apiScopePublic:
|
|
|
|
name = name + "public"
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeSystem:
|
2018-05-12 15:29:12 +02:00
|
|
|
name = name + "system"
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeTest:
|
2018-05-12 15:29:12 +02:00
|
|
|
name = name + "test"
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2018-05-12 15:29:12 +02:00
|
|
|
name = name + ".latest"
|
|
|
|
return name
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
|
2018-05-12 15:29:12 +02:00
|
|
|
name := ":" + module.BaseModuleName() + "-removed.api."
|
|
|
|
switch apiScope {
|
|
|
|
case apiScopePublic:
|
|
|
|
name = name + "public"
|
|
|
|
case apiScopeSystem:
|
|
|
|
name = name + "system"
|
|
|
|
case apiScopeTest:
|
|
|
|
name = name + "test"
|
|
|
|
}
|
|
|
|
name = name + ".latest"
|
|
|
|
return name
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a static java library that has API stubs
|
2019-04-16 23:43:28 +02:00
|
|
|
func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
|
2018-04-10 06:07:10 +02:00
|
|
|
props := struct {
|
|
|
|
Name *string
|
|
|
|
Srcs []string
|
|
|
|
Sdk_version *string
|
2018-06-25 09:04:37 +02:00
|
|
|
Libs []string
|
2018-04-10 06:07:10 +02:00
|
|
|
Soc_specific *bool
|
|
|
|
Device_specific *bool
|
|
|
|
Product_specific *bool
|
2018-07-31 10:19:11 +02:00
|
|
|
Compile_dex *bool
|
2018-10-19 06:46:09 +02:00
|
|
|
No_standard_libs *bool
|
|
|
|
System_modules *string
|
|
|
|
Java_version *string
|
2018-04-10 06:07:10 +02:00
|
|
|
Product_variables struct {
|
|
|
|
Unbundled_build struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
2018-04-23 14:41:26 +02:00
|
|
|
Pdk struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
Openjdk9 struct {
|
|
|
|
Srcs []string
|
|
|
|
Javacflags []string
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}{}
|
|
|
|
|
2018-04-27 09:29:21 +02:00
|
|
|
props.Name = proptools.StringPtr(module.stubsName(apiScope))
|
2018-04-10 06:07:10 +02:00
|
|
|
// sources are generated from the droiddoc
|
2018-04-27 09:29:21 +02:00
|
|
|
props.Srcs = []string{":" + module.docsName(apiScope)}
|
|
|
|
props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope))
|
2018-10-19 06:46:09 +02:00
|
|
|
props.Libs = module.sdkLibraryProperties.Stub_only_libs
|
2018-04-10 06:07:10 +02:00
|
|
|
// Unbundled apps will use the prebult one from /prebuilts/sdk
|
2019-04-18 23:27:12 +02:00
|
|
|
if mctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
2019-01-21 20:56:21 +01:00
|
|
|
props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
|
|
|
|
}
|
2018-04-23 14:41:26 +02:00
|
|
|
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
|
2018-10-19 06:46:09 +02:00
|
|
|
props.No_standard_libs = module.Library.Module.properties.No_standard_libs
|
|
|
|
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
|
|
|
|
if module.Library.Module.deviceProperties.Compile_dex != nil {
|
|
|
|
props.Compile_dex = module.Library.Module.deviceProperties.Compile_dex
|
2018-07-31 10:19:11 +02:00
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-06-27 02:59:05 +02:00
|
|
|
mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props)
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a droiddoc module that creates stubs source files from the given full source
|
|
|
|
// files
|
2019-04-16 23:43:28 +02:00
|
|
|
func (module *SdkLibrary) createDocs(mctx android.LoadHookContext, apiScope apiScope) {
|
2018-04-10 06:07:10 +02:00
|
|
|
props := struct {
|
2018-10-19 06:46:09 +02:00
|
|
|
Name *string
|
|
|
|
Srcs []string
|
|
|
|
Installable *bool
|
|
|
|
Srcs_lib *string
|
|
|
|
Srcs_lib_whitelist_dirs []string
|
|
|
|
Srcs_lib_whitelist_pkgs []string
|
|
|
|
Libs []string
|
2019-02-11 16:55:17 +01:00
|
|
|
Arg_files []string
|
2018-10-19 06:46:09 +02:00
|
|
|
Args *string
|
|
|
|
Api_tag_name *string
|
|
|
|
Api_filename *string
|
|
|
|
Removed_api_filename *string
|
|
|
|
No_standard_libs *bool
|
|
|
|
Java_version *string
|
|
|
|
Merge_annotations_dirs []string
|
|
|
|
Merge_inclusion_annotations_dirs []string
|
|
|
|
Check_api struct {
|
2019-02-28 06:24:05 +01:00
|
|
|
Current ApiToCheck
|
|
|
|
Last_released ApiToCheck
|
|
|
|
Ignore_missing_latest_api *bool
|
2018-05-12 15:29:12 +02:00
|
|
|
}
|
2018-05-29 04:35:17 +02:00
|
|
|
Aidl struct {
|
|
|
|
Include_dirs []string
|
|
|
|
Local_include_dirs []string
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}{}
|
|
|
|
|
2018-04-27 09:29:21 +02:00
|
|
|
props.Name = proptools.StringPtr(module.docsName(apiScope))
|
2018-10-19 06:46:09 +02:00
|
|
|
props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
|
|
|
|
props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...)
|
2018-04-10 06:07:10 +02:00
|
|
|
props.Installable = proptools.BoolPtr(false)
|
2018-06-05 09:46:14 +02:00
|
|
|
// 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.
|
2018-10-19 06:46:09 +02:00
|
|
|
props.Libs = module.Library.Module.properties.Libs
|
|
|
|
props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
|
|
|
|
props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
|
|
|
|
props.Aidl.Local_include_dirs = module.Library.Module.deviceProperties.Aidl.Local_include_dirs
|
|
|
|
props.No_standard_libs = module.Library.Module.properties.No_standard_libs
|
|
|
|
props.Java_version = module.Library.Module.properties.Java_version
|
|
|
|
|
|
|
|
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, " ") +
|
2019-01-14 03:36:50 +01:00
|
|
|
" --hide MissingPermission --hide BroadcastBehavior " +
|
|
|
|
"--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
|
|
|
|
"--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
|
2018-09-17 06:23:09 +02:00
|
|
|
|
2018-04-27 09:29:21 +02:00
|
|
|
switch apiScope {
|
|
|
|
case apiScopeSystem:
|
2018-04-10 06:07:10 +02:00
|
|
|
droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeTest:
|
|
|
|
droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2019-02-11 16:55:17 +01:00
|
|
|
props.Arg_files = module.sdkLibraryProperties.Droiddoc_option_files
|
2018-04-10 06:07:10 +02:00
|
|
|
props.Args = proptools.StringPtr(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
|
|
|
|
// last-released (a.k.a numbered) list of API.
|
|
|
|
currentApiFileName := "current.txt"
|
|
|
|
removedApiFileName := "removed.txt"
|
2018-04-27 09:29:21 +02:00
|
|
|
switch apiScope {
|
|
|
|
case apiScopeSystem:
|
2018-04-10 06:07:10 +02:00
|
|
|
currentApiFileName = "system-" + currentApiFileName
|
|
|
|
removedApiFileName = "system-" + removedApiFileName
|
2018-04-27 09:29:21 +02:00
|
|
|
case apiScopeTest:
|
|
|
|
currentApiFileName = "test-" + currentApiFileName
|
|
|
|
removedApiFileName = "test-" + removedApiFileName
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
currentApiFileName = path.Join("api", currentApiFileName)
|
|
|
|
removedApiFileName = path.Join("api", removedApiFileName)
|
2018-05-12 15:29:12 +02:00
|
|
|
// TODO(jiyong): remove these three props
|
2018-04-27 09:29:21 +02:00
|
|
|
props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
|
2018-04-10 06:07:10 +02:00
|
|
|
props.Api_filename = proptools.StringPtr(currentApiFileName)
|
|
|
|
props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
|
|
|
|
|
2018-05-12 15:29:12 +02:00
|
|
|
// check against the not-yet-release API
|
|
|
|
props.Check_api.Current.Api_file = proptools.StringPtr(currentApiFileName)
|
|
|
|
props.Check_api.Current.Removed_api_file = proptools.StringPtr(removedApiFileName)
|
|
|
|
|
|
|
|
// check against the latest released API
|
|
|
|
props.Check_api.Last_released.Api_file = proptools.StringPtr(
|
|
|
|
module.latestApiFilegroupName(apiScope))
|
|
|
|
props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
|
|
|
|
module.latestRemovedApiFilegroupName(apiScope))
|
2019-02-28 06:24:05 +01:00
|
|
|
props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
|
2018-10-19 06:46:09 +02:00
|
|
|
props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib
|
|
|
|
props.Srcs_lib_whitelist_dirs = module.sdkLibraryProperties.Srcs_lib_whitelist_dirs
|
|
|
|
props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-01-14 03:36:50 +01:00
|
|
|
mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates the xml file that publicizes the runtime library
|
2019-04-16 23:43:28 +02:00
|
|
|
func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) {
|
2018-04-10 06:07:10 +02:00
|
|
|
template := `
|
|
|
|
<?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>
|
|
|
|
`
|
|
|
|
// 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(template, 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(android.ModuleFactoryAdaptor(genrule.GenRuleFactory), &genruleProps)
|
|
|
|
|
|
|
|
// creates a prebuilt_etc module to actually place the xml file under
|
|
|
|
// <partition>/etc/permissions
|
|
|
|
etcProps := struct {
|
|
|
|
Name *string
|
2018-04-25 15:57:34 +02:00
|
|
|
Src *string
|
2018-04-10 06:07:10 +02:00
|
|
|
Sub_dir *string
|
|
|
|
Soc_specific *bool
|
|
|
|
Device_specific *bool
|
|
|
|
Product_specific *bool
|
|
|
|
}{}
|
|
|
|
etcProps.Name = proptools.StringPtr(module.xmlFileName())
|
2018-04-25 15:57:34 +02:00
|
|
|
etcProps.Src = proptools.StringPtr(":" + module.xmlFileName() + "-gen")
|
2018-04-10 06:07:10 +02:00
|
|
|
etcProps.Sub_dir = proptools.StringPtr("permissions")
|
|
|
|
if module.SocSpecific() {
|
|
|
|
etcProps.Soc_specific = proptools.BoolPtr(true)
|
|
|
|
} else if module.DeviceSpecific() {
|
|
|
|
etcProps.Device_specific = proptools.BoolPtr(true)
|
|
|
|
} else if module.ProductSpecific() {
|
|
|
|
etcProps.Product_specific = proptools.BoolPtr(true)
|
|
|
|
}
|
|
|
|
mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps)
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) PrebuiltJars(ctx android.BaseContext, sdkVersion string) android.Paths {
|
2018-10-19 06:46:09 +02:00
|
|
|
var api, v string
|
|
|
|
if sdkVersion == "" {
|
|
|
|
api = "system"
|
|
|
|
v = "current"
|
|
|
|
} else if strings.Contains(sdkVersion, "_") {
|
|
|
|
t := strings.Split(sdkVersion, "_")
|
|
|
|
api = t[0]
|
|
|
|
v = t[1]
|
|
|
|
} else {
|
|
|
|
api = "public"
|
|
|
|
v = sdkVersion
|
|
|
|
}
|
|
|
|
dir := filepath.Join("prebuilts", "sdk", v, api)
|
|
|
|
jar := filepath.Join(dir, module.BaseModuleName()+".jar")
|
|
|
|
jarPath := android.ExistentPathForSource(ctx, jar)
|
2019-02-28 07:01:28 +01:00
|
|
|
if !jarPath.Valid() {
|
|
|
|
ctx.PropertyErrorf("sdk_library", "invalid sdk version %q, %q does not exist", v, jar)
|
|
|
|
return nil
|
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
return android.Paths{jarPath.Path()}
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// to satisfy SdkLibraryDependency interface
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths {
|
2018-04-10 06:07:10 +02:00
|
|
|
// This module is just a wrapper for the stubs.
|
2019-04-18 23:27:12 +02:00
|
|
|
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
2018-10-19 06:46:09 +02:00
|
|
|
return module.PrebuiltJars(ctx, sdkVersion)
|
2018-04-10 06:07:10 +02:00
|
|
|
} else {
|
2018-10-19 06:46:09 +02:00
|
|
|
if strings.HasPrefix(sdkVersion, "system_") {
|
|
|
|
return module.systemApiStubsPath
|
|
|
|
} else if sdkVersion == "" {
|
|
|
|
return module.Library.HeaderJars()
|
|
|
|
} else {
|
|
|
|
return module.publicApiStubsPath
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 09:16:44 +02:00
|
|
|
// to satisfy SdkLibraryDependency interface
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths {
|
2018-07-13 09:16:44 +02:00
|
|
|
// This module is just a wrapper for the stubs.
|
2019-04-18 23:27:12 +02:00
|
|
|
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
2018-10-19 06:46:09 +02:00
|
|
|
return module.PrebuiltJars(ctx, sdkVersion)
|
2018-07-13 09:16:44 +02:00
|
|
|
} else {
|
2018-10-19 06:46:09 +02:00
|
|
|
if strings.HasPrefix(sdkVersion, "system_") {
|
|
|
|
return module.systemApiStubsImplPath
|
|
|
|
} else if sdkVersion == "" {
|
|
|
|
return module.Library.ImplementationJars()
|
|
|
|
} else {
|
|
|
|
return module.publicApiStubsImplPath
|
|
|
|
}
|
2018-07-13 09:16:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 20:22:08 +01:00
|
|
|
var javaSdkLibrariesKey = android.NewOnceKey("javaSdkLibraries")
|
|
|
|
|
2018-04-23 14:41:26 +02:00
|
|
|
func javaSdkLibraries(config android.Config) *[]string {
|
2019-02-04 20:22:08 +01:00
|
|
|
return config.Once(javaSdkLibrariesKey, func() interface{} {
|
2018-04-23 14:41:26 +02:00
|
|
|
return &[]string{}
|
|
|
|
}).(*[]string)
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:07:10 +02:00
|
|
|
// 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
|
2019-04-16 23:43:28 +02:00
|
|
|
func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
|
2019-03-21 09:43:49 +01:00
|
|
|
if len(module.Library.Module.properties.Srcs) == 0 {
|
2019-02-08 13:00:45 +01:00
|
|
|
mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
|
|
|
|
}
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-03-21 09:43:49 +01:00
|
|
|
if len(module.sdkLibraryProperties.Api_packages) == 0 {
|
2019-02-08 13:00:45 +01:00
|
|
|
mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
|
|
|
|
}
|
2019-03-18 02:19:51 +01:00
|
|
|
|
|
|
|
missing_current_api := false
|
|
|
|
|
|
|
|
for _, scope := range []string{"", "system-", "test-"} {
|
|
|
|
for _, api := range []string{"current.txt", "removed.txt"} {
|
|
|
|
path := path.Join(mctx.ModuleDir(), "api", scope+api)
|
|
|
|
p := android.ExistentPathForSource(mctx, path)
|
|
|
|
if !p.Valid() {
|
|
|
|
mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
|
|
|
|
missing_current_api = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if missing_current_api {
|
|
|
|
script := "build/soong/scripts/gen-java-current-api-files.sh"
|
|
|
|
p := android.ExistentPathForSource(mctx, script)
|
|
|
|
|
|
|
|
if !p.Valid() {
|
|
|
|
panic(fmt.Sprintf("script file %s doesn't exist", script))
|
|
|
|
}
|
|
|
|
|
|
|
|
mctx.ModuleErrorf("One or more current api files are missing. "+
|
|
|
|
"You can update them by:\n"+
|
|
|
|
"%s %q && m update-api", script, mctx.ModuleDir())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
// for public API stubs
|
|
|
|
module.createStubsLibrary(mctx, apiScopePublic)
|
|
|
|
module.createDocs(mctx, apiScopePublic)
|
2018-04-27 09:29:21 +02:00
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
if !Bool(module.properties.No_standard_libs) {
|
|
|
|
// for system API stubs
|
|
|
|
module.createStubsLibrary(mctx, apiScopeSystem)
|
|
|
|
module.createDocs(mctx, apiScopeSystem)
|
2018-04-10 06:07:10 +02:00
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
// for test API stubs
|
|
|
|
module.createStubsLibrary(mctx, apiScopeTest)
|
|
|
|
module.createDocs(mctx, apiScopeTest)
|
2018-04-23 14:41:26 +02:00
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
// for runtime
|
|
|
|
module.createXmlFile(mctx)
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
2019-02-08 13:00:45 +01:00
|
|
|
|
|
|
|
// 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())
|
2018-04-10 06:07:10 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func (module *SdkLibrary) InitSdkLibraryProperties() {
|
2018-10-19 06:46:09 +02:00
|
|
|
module.AddProperties(
|
|
|
|
&module.sdkLibraryProperties,
|
|
|
|
&module.Library.Module.properties,
|
|
|
|
&module.Library.Module.dexpreoptProperties,
|
|
|
|
&module.Library.Module.deviceProperties,
|
|
|
|
&module.Library.Module.protoProperties,
|
|
|
|
)
|
|
|
|
|
|
|
|
module.Library.Module.properties.Installable = proptools.BoolPtr(true)
|
|
|
|
module.Library.Module.deviceProperties.IsSDKLibrary = true
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
2018-10-19 06:46:09 +02:00
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func SdkLibraryFactory() android.Module {
|
|
|
|
module := &SdkLibrary{}
|
|
|
|
module.InitSdkLibraryProperties()
|
2018-10-19 06:46:09 +02:00
|
|
|
InitJavaModule(module, android.HostAndDeviceSupported)
|
2019-04-16 23:43:28 +02:00
|
|
|
android.AddLoadHook(module, func(ctx android.LoadHookContext) { module.CreateInternalModules(ctx) })
|
2018-04-10 06:07:10 +02:00
|
|
|
return module
|
|
|
|
}
|
2019-04-17 20:11:46 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
}
|