java_sdk_library supports test as another API scope

For each java_sdk_library module, three (possibly different) stubs libs
are created.

*.stubs: public APIs only
*.system.stubs: public APIs + @SystemApi
*.test.stubs: public APIs + @TestApi

Depending on the sdk_version (or LOCAL_SDK_VERSION) of the calling
module, stubs lib of the corresponding api scope is linked.

Bug: 77575606
Test: m -j
Change-Id: I1437c64460914dbfc349dbc31d6f3ef090f541e3
This commit is contained in:
Jiyong Park
2018-04-27 16:29:21 +09:00
parent 5a8d1bee89
commit df13054c2a

View File

@@ -31,6 +31,7 @@ import (
var ( var (
sdkStubsLibrarySuffix = ".stubs" sdkStubsLibrarySuffix = ".stubs"
sdkSystemApiSuffix = ".system" sdkSystemApiSuffix = ".system"
sdkTestApiSuffix = ".test"
sdkDocsSuffix = ".docs" sdkDocsSuffix = ".docs"
sdkImplLibrarySuffix = ".impl" sdkImplLibrarySuffix = ".impl"
sdkXmlFileSuffix = ".xml" sdkXmlFileSuffix = ".xml"
@@ -44,6 +45,15 @@ type stubsLibraryDependencyTag struct {
var ( var (
publicApiStubsTag = dependencyTag{name: "public"} publicApiStubsTag = dependencyTag{name: "public"}
systemApiStubsTag = dependencyTag{name: "system"} systemApiStubsTag = dependencyTag{name: "system"}
testApiStubsTag = dependencyTag{name: "test"}
)
type apiScope int
const (
apiScopePublic apiScope = iota
apiScopeSystem
apiScopeTest
) )
var ( var (
@@ -104,12 +114,14 @@ type sdkLibrary struct {
publicApiStubsPath android.Paths publicApiStubsPath android.Paths
systemApiStubsPath android.Paths systemApiStubsPath android.Paths
testApiStubsPath android.Paths
} }
func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
// Add dependencies to the stubs library // Add dependencies to the stubs library
ctx.AddDependency(ctx.Module(), publicApiStubsTag, module.stubsName(false)) ctx.AddDependency(ctx.Module(), publicApiStubsTag, module.stubsName(apiScopePublic))
ctx.AddDependency(ctx.Module(), systemApiStubsTag, module.stubsName(true)) ctx.AddDependency(ctx.Module(), systemApiStubsTag, module.stubsName(apiScopeSystem))
ctx.AddDependency(ctx.Module(), testApiStubsTag, module.stubsName(apiScopeTest))
} }
func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -126,6 +138,8 @@ func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
module.publicApiStubsPath = stubs.HeaderJars() module.publicApiStubsPath = stubs.HeaderJars()
case systemApiStubsTag: case systemApiStubsTag:
module.systemApiStubsPath = stubs.HeaderJars() module.systemApiStubsPath = stubs.HeaderJars()
case testApiStubsTag:
module.testApiStubsPath = stubs.HeaderJars()
default: 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)
} }
@@ -148,19 +162,25 @@ func (module *sdkLibrary) AndroidMk() android.AndroidMkData {
} }
// Module name of the stubs library // Module name of the stubs library
func (module *sdkLibrary) stubsName(forSystemApi bool) string { func (module *sdkLibrary) stubsName(apiScope apiScope) string {
stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
if forSystemApi { switch apiScope {
case apiScopeSystem:
stubsName = stubsName + sdkSystemApiSuffix stubsName = stubsName + sdkSystemApiSuffix
case apiScopeTest:
stubsName = stubsName + sdkTestApiSuffix
} }
return stubsName return stubsName
} }
// Module name of the docs // Module name of the docs
func (module *sdkLibrary) docsName(forSystemApi bool) string { func (module *sdkLibrary) docsName(apiScope apiScope) string {
docsName := module.BaseModuleName() + sdkDocsSuffix docsName := module.BaseModuleName() + sdkDocsSuffix
if forSystemApi { switch apiScope {
case apiScopeSystem:
docsName = docsName + sdkSystemApiSuffix docsName = docsName + sdkSystemApiSuffix
case apiScopeTest:
docsName = docsName + sdkTestApiSuffix
} }
return docsName return docsName
} }
@@ -191,10 +211,15 @@ func (module *sdkLibrary) xmlFileName() string {
// SDK version that the stubs library is built against. Note that this is always // 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 // *current. Older stubs library built with a numberd SDK version is created from
// the prebuilt jar. // the prebuilt jar.
func (module *sdkLibrary) sdkVersion(forSystemApi bool) string { func (module *sdkLibrary) sdkVersion(apiScope apiScope) string {
if forSystemApi { switch apiScope {
case apiScopePublic:
return "current"
case apiScopeSystem:
return "system_current" return "system_current"
} else { case apiScopeTest:
return "test_current"
default:
return "current" return "current"
} }
} }
@@ -202,10 +227,13 @@ func (module *sdkLibrary) sdkVersion(forSystemApi bool) string {
// $(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(forSystemApi bool) string { func (module *sdkLibrary) apiTagName(apiScope apiScope) string {
apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1) apiTagName := strings.Replace(strings.ToUpper(module.BaseModuleName()), ".", "_", -1)
if forSystemApi { switch apiScope {
case apiScopeSystem:
apiTagName = apiTagName + "_SYSTEM" apiTagName = apiTagName + "_SYSTEM"
case apiScopeTest:
apiTagName = apiTagName + "_TEST"
} }
return apiTagName return apiTagName
} }
@@ -213,11 +241,14 @@ func (module *sdkLibrary) apiTagName(forSystemApi bool) string {
// returns the path (relative to this module) to the API txt file. Files are located // returns the path (relative to this module) to the API txt file. Files are located
// ./<api_dir>/<api_level>.txt where <api_level> is either current, system-current, removed, // ./<api_dir>/<api_level>.txt where <api_level> is either current, system-current, removed,
// or system-removed. // or system-removed.
func (module *sdkLibrary) apiFilePath(apiLevel string, forSystemApi bool) string { func (module *sdkLibrary) apiFilePath(apiLevel string, apiScope apiScope) string {
apiDir := "api" apiDir := "api"
apiFile := apiLevel apiFile := apiLevel
if forSystemApi { switch apiScope {
case apiScopeSystem:
apiFile = "system-" + apiFile apiFile = "system-" + apiFile
case apiScopeTest:
apiFile = "test-" + apiFile
} }
apiFile = apiFile + ".txt" apiFile = apiFile + ".txt"
@@ -225,7 +256,7 @@ func (module *sdkLibrary) apiFilePath(apiLevel string, forSystemApi bool) string
} }
// Creates a static java library that has API stubs // Creates a static java library that has API stubs
func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, forSystemApi bool) { func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext, apiScope apiScope) {
props := struct { props := struct {
Name *string Name *string
Srcs []string Srcs []string
@@ -243,10 +274,10 @@ func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext,
} }
}{} }{}
props.Name = proptools.StringPtr(module.stubsName(forSystemApi)) props.Name = proptools.StringPtr(module.stubsName(apiScope))
// sources are generated from the droiddoc // sources are generated from the droiddoc
props.Srcs = []string{":" + module.docsName(forSystemApi)} props.Srcs = []string{":" + module.docsName(apiScope)}
props.Sdk_version = proptools.StringPtr(module.sdkVersion(forSystemApi)) props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope))
// Unbundled apps will use the prebult one from /prebuilts/sdk // Unbundled apps will use the prebult one from /prebuilts/sdk
props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
@@ -264,7 +295,7 @@ func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext,
// 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) createDocs(mctx android.TopDownMutatorContext, forSystemApi bool) { func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) {
props := struct { props := struct {
Name *string Name *string
Srcs []string Srcs []string
@@ -280,7 +311,7 @@ func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, forSyst
Removed_api_filename *string Removed_api_filename *string
}{} }{}
props.Name = proptools.StringPtr(module.docsName(forSystemApi)) props.Name = proptools.StringPtr(module.docsName(apiScope))
props.Srcs = module.properties.Srcs props.Srcs = module.properties.Srcs
props.Custom_template = proptools.StringPtr("droiddoc-templates-sdk") props.Custom_template = proptools.StringPtr("droiddoc-templates-sdk")
props.Installable = proptools.BoolPtr(false) props.Installable = proptools.BoolPtr(false)
@@ -289,8 +320,11 @@ func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, forSyst
droiddocArgs := " -hide 110 -hide 111 -hide 113 -hide 121 -hide 125 -hide 126 -hide 127 -hide 128" + droiddocArgs := " -hide 110 -hide 111 -hide 113 -hide 121 -hide 125 -hide 126 -hide 127 -hide 128" +
" -stubpackages " + strings.Join(module.properties.Api_packages, ":") + " -stubpackages " + strings.Join(module.properties.Api_packages, ":") +
" -nodocs" " -nodocs"
if forSystemApi { switch apiScope {
case apiScopeSystem:
droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi" droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.SystemApi"
case apiScopeTest:
droiddocArgs = droiddocArgs + " -showAnnotation android.annotation.TestApi"
} }
props.Args = proptools.StringPtr(droiddocArgs) props.Args = proptools.StringPtr(droiddocArgs)
@@ -300,13 +334,17 @@ func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, forSyst
// TODO: If any incompatible change is detected, break the build // TODO: If any incompatible change is detected, break the build
currentApiFileName := "current.txt" currentApiFileName := "current.txt"
removedApiFileName := "removed.txt" removedApiFileName := "removed.txt"
if forSystemApi { switch apiScope {
case apiScopeSystem:
currentApiFileName = "system-" + currentApiFileName currentApiFileName = "system-" + currentApiFileName
removedApiFileName = "system-" + removedApiFileName removedApiFileName = "system-" + removedApiFileName
case apiScopeTest:
currentApiFileName = "test-" + currentApiFileName
removedApiFileName = "test-" + removedApiFileName
} }
currentApiFileName = path.Join("api", currentApiFileName) currentApiFileName = path.Join("api", currentApiFileName)
removedApiFileName = path.Join("api", removedApiFileName) removedApiFileName = path.Join("api", removedApiFileName)
props.Api_tag_name = proptools.StringPtr(module.apiTagName(forSystemApi)) props.Api_tag_name = proptools.StringPtr(module.apiTagName(apiScope))
// Note: the exact names of these two are not important because they are always // Note: the exact names of these two are not important because they are always
// referenced by the make variable $(INTERNAL_PLATFORM_<TAG_NAME>_API_FILE) // referenced by the make variable $(INTERNAL_PLATFORM_<TAG_NAME>_API_FILE)
props.Api_filename = proptools.StringPtr(currentApiFileName) props.Api_filename = proptools.StringPtr(currentApiFileName)
@@ -448,12 +486,16 @@ func javaSdkLibraries(config android.Config) *[]string {
func sdkLibraryMutator(mctx android.TopDownMutatorContext) { func sdkLibraryMutator(mctx android.TopDownMutatorContext) {
if module, ok := mctx.Module().(*sdkLibrary); ok { if module, ok := mctx.Module().(*sdkLibrary); ok {
// for public API stubs // for public API stubs
module.createStubsLibrary(mctx, false) module.createStubsLibrary(mctx, apiScopePublic)
module.createDocs(mctx, false) module.createDocs(mctx, apiScopePublic)
// for system API stubs // for system API stubs
module.createStubsLibrary(mctx, true) module.createStubsLibrary(mctx, apiScopeSystem)
module.createDocs(mctx, true) module.createDocs(mctx, apiScopeSystem)
// for test API stubs
module.createStubsLibrary(mctx, apiScopeTest)
module.createDocs(mctx, apiScopeTest)
// for runtime // for runtime
module.createXmlFile(mctx) module.createXmlFile(mctx)