Merge "Parameterize java_sdk_library by api scope" am: b8e5c68fef
Change-Id: I7006e9c7b9192c51458539fa515acf7082f42105
This commit is contained in:
@@ -16,6 +16,7 @@ package java
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
@@ -24,6 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,21 +55,96 @@ const (
|
|||||||
`</permissions>\n`
|
`</permissions>\n`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A tag to associated a dependency with a specific api scope.
|
||||||
|
type scopeDependencyTag struct {
|
||||||
|
blueprint.BaseDependencyTag
|
||||||
|
name string
|
||||||
|
apiScope *apiScope
|
||||||
|
}
|
||||||
|
|
||||||
|
// Provides information about an api scope, e.g. public, system, test.
|
||||||
|
type apiScope struct {
|
||||||
|
// The name of the api scope, e.g. public, system, test
|
||||||
|
name string
|
||||||
|
|
||||||
|
// The tag to use to depend on the stubs library module.
|
||||||
|
stubsTag scopeDependencyTag
|
||||||
|
|
||||||
|
// The tag to use to depend on the stubs
|
||||||
|
apiFileTag scopeDependencyTag
|
||||||
|
|
||||||
|
// The scope specific prefix to add to the api file base of "current.txt" or "removed.txt".
|
||||||
|
apiFilePrefix string
|
||||||
|
|
||||||
|
// The scope specific prefix to add to the sdk library module name to construct a scope specific
|
||||||
|
// module name.
|
||||||
|
moduleSuffix string
|
||||||
|
|
||||||
|
// The suffix to add to the make variable that references the location of the api file.
|
||||||
|
apiFileMakeVariableSuffix string
|
||||||
|
|
||||||
|
// SDK version that the stubs library is built against. Note that this is always
|
||||||
|
// *current. Older stubs library built with a numbered SDK version is created from
|
||||||
|
// the prebuilt jar.
|
||||||
|
sdkVersion string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize a scope, creating and adding appropriate dependency tags
|
||||||
|
func initApiScope(scope *apiScope) *apiScope {
|
||||||
|
//apiScope := &scope
|
||||||
|
scope.stubsTag = scopeDependencyTag{
|
||||||
|
name: scope.name + "-stubs",
|
||||||
|
apiScope: scope,
|
||||||
|
}
|
||||||
|
scope.apiFileTag = scopeDependencyTag{
|
||||||
|
name: scope.name + "-api",
|
||||||
|
apiScope: scope,
|
||||||
|
}
|
||||||
|
return scope
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scope *apiScope) stubsModuleName(baseName string) string {
|
||||||
|
return baseName + sdkStubsLibrarySuffix + scope.moduleSuffix
|
||||||
|
}
|
||||||
|
|
||||||
|
func (scope *apiScope) docsModuleName(baseName string) string {
|
||||||
|
return baseName + sdkDocsSuffix + scope.moduleSuffix
|
||||||
|
}
|
||||||
|
|
||||||
|
type apiScopes []*apiScope
|
||||||
|
|
||||||
|
func (scopes apiScopes) Strings(accessor func(*apiScope) string) []string {
|
||||||
|
var list []string
|
||||||
|
for _, scope := range scopes {
|
||||||
|
list = append(list, accessor(scope))
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
publicApiStubsTag = dependencyTag{name: "public"}
|
apiScopePublic = initApiScope(&apiScope{
|
||||||
systemApiStubsTag = dependencyTag{name: "system"}
|
name: "public",
|
||||||
testApiStubsTag = dependencyTag{name: "test"}
|
sdkVersion: "current",
|
||||||
publicApiFileTag = dependencyTag{name: "publicApi"}
|
})
|
||||||
systemApiFileTag = dependencyTag{name: "systemApi"}
|
apiScopeSystem = initApiScope(&apiScope{
|
||||||
testApiFileTag = dependencyTag{name: "testApi"}
|
name: "system",
|
||||||
)
|
apiFilePrefix: "system-",
|
||||||
|
moduleSuffix: sdkSystemApiSuffix,
|
||||||
type apiScope int
|
apiFileMakeVariableSuffix: "_SYSTEM",
|
||||||
|
sdkVersion: "system_current",
|
||||||
const (
|
})
|
||||||
apiScopePublic apiScope = iota
|
apiScopeTest = initApiScope(&apiScope{
|
||||||
apiScopeSystem
|
name: "test",
|
||||||
apiScopeTest
|
apiFilePrefix: "test-",
|
||||||
|
moduleSuffix: sdkTestApiSuffix,
|
||||||
|
apiFileMakeVariableSuffix: "_TEST",
|
||||||
|
sdkVersion: "test_current",
|
||||||
|
})
|
||||||
|
allApiScopes = apiScopes{
|
||||||
|
apiScopePublic,
|
||||||
|
apiScopeSystem,
|
||||||
|
apiScopeTest,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -142,22 +219,18 @@ type sdkLibraryProperties struct {
|
|||||||
//Html_doc *bool
|
//Html_doc *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type scopePaths struct {
|
||||||
|
stubsHeaderPath android.Paths
|
||||||
|
stubsImplPath android.Paths
|
||||||
|
apiFilePath android.Path
|
||||||
|
}
|
||||||
|
|
||||||
type SdkLibrary struct {
|
type SdkLibrary struct {
|
||||||
Library
|
Library
|
||||||
|
|
||||||
sdkLibraryProperties sdkLibraryProperties
|
sdkLibraryProperties sdkLibraryProperties
|
||||||
|
|
||||||
publicApiStubsPath android.Paths
|
scopePaths map[*apiScope]*scopePaths
|
||||||
systemApiStubsPath android.Paths
|
|
||||||
testApiStubsPath android.Paths
|
|
||||||
|
|
||||||
publicApiStubsImplPath android.Paths
|
|
||||||
systemApiStubsImplPath android.Paths
|
|
||||||
testApiStubsImplPath android.Paths
|
|
||||||
|
|
||||||
publicApiFilePath android.Path
|
|
||||||
systemApiFilePath android.Path
|
|
||||||
testApiFilePath android.Path
|
|
||||||
|
|
||||||
permissionsFile android.Path
|
permissionsFile android.Path
|
||||||
}
|
}
|
||||||
@@ -165,21 +238,36 @@ type SdkLibrary struct {
|
|||||||
var _ Dependency = (*SdkLibrary)(nil)
|
var _ Dependency = (*SdkLibrary)(nil)
|
||||||
var _ SdkLibraryDependency = (*SdkLibrary)(nil)
|
var _ SdkLibraryDependency = (*SdkLibrary)(nil)
|
||||||
|
|
||||||
|
func (module *SdkLibrary) getActiveApiScopes() apiScopes {
|
||||||
|
if module.sdkLibraryProperties.Has_system_and_test_apis {
|
||||||
|
return allApiScopes
|
||||||
|
} else {
|
||||||
|
return apiScopes{apiScopePublic}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (module *SdkLibrary) getScopePaths(scope *apiScope) *scopePaths {
|
||||||
|
if module.scopePaths == nil {
|
||||||
|
module.scopePaths = make(map[*apiScope]*scopePaths)
|
||||||
|
}
|
||||||
|
paths := module.scopePaths[scope]
|
||||||
|
if paths == nil {
|
||||||
|
paths = &scopePaths{}
|
||||||
|
module.scopePaths[scope] = paths
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
|
useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks()
|
||||||
// Add dependencies to the stubs library
|
for _, apiScope := range module.getActiveApiScopes() {
|
||||||
if useBuiltStubs {
|
// Add dependencies to the stubs library
|
||||||
ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
|
|
||||||
}
|
|
||||||
ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
|
|
||||||
|
|
||||||
if module.sdkLibraryProperties.Has_system_and_test_apis {
|
|
||||||
if useBuiltStubs {
|
if useBuiltStubs {
|
||||||
ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
|
ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope))
|
||||||
ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
|
|
||||||
}
|
}
|
||||||
ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
|
|
||||||
ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest))
|
ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.docsName(apiScope))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.Library.deps(ctx)
|
module.Library.deps(ctx)
|
||||||
@@ -194,34 +282,26 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
|
|||||||
module.buildPermissionsFile(ctx)
|
module.buildPermissionsFile(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 depended upon from others via "libs" property,
|
||||||
// the recorded paths will be returned depending on the link type of the caller.
|
// the recorded paths will be returned depending on the link type of the caller.
|
||||||
ctx.VisitDirectDeps(func(to android.Module) {
|
ctx.VisitDirectDeps(func(to android.Module) {
|
||||||
otherName := ctx.OtherModuleName(to)
|
otherName := ctx.OtherModuleName(to)
|
||||||
tag := ctx.OtherModuleDependencyTag(to)
|
tag := ctx.OtherModuleDependencyTag(to)
|
||||||
|
|
||||||
if lib, ok := to.(Dependency); ok {
|
if lib, ok := to.(Dependency); ok {
|
||||||
switch tag {
|
if scopeTag, ok := tag.(scopeDependencyTag); ok {
|
||||||
case publicApiStubsTag:
|
apiScope := scopeTag.apiScope
|
||||||
module.publicApiStubsPath = lib.HeaderJars()
|
scopePaths := module.getScopePaths(apiScope)
|
||||||
module.publicApiStubsImplPath = lib.ImplementationJars()
|
scopePaths.stubsHeaderPath = lib.HeaderJars()
|
||||||
case systemApiStubsTag:
|
scopePaths.stubsImplPath = lib.ImplementationJars()
|
||||||
module.systemApiStubsPath = lib.HeaderJars()
|
|
||||||
module.systemApiStubsImplPath = lib.ImplementationJars()
|
|
||||||
case testApiStubsTag:
|
|
||||||
module.testApiStubsPath = lib.HeaderJars()
|
|
||||||
module.testApiStubsImplPath = lib.ImplementationJars()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if doc, ok := to.(ApiFilePath); ok {
|
if doc, ok := to.(ApiFilePath); ok {
|
||||||
switch tag {
|
if scopeTag, ok := tag.(scopeDependencyTag); ok {
|
||||||
case publicApiFileTag:
|
apiScope := scopeTag.apiScope
|
||||||
module.publicApiFilePath = doc.ApiFilePath()
|
scopePaths := module.getScopePaths(apiScope)
|
||||||
case systemApiFileTag:
|
scopePaths.apiFilePath = doc.ApiFilePath()
|
||||||
module.systemApiFilePath = doc.ApiFilePath()
|
} else {
|
||||||
case testApiFileTag:
|
|
||||||
module.testApiFilePath = doc.ApiFilePath()
|
|
||||||
default:
|
|
||||||
ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
|
ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,42 +353,23 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
owner = "android"
|
owner = "android"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create dist rules to install the stubs libs to the dist dir
|
|
||||||
if len(module.publicApiStubsPath) == 1 {
|
// Create dist rules to install the stubs libs and api files to the dist dir
|
||||||
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
for _, apiScope := range module.getActiveApiScopes() {
|
||||||
module.publicApiStubsImplPath.Strings()[0]+
|
if scopePaths, ok := module.scopePaths[apiScope]; ok {
|
||||||
":"+path.Join("apistubs", owner, "public",
|
if len(scopePaths.stubsHeaderPath) == 1 {
|
||||||
module.BaseModuleName()+".jar")+")")
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
||||||
}
|
scopePaths.stubsImplPath.Strings()[0]+
|
||||||
if len(module.systemApiStubsPath) == 1 {
|
":"+path.Join("apistubs", owner, apiScope.name,
|
||||||
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
module.BaseModuleName()+".jar")+")")
|
||||||
module.systemApiStubsImplPath.Strings()[0]+
|
}
|
||||||
":"+path.Join("apistubs", owner, "system",
|
if scopePaths.apiFilePath != nil {
|
||||||
module.BaseModuleName()+".jar")+")")
|
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
||||||
}
|
scopePaths.apiFilePath.String()+
|
||||||
if len(module.testApiStubsPath) == 1 {
|
":"+path.Join("apistubs", owner, apiScope.name, "api",
|
||||||
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
|
module.BaseModuleName()+".txt")+")")
|
||||||
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")+")")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -317,27 +378,13 @@ func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Module name of the stubs library
|
// Module name of the stubs library
|
||||||
func (module *SdkLibrary) stubsName(apiScope apiScope) string {
|
func (module *SdkLibrary) stubsName(apiScope *apiScope) string {
|
||||||
stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
|
return apiScope.stubsModuleName(module.BaseModuleName())
|
||||||
switch apiScope {
|
|
||||||
case apiScopeSystem:
|
|
||||||
stubsName = stubsName + sdkSystemApiSuffix
|
|
||||||
case apiScopeTest:
|
|
||||||
stubsName = stubsName + sdkTestApiSuffix
|
|
||||||
}
|
|
||||||
return stubsName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module name of the docs
|
// Module name of the docs
|
||||||
func (module *SdkLibrary) docsName(apiScope apiScope) string {
|
func (module *SdkLibrary) docsName(apiScope *apiScope) string {
|
||||||
docsName := module.BaseModuleName() + sdkDocsSuffix
|
return apiScope.docsModuleName(module.BaseModuleName())
|
||||||
switch apiScope {
|
|
||||||
case apiScopeSystem:
|
|
||||||
docsName = docsName + sdkSystemApiSuffix
|
|
||||||
case apiScopeTest:
|
|
||||||
docsName = docsName + sdkTestApiSuffix
|
|
||||||
}
|
|
||||||
return docsName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module name of the runtime implementation library
|
// Module name of the runtime implementation library
|
||||||
@@ -371,28 +418,12 @@ func (module *SdkLibrary) xmlFileName() string {
|
|||||||
return module.BaseModuleName() + sdkXmlFileSuffix
|
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.
|
|
||||||
func (module *SdkLibrary) sdkVersionForScope(apiScope apiScope) string {
|
|
||||||
switch apiScope {
|
|
||||||
case apiScopePublic:
|
|
||||||
return "current"
|
|
||||||
case apiScopeSystem:
|
|
||||||
return "system_current"
|
|
||||||
case apiScopeTest:
|
|
||||||
return "test_current"
|
|
||||||
default:
|
|
||||||
return "current"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the sdk version for use when compiling the stubs library.
|
// Get the sdk version for use when compiling the stubs library.
|
||||||
func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) string {
|
func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string {
|
||||||
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
|
sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library))
|
||||||
if sdkDep.hasStandardLibs() {
|
if sdkDep.hasStandardLibs() {
|
||||||
// If building against a standard sdk then use the sdk version appropriate for the scope.
|
// If building against a standard sdk then use the sdk version appropriate for the scope.
|
||||||
return module.sdkVersionForScope(apiScope)
|
return apiScope.sdkVersion
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, use no system module.
|
// Otherwise, use no system module.
|
||||||
return "none"
|
return "none"
|
||||||
@@ -402,47 +433,20 @@ func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext
|
|||||||
// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
|
// $(INTERNAL_PLATFORM_<apiTagName>_API_FILE) points to the generated
|
||||||
// api file for the current source
|
// api file for the current source
|
||||||
// TODO: remove this when apicheck is done in soong
|
// TODO: remove this when apicheck is done in soong
|
||||||
func (module *SdkLibrary) apiTagName(apiScope apiScope) string {
|
func (module *SdkLibrary) apiTagName(apiScope *apiScope) string {
|
||||||
apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
|
return strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) + apiScope.apiFileMakeVariableSuffix
|
||||||
switch apiScope {
|
|
||||||
case apiScopeSystem:
|
|
||||||
apiTagName = apiTagName + "_SYSTEM"
|
|
||||||
case apiScopeTest:
|
|
||||||
apiTagName = apiTagName + "_TEST"
|
|
||||||
}
|
|
||||||
return apiTagName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (module *SdkLibrary) latestApiFilegroupName(apiScope apiScope) string {
|
func (module *SdkLibrary) latestApiFilegroupName(apiScope *apiScope) string {
|
||||||
name := ":" + module.BaseModuleName() + ".api."
|
return ":" + module.BaseModuleName() + ".api." + apiScope.name + ".latest"
|
||||||
switch apiScope {
|
|
||||||
case apiScopePublic:
|
|
||||||
name = name + "public"
|
|
||||||
case apiScopeSystem:
|
|
||||||
name = name + "system"
|
|
||||||
case apiScopeTest:
|
|
||||||
name = name + "test"
|
|
||||||
}
|
|
||||||
name = name + ".latest"
|
|
||||||
return name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope apiScope) string {
|
func (module *SdkLibrary) latestRemovedApiFilegroupName(apiScope *apiScope) string {
|
||||||
name := ":" + module.BaseModuleName() + "-removed.api."
|
return ":" + module.BaseModuleName() + "-removed.api." + apiScope.name + ".latest"
|
||||||
switch apiScope {
|
|
||||||
case apiScopePublic:
|
|
||||||
name = name + "public"
|
|
||||||
case apiScopeSystem:
|
|
||||||
name = name + "system"
|
|
||||||
case apiScopeTest:
|
|
||||||
name = name + "test"
|
|
||||||
}
|
|
||||||
name = name + ".latest"
|
|
||||||
return name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a static java library that has API stubs
|
// Creates a static java library that has API stubs
|
||||||
func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope apiScope) {
|
func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) {
|
||||||
props := struct {
|
props := struct {
|
||||||
Name *string
|
Name *string
|
||||||
Srcs []string
|
Srcs []string
|
||||||
@@ -505,7 +509,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc
|
|||||||
|
|
||||||
// Creates a droiddoc module that creates stubs source files from the given full source
|
// Creates a droiddoc module that creates stubs source files from the given full source
|
||||||
// files
|
// files
|
||||||
func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope apiScope) {
|
func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiScope *apiScope) {
|
||||||
props := struct {
|
props := struct {
|
||||||
Name *string
|
Name *string
|
||||||
Srcs []string
|
Srcs []string
|
||||||
@@ -590,16 +594,8 @@ func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiSc
|
|||||||
// List of APIs identified from the provided source files are created. They are later
|
// 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
|
// 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.
|
// last-released (a.k.a numbered) list of API.
|
||||||
currentApiFileName := "current.txt"
|
currentApiFileName := apiScope.apiFilePrefix + "current.txt"
|
||||||
removedApiFileName := "removed.txt"
|
removedApiFileName := apiScope.apiFilePrefix + "removed.txt"
|
||||||
switch apiScope {
|
|
||||||
case apiScopeSystem:
|
|
||||||
currentApiFileName = "system-" + currentApiFileName
|
|
||||||
removedApiFileName = "system-" + removedApiFileName
|
|
||||||
case apiScopeTest:
|
|
||||||
currentApiFileName = "test-" + currentApiFileName
|
|
||||||
removedApiFileName = "test-" + removedApiFileName
|
|
||||||
}
|
|
||||||
apiDir := module.getApiDir()
|
apiDir := module.getApiDir()
|
||||||
currentApiFileName = path.Join(apiDir, currentApiFileName)
|
currentApiFileName = path.Join(apiDir, currentApiFileName)
|
||||||
removedApiFileName = path.Join(apiDir, removedApiFileName)
|
removedApiFileName = path.Join(apiDir, removedApiFileName)
|
||||||
@@ -677,38 +673,48 @@ func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, s sdkSpec)
|
|||||||
return android.Paths{jarPath.Path()}
|
return android.Paths{jarPath.Path()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// to satisfy SdkLibraryDependency interface
|
func (module *SdkLibrary) sdkJars(
|
||||||
func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
ctx android.BaseModuleContext,
|
||||||
|
sdkVersion sdkSpec,
|
||||||
|
headerJars bool) android.Paths {
|
||||||
|
|
||||||
// This module is just a wrapper for the stubs.
|
// This module is just a wrapper for the stubs.
|
||||||
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
||||||
return module.PrebuiltJars(ctx, sdkVersion)
|
return module.PrebuiltJars(ctx, sdkVersion)
|
||||||
} else {
|
} else {
|
||||||
|
if !sdkVersion.specified() {
|
||||||
|
if headerJars {
|
||||||
|
return module.Library.HeaderJars()
|
||||||
|
} else {
|
||||||
|
return module.Library.ImplementationJars()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var paths *scopePaths
|
||||||
switch sdkVersion.kind {
|
switch sdkVersion.kind {
|
||||||
case sdkSystem:
|
case sdkSystem:
|
||||||
return module.systemApiStubsPath
|
paths = module.getScopePaths(apiScopeSystem)
|
||||||
case sdkPrivate:
|
case sdkPrivate:
|
||||||
return module.Library.HeaderJars()
|
return module.Library.HeaderJars()
|
||||||
default:
|
default:
|
||||||
return module.publicApiStubsPath
|
paths = module.getScopePaths(apiScopePublic)
|
||||||
|
}
|
||||||
|
|
||||||
|
if headerJars {
|
||||||
|
return paths.stubsHeaderPath
|
||||||
|
} else {
|
||||||
|
return paths.stubsImplPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// to satisfy SdkLibraryDependency interface
|
||||||
|
func (module *SdkLibrary) SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
||||||
|
return module.sdkJars(ctx, sdkVersion, true /*headerJars*/)
|
||||||
|
}
|
||||||
|
|
||||||
// to satisfy SdkLibraryDependency interface
|
// to satisfy SdkLibraryDependency interface
|
||||||
func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
func (module *SdkLibrary) SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths {
|
||||||
// This module is just a wrapper for the stubs.
|
return module.sdkJars(ctx, sdkVersion, false /*headerJars*/)
|
||||||
if ctx.Config().UnbundledBuildUsePrebuiltSdks() {
|
|
||||||
return module.PrebuiltJars(ctx, sdkVersion)
|
|
||||||
} else {
|
|
||||||
switch sdkVersion.kind {
|
|
||||||
case sdkSystem:
|
|
||||||
return module.systemApiStubsImplPath
|
|
||||||
case sdkPrivate:
|
|
||||||
return module.Library.ImplementationJars()
|
|
||||||
default:
|
|
||||||
return module.publicApiStubsImplPath
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (module *SdkLibrary) SetNoDist() {
|
func (module *SdkLibrary) SetNoDist() {
|
||||||
@@ -744,17 +750,14 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
|
|||||||
module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis
|
module.sdkLibraryProperties.Has_system_and_test_apis = hasSystemAndTestApis
|
||||||
module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
|
module.sdkLibraryProperties.No_dist = proptools.BoolPtr(!hasSystemAndTestApis)
|
||||||
|
|
||||||
scopes := []string{""}
|
|
||||||
if hasSystemAndTestApis {
|
|
||||||
scopes = append(scopes, "system-", "test-")
|
|
||||||
}
|
|
||||||
|
|
||||||
missing_current_api := false
|
missing_current_api := false
|
||||||
|
|
||||||
|
activeScopes := module.getActiveApiScopes()
|
||||||
|
|
||||||
apiDir := module.getApiDir()
|
apiDir := module.getApiDir()
|
||||||
for _, scope := range scopes {
|
for _, scope := range activeScopes {
|
||||||
for _, api := range []string{"current.txt", "removed.txt"} {
|
for _, api := range []string{"current.txt", "removed.txt"} {
|
||||||
path := path.Join(mctx.ModuleDir(), apiDir, scope+api)
|
path := path.Join(mctx.ModuleDir(), apiDir, scope.apiFilePrefix+api)
|
||||||
p := android.ExistentPathForSource(mctx, path)
|
p := android.ExistentPathForSource(mctx, path)
|
||||||
if !p.Valid() {
|
if !p.Valid() {
|
||||||
mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
|
mctx.ModuleErrorf("Current api file %#v doesn't exist", path)
|
||||||
@@ -774,22 +777,14 @@ func (module *SdkLibrary) CreateInternalModules(mctx android.LoadHookContext) {
|
|||||||
mctx.ModuleErrorf("One or more current api files are missing. "+
|
mctx.ModuleErrorf("One or more current api files are missing. "+
|
||||||
"You can update them by:\n"+
|
"You can update them by:\n"+
|
||||||
"%s %q %s && m update-api",
|
"%s %q %s && m update-api",
|
||||||
script, filepath.Join(mctx.ModuleDir(), apiDir), strings.Join(scopes, " "))
|
script, filepath.Join(mctx.ModuleDir(), apiDir),
|
||||||
|
strings.Join(activeScopes.Strings(func(s *apiScope) string { return s.apiFilePrefix }), " "))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// for public API stubs
|
for _, scope := range activeScopes {
|
||||||
module.createStubsLibrary(mctx, apiScopePublic)
|
module.createStubsLibrary(mctx, scope)
|
||||||
module.createStubsSources(mctx, apiScopePublic)
|
module.createStubsSources(mctx, scope)
|
||||||
|
|
||||||
if hasSystemAndTestApis {
|
|
||||||
// for system API stubs
|
|
||||||
module.createStubsLibrary(mctx, apiScopeSystem)
|
|
||||||
module.createStubsSources(mctx, apiScopeSystem)
|
|
||||||
|
|
||||||
// for test API stubs
|
|
||||||
module.createStubsLibrary(mctx, apiScopeTest)
|
|
||||||
module.createStubsSources(mctx, apiScopeTest)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
|
if !proptools.Bool(module.sdkLibraryProperties.Api_only) {
|
||||||
@@ -909,7 +904,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte
|
|||||||
|
|
||||||
func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (module *sdkLibraryImport) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
// Add dependencies to the prebuilt stubs library
|
// Add dependencies to the prebuilt stubs library
|
||||||
ctx.AddVariationDependencies(nil, publicApiStubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
|
ctx.AddVariationDependencies(nil, apiScopePublic.stubsTag, module.BaseModuleName()+sdkStubsLibrarySuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
@@ -918,7 +913,7 @@ func (module *sdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
|
|||||||
tag := ctx.OtherModuleDependencyTag(to)
|
tag := ctx.OtherModuleDependencyTag(to)
|
||||||
|
|
||||||
switch tag {
|
switch tag {
|
||||||
case publicApiStubsTag:
|
case apiScopePublic.stubsTag:
|
||||||
module.stubsPath = to.(Dependency).HeaderJars()
|
module.stubsPath = to.(Dependency).HeaderJars()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user