Support core library

To support core library, "Openjdk9", "No_standard_libs" and metalava
properties are added to java_sdk_library.
If core_lib is true, dist paths are changed to
apistubs/core/....
impl library name is changed to {module_name}.jar instead of
{module_name}.impl.jar

Bug: 110404779
Test: m -j
Change-Id: Ieb6248ea714b4260333d8bf61573d4f3413f7f24
Merged-In: Ieb6248ea714b4260333d8bf61573d4f3413f7f24
(cherry picked from commit af4907fed7)
This commit is contained in:
Sundong Ahn 2018-10-19 13:46:09 +09:00 committed by Colin Cross
parent 63d91fad6a
commit 054b19a131
6 changed files with 226 additions and 232 deletions

View File

@ -22,6 +22,25 @@ import (
"android/soong/android" "android/soong/android"
) )
func (library *Library) AndroidMkHostDex(w io.Writer, name string, data android.AndroidMkData) {
if Bool(library.deviceProperties.Hostdex) && !library.Host() {
fmt.Fprintln(w, "include $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
if library.installFile == nil {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
}
if library.dexJarFile != nil {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
}
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
}
}
func (library *Library) AndroidMk() android.AndroidMkData { func (library *Library) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{ return android.AndroidMkData{
Class: "JAVA_LIBRARIES", Class: "JAVA_LIBRARIES",
@ -69,23 +88,7 @@ func (library *Library) AndroidMk() android.AndroidMkData {
}, },
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
android.WriteAndroidMkData(w, data) android.WriteAndroidMkData(w, data)
library.AndroidMkHostDex(w, name, data)
if Bool(library.deviceProperties.Hostdex) && !library.Host() {
fmt.Fprintln(w, "include $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
if library.installFile == nil {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
}
if library.dexJarFile != nil {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
}
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
}
}, },
} }
} }

View File

@ -629,14 +629,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps {
case Dependency: case Dependency:
deps.classpath = append(deps.classpath, dep.HeaderJars()...) deps.classpath = append(deps.classpath, dep.HeaderJars()...)
case SdkLibraryDependency: case SdkLibraryDependency:
sdkVersion := j.sdkVersion() deps.classpath = append(deps.classpath, dep.ImplementationJars(ctx, j.sdkVersion())...)
linkType := javaSdk
if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") {
linkType = javaSystem
} else if sdkVersion == "" {
linkType = javaPlatform
}
deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...)
case android.SourceFileProducer: case android.SourceFileProducer:
checkProducesJars(ctx, dep) checkProducesJars(ctx, dep)
deps.classpath = append(deps.classpath, dep.Srcs()...) deps.classpath = append(deps.classpath, dep.Srcs()...)

View File

@ -336,8 +336,8 @@ type Dependency interface {
} }
type SdkLibraryDependency interface { type SdkLibraryDependency interface {
HeaderJars(linkType linkType) android.Paths HeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths
ImplementationJars(linkType linkType) android.Paths ImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths
} }
type SrcDependency interface { type SrcDependency interface {
@ -729,8 +729,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
case SdkLibraryDependency: case SdkLibraryDependency:
switch tag { switch tag {
case libTag: case libTag:
linkType, _ := getLinkType(j, ctx.ModuleName()) deps.classpath = append(deps.classpath, dep.HeaderJars(ctx, j.sdkVersion())...)
deps.classpath = append(deps.classpath, dep.HeaderJars(linkType)...)
// names of sdk libs that are directly depended are exported // names of sdk libs that are directly depended are exported
j.exportedSdkLibs = append(j.exportedSdkLibs, otherName) j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
default: default:
@ -748,6 +747,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...) deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
case android.DefaultsDepTag, android.SourceDepTag: case android.DefaultsDepTag, android.SourceDepTag:
// Nothing to do // Nothing to do
case publicApiFileTag, systemApiFileTag, testApiFileTag:
// Nothing to do
default: default:
ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName) ctx.ModuleErrorf("dependency on genrule %q may only be in srcs, libs, or static_libs", otherName)
} }

View File

@ -861,7 +861,6 @@ func TestJavaSdkLibrary(t *testing.T) {
ctx.ModuleForTests("foo"+sdkDocsSuffix, "android_common") ctx.ModuleForTests("foo"+sdkDocsSuffix, "android_common")
ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkSystemApiSuffix, "android_common") ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkSystemApiSuffix, "android_common")
ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkTestApiSuffix, "android_common") ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkTestApiSuffix, "android_common")
ctx.ModuleForTests("foo"+sdkImplLibrarySuffix, "android_common")
ctx.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common") ctx.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common")
ctx.ModuleForTests("foo.api.public.28", "") ctx.ModuleForTests("foo.api.public.28", "")
ctx.ModuleForTests("foo.api.system.28", "") ctx.ModuleForTests("foo.api.system.28", "")
@ -874,9 +873,9 @@ func TestJavaSdkLibrary(t *testing.T) {
"foo.stubs.system.jar") "foo.stubs.system.jar")
} }
// ... and not to the impl lib // ... and not to the impl lib
if strings.Contains(bazJavac.Args["classpath"], "foo.impl.jar") { if strings.Contains(bazJavac.Args["classpath"], "foo.jar") {
t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"],
"foo.impl.jar") "foo.jar")
} }
// test if baz is not linked to the system variant of foo // test if baz is not linked to the system variant of foo
if strings.Contains(bazJavac.Args["classpath"], "foo.stubs.jar") { if strings.Contains(bazJavac.Args["classpath"], "foo.stubs.jar") {

View File

@ -17,7 +17,6 @@ package java
import ( import (
"android/soong/android" "android/soong/android"
"sort" "sort"
"strconv"
"strings" "strings"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@ -66,14 +65,9 @@ func parseJarPath(ctx android.BaseModuleContext, path string) (module string, ap
return return
} }
func parseApiFilePath(ctx android.BaseModuleContext, path string) (module string, apiver int, scope string) { func parseApiFilePath(ctx android.BaseModuleContext, path string) (module string, apiver string, scope string) {
elements := strings.Split(path, "/") elements := strings.Split(path, "/")
ver, err := strconv.Atoi(elements[0]) apiver = elements[0]
if err != nil {
ctx.ModuleErrorf("invalid version %q found in path: %q", elements[0], path)
return
}
apiver = ver
scope = elements[1] scope = elements[1]
if scope != "public" && scope != "system" && scope != "test" { if scope != "public" && scope != "system" && scope != "test" {
@ -151,7 +145,7 @@ func prebuiltApiFiles(mctx android.TopDownMutatorContext) {
type latestApiInfo struct { type latestApiInfo struct {
module string module string
scope string scope string
apiver int apiver string
path string path string
} }
m := make(map[string]latestApiInfo) m := make(map[string]latestApiInfo)
@ -160,14 +154,15 @@ func prebuiltApiFiles(mctx android.TopDownMutatorContext) {
// create a filegroup for each api txt file // create a filegroup for each api txt file
localPath := strings.TrimPrefix(f, mydir) localPath := strings.TrimPrefix(f, mydir)
module, apiver, scope := parseApiFilePath(mctx, localPath) module, apiver, scope := parseApiFilePath(mctx, localPath)
createFilegroup(mctx, module, scope, strconv.Itoa(apiver), localPath) createFilegroup(mctx, module, scope, apiver, localPath)
// find the latest apiver // find the latest apiver
key := module + "." + scope key := module + "." + scope
info, ok := m[key] info, ok := m[key]
if !ok { if !ok {
m[key] = latestApiInfo{module, scope, apiver, localPath} m[key] = latestApiInfo{module, scope, apiver, localPath}
} else if apiver > info.apiver { } else if len(apiver) > len(info.apiver) || (len(apiver) == len(info.apiver) &&
strings.Compare(apiver, info.apiver) > 0) {
info.apiver = apiver info.apiver = apiver
info.path = localPath info.path = localPath
} }

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"io" "io"
"path" "path"
"path/filepath"
"sort" "sort"
"strings" "strings"
"sync" "sync"
@ -33,7 +34,6 @@ var (
sdkSystemApiSuffix = ".system" sdkSystemApiSuffix = ".system"
sdkTestApiSuffix = ".test" sdkTestApiSuffix = ".test"
sdkDocsSuffix = ".docs" sdkDocsSuffix = ".docs"
sdkImplLibrarySuffix = ".impl"
sdkXmlFileSuffix = ".xml" sdkXmlFileSuffix = ".xml"
) )
@ -46,7 +46,6 @@ var (
publicApiStubsTag = dependencyTag{name: "public"} publicApiStubsTag = dependencyTag{name: "public"}
systemApiStubsTag = dependencyTag{name: "system"} systemApiStubsTag = dependencyTag{name: "system"}
testApiStubsTag = dependencyTag{name: "test"} testApiStubsTag = dependencyTag{name: "test"}
implLibTag = dependencyTag{name: "platform"}
publicApiFileTag = dependencyTag{name: "publicApi"} publicApiFileTag = dependencyTag{name: "publicApi"}
systemApiFileTag = dependencyTag{name: "systemApi"} systemApiFileTag = dependencyTag{name: "systemApi"}
testApiFileTag = dependencyTag{name: "testApi"} testApiFileTag = dependencyTag{name: "testApi"}
@ -89,20 +88,9 @@ func init() {
} }
type sdkLibraryProperties struct { type sdkLibraryProperties struct {
// list of source files used to compile the Java module. May be .java, .logtags, .proto,
// or .aidl files.
Srcs []string `android:"arch_variant"`
// list of optional source files that are part of API but not part of runtime library. // list of optional source files that are part of API but not part of runtime library.
Api_srcs []string `android:"arch_variant"` Api_srcs []string `android:"arch_variant"`
// list of of java libraries that will be in the classpath
Libs []string `android:"arch_variant"`
// list of java libraries that will be compiled into the resulting runtime jar.
// These libraries are not compiled into the stubs jar.
Static_libs []string `android:"arch_variant"`
// List of Java libraries that will be in the classpath when building stubs // List of Java libraries that will be in the classpath when building stubs
Stub_only_libs []string `android:"arch_variant"` Stub_only_libs []string `android:"arch_variant"`
@ -112,18 +100,9 @@ type sdkLibraryProperties struct {
// list of package names that must be hidden from the API // list of package names that must be hidden from the API
Hidden_api_packages []string Hidden_api_packages []string
Errorprone struct {
// List of javac flags that should only be used when running errorprone.
Javacflags []string
}
// Additional droiddoc options // Additional droiddoc options
Droiddoc_options []string Droiddoc_options []string
// If set to true, compile dex regardless of installable. Defaults to false.
// This applies to the stubs lib.
Compile_dex *bool
// the java library (in classpath) for documentation that provides java srcs and srcjars. // the java library (in classpath) for documentation that provides java srcs and srcjars.
Srcs_lib *string Srcs_lib *string
@ -134,27 +113,32 @@ type sdkLibraryProperties struct {
// Defaults to "android.annotation". // Defaults to "android.annotation".
Srcs_lib_whitelist_pkgs []string Srcs_lib_whitelist_pkgs []string
// 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
// TODO: determines whether to create HTML doc or not // TODO: determines whether to create HTML doc or not
//Html_doc *bool //Html_doc *bool
} }
type sdkLibrary struct { type sdkLibrary struct {
android.ModuleBase Library
android.DefaultableModuleBase
properties sdkLibraryProperties sdkLibraryProperties sdkLibraryProperties
deviceProperties CompilerDeviceProperties
dexpreoptProperties DexpreoptProperties
publicApiStubsPath android.Paths publicApiStubsPath android.Paths
systemApiStubsPath android.Paths systemApiStubsPath android.Paths
testApiStubsPath android.Paths testApiStubsPath android.Paths
implLibPath android.Paths
publicApiStubsImplPath android.Paths publicApiStubsImplPath android.Paths
systemApiStubsImplPath android.Paths systemApiStubsImplPath android.Paths
testApiStubsImplPath android.Paths testApiStubsImplPath android.Paths
implLibImplPath android.Paths
publicApiFilePath android.Path publicApiFilePath android.Path
systemApiFilePath android.Path systemApiFilePath android.Path
@ -164,16 +148,21 @@ type sdkLibrary struct {
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.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic)) ctx.AddVariationDependencies(nil, publicApiStubsTag, module.stubsName(apiScopePublic))
ctx.AddVariationDependencies(nil, systemApiStubsTag, module.stubsName(apiScopeSystem))
ctx.AddVariationDependencies(nil, testApiStubsTag, module.stubsName(apiScopeTest))
ctx.AddVariationDependencies(nil, implLibTag, module.implName())
ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic)) ctx.AddVariationDependencies(nil, publicApiFileTag, module.docsName(apiScopePublic))
ctx.AddVariationDependencies(nil, systemApiFileTag, module.docsName(apiScopeSystem))
ctx.AddVariationDependencies(nil, testApiFileTag, module.docsName(apiScopeTest)) 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)
} }
func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
module.Library.GenerateAndroidBuildActions(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 dependened 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.
@ -192,11 +181,6 @@ func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
case testApiStubsTag: case testApiStubsTag:
module.testApiStubsPath = lib.HeaderJars() module.testApiStubsPath = lib.HeaderJars()
module.testApiStubsImplPath = lib.ImplementationJars() module.testApiStubsImplPath = lib.ImplementationJars()
case implLibTag:
module.implLibPath = lib.HeaderJars()
module.implLibImplPath = lib.ImplementationJars()
default:
ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
} }
} }
if doc, ok := to.(ApiFilePath); ok { if doc, ok := to.(ApiFilePath); ok {
@ -215,58 +199,62 @@ func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
} }
func (module *sdkLibrary) AndroidMk() android.AndroidMkData { func (module *sdkLibrary) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{ data := module.Library.AndroidMk()
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { data.Required = append(data.Required, module.xmlFileName())
// Create a phony module that installs the impl library, for the case when this lib is
// in PRODUCT_PACKAGES. data.Custom = func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") android.WriteAndroidMkData(w, data)
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name) module.Library.AndroidMkHostDex(w, name, data)
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+module.implName()) // Create a phony module that installs the impl library, for the case when this lib is
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") // in PRODUCT_PACKAGES.
owner := module.ModuleBase.Owner() owner := module.ModuleBase.Owner()
if owner == "" { if owner == "" {
if Bool(module.sdkLibraryProperties.Core_lib) {
owner = "core"
} else {
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 to the dist dir
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ if len(module.publicApiStubsPath) == 1 {
module.publicApiStubsImplPath.Strings()[0]+ fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
":"+path.Join("apistubs", owner, "public", module.publicApiStubsImplPath.Strings()[0]+
module.BaseModuleName()+".jar")+")") ":"+path.Join("apistubs", owner, "public",
} module.BaseModuleName()+".jar")+")")
if len(module.systemApiStubsPath) == 1 { }
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ if len(module.systemApiStubsPath) == 1 {
module.systemApiStubsImplPath.Strings()[0]+ fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
":"+path.Join("apistubs", owner, "system", module.systemApiStubsImplPath.Strings()[0]+
module.BaseModuleName()+".jar")+")") ":"+path.Join("apistubs", owner, "system",
} module.BaseModuleName()+".jar")+")")
if len(module.testApiStubsPath) == 1 { }
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ if len(module.testApiStubsPath) == 1 {
module.testApiStubsImplPath.Strings()[0]+ fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
":"+path.Join("apistubs", owner, "test", module.testApiStubsImplPath.Strings()[0]+
module.BaseModuleName()+".jar")+")") ":"+path.Join("apistubs", owner, "test",
} module.BaseModuleName()+".jar")+")")
if module.publicApiFilePath != nil { }
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ if module.publicApiFilePath != nil {
module.publicApiFilePath.String()+ fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
":"+path.Join("apistubs", owner, "public", "api", module.publicApiFilePath.String()+
module.BaseModuleName()+".txt")+")") ":"+path.Join("apistubs", owner, "public", "api",
} module.BaseModuleName()+".txt")+")")
if module.systemApiFilePath != nil { }
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ if module.systemApiFilePath != nil {
module.systemApiFilePath.String()+ fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
":"+path.Join("apistubs", owner, "system", "api", module.systemApiFilePath.String()+
module.BaseModuleName()+".txt")+")") ":"+path.Join("apistubs", owner, "system", "api",
} module.BaseModuleName()+".txt")+")")
if module.testApiFilePath != nil { }
fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+ if module.testApiFilePath != nil {
module.testApiFilePath.String()+ fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
":"+path.Join("apistubs", owner, "test", "api", module.testApiFilePath.String()+
module.BaseModuleName()+".txt")+")") ":"+path.Join("apistubs", owner, "test", "api",
} module.BaseModuleName()+".txt")+")")
}, }
} }
return data
} }
// Module name of the stubs library // Module name of the stubs library
@ -295,7 +283,7 @@ func (module *sdkLibrary) docsName(apiScope apiScope) string {
// Module name of the runtime implementation library // Module name of the runtime implementation library
func (module *sdkLibrary) implName() string { func (module *sdkLibrary) implName() string {
return module.BaseModuleName() + sdkImplLibrarySuffix return module.BaseModuleName()
} }
// File path to the runtime implementation library // File path to the runtime implementation library
@ -385,6 +373,9 @@ func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext,
Device_specific *bool Device_specific *bool
Product_specific *bool Product_specific *bool
Compile_dex *bool Compile_dex *bool
No_standard_libs *bool
System_modules *string
Java_version *string
Product_variables struct { Product_variables struct {
Unbundled_build struct { Unbundled_build struct {
Enabled *bool Enabled *bool
@ -393,18 +384,27 @@ func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext,
Enabled *bool Enabled *bool
} }
} }
Openjdk9 struct {
Srcs []string
Javacflags []string
}
}{} }{}
props.Name = proptools.StringPtr(module.stubsName(apiScope)) props.Name = proptools.StringPtr(module.stubsName(apiScope))
// sources are generated from the droiddoc // sources are generated from the droiddoc
props.Srcs = []string{":" + module.docsName(apiScope)} props.Srcs = []string{":" + module.docsName(apiScope)}
props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope)) props.Sdk_version = proptools.StringPtr(module.sdkVersion(apiScope))
props.Libs = module.properties.Stub_only_libs props.Libs = module.sdkLibraryProperties.Stub_only_libs
// 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)
if module.properties.Compile_dex != nil { props.No_standard_libs = module.Library.Module.properties.No_standard_libs
props.Compile_dex = module.properties.Compile_dex 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
} }
if module.SocSpecific() { if module.SocSpecific() {
@ -422,18 +422,22 @@ func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext,
// files // files
func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) { func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScope apiScope) {
props := struct { props := struct {
Name *string Name *string
Srcs []string Srcs []string
Installable *bool Installable *bool
Srcs_lib *string Srcs_lib *string
Srcs_lib_whitelist_dirs []string Srcs_lib_whitelist_dirs []string
Srcs_lib_whitelist_pkgs []string Srcs_lib_whitelist_pkgs []string
Libs []string Libs []string
Args *string Args *string
Api_tag_name *string Api_tag_name *string
Api_filename *string Api_filename *string
Removed_api_filename *string Removed_api_filename *string
Check_api struct { No_standard_libs *bool
Java_version *string
Merge_annotations_dirs []string
Merge_inclusion_annotations_dirs []string
Check_api struct {
Current ApiToCheck Current ApiToCheck
Last_released ApiToCheck Last_released ApiToCheck
} }
@ -444,19 +448,24 @@ func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScop
}{} }{}
props.Name = proptools.StringPtr(module.docsName(apiScope)) props.Name = proptools.StringPtr(module.docsName(apiScope))
props.Srcs = append(props.Srcs, module.properties.Srcs...) props.Srcs = append(props.Srcs, module.Library.Module.properties.Srcs...)
props.Srcs = append(props.Srcs, module.properties.Api_srcs...) props.Srcs = append(props.Srcs, module.sdkLibraryProperties.Api_srcs...)
props.Installable = proptools.BoolPtr(false) props.Installable = proptools.BoolPtr(false)
// A droiddoc module has only one Libs property and doesn't distinguish between // 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. // shared libs and static libs. So we need to add both of these libs to Libs property.
props.Libs = module.properties.Libs props.Libs = module.Library.Module.properties.Libs
props.Libs = append(props.Libs, module.properties.Static_libs...) props.Libs = append(props.Libs, module.Library.Module.properties.Static_libs...)
props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs props.Aidl.Include_dirs = module.Library.Module.deviceProperties.Aidl.Include_dirs
props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_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
droiddocArgs := " --stub-packages " + strings.Join(module.properties.Api_packages, ":") + props.Merge_annotations_dirs = module.sdkLibraryProperties.Merge_annotations_dirs
" " + android.JoinWithPrefix(module.properties.Hidden_api_packages, " --hide-package ") + props.Merge_inclusion_annotations_dirs = module.sdkLibraryProperties.Merge_inclusion_annotations_dirs
" " + android.JoinWithPrefix(module.properties.Droiddoc_options, " ") +
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 MissingPermission --hide BroadcastBehavior " +
"--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " + "--hide HiddenSuperclass --hide DeprecationMismatch --hide UnavailableSymbol " +
"--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo" "--hide SdkConstant --hide HiddenTypeParameter --hide Todo --hide Typo"
@ -498,55 +507,13 @@ func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, apiScop
module.latestApiFilegroupName(apiScope)) module.latestApiFilegroupName(apiScope))
props.Check_api.Last_released.Removed_api_file = proptools.StringPtr( props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
module.latestRemovedApiFilegroupName(apiScope)) module.latestRemovedApiFilegroupName(apiScope))
props.Srcs_lib = module.properties.Srcs_lib props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib
props.Srcs_lib_whitelist_dirs = module.properties.Srcs_lib_whitelist_dirs props.Srcs_lib_whitelist_dirs = module.sdkLibraryProperties.Srcs_lib_whitelist_dirs
props.Srcs_lib_whitelist_pkgs = module.properties.Srcs_lib_whitelist_pkgs props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs
mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props) mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
} }
// Creates the runtime library. This is not directly linkable from other modules.
func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) {
props := struct {
Name *string
Srcs []string
Libs []string
Static_libs []string
Soc_specific *bool
Device_specific *bool
Product_specific *bool
Installable *bool
Required []string
Errorprone struct {
Javacflags []string
}
IsSDKLibrary bool
}{}
props.Name = proptools.StringPtr(module.implName())
props.Srcs = module.properties.Srcs
props.Libs = module.properties.Libs
props.Static_libs = module.properties.Static_libs
props.Installable = proptools.BoolPtr(true)
// XML file is installed along with the impl lib
props.Required = []string{module.xmlFileName()}
props.Errorprone.Javacflags = module.properties.Errorprone.Javacflags
props.IsSDKLibrary = true
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(LibraryFactory),
&props,
&module.deviceProperties,
&module.dexpreoptProperties)
}
// Creates the xml file that publicizes the runtime library // Creates the xml file that publicizes the runtime library
func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) { func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) {
template := ` template := `
@ -607,27 +574,54 @@ func (module *sdkLibrary) createXmlFile(mctx android.TopDownMutatorContext) {
mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps) mctx.CreateModule(android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory), &etcProps)
} }
// to satisfy SdkLibraryDependency interface func (module *sdkLibrary) PrebuiltJars(ctx android.BaseContext, sdkVersion string) android.Paths {
func (module *sdkLibrary) HeaderJars(linkType linkType) android.Paths { var api, v string
// This module is just a wrapper for the stubs. if sdkVersion == "" {
if linkType == javaSystem { api = "system"
return module.systemApiStubsPath v = "current"
} else if linkType == javaPlatform { } else if strings.Contains(sdkVersion, "_") {
return module.implLibPath t := strings.Split(sdkVersion, "_")
api = t[0]
v = t[1]
} else { } else {
return module.publicApiStubsPath api = "public"
v = sdkVersion
}
dir := filepath.Join("prebuilts", "sdk", v, api)
jar := filepath.Join(dir, module.BaseModuleName()+".jar")
jarPath := android.ExistentPathForSource(ctx, jar)
return android.Paths{jarPath.Path()}
}
// to satisfy SdkLibraryDependency interface
func (module *sdkLibrary) HeaderJars(ctx android.BaseContext, sdkVersion string) android.Paths {
// This module is just a wrapper for the stubs.
if ctx.Config().UnbundledBuild() {
return module.PrebuiltJars(ctx, sdkVersion)
} else {
if strings.HasPrefix(sdkVersion, "system_") {
return module.systemApiStubsPath
} else if sdkVersion == "" {
return module.Library.HeaderJars()
} else {
return module.publicApiStubsPath
}
} }
} }
// to satisfy SdkLibraryDependency interface // to satisfy SdkLibraryDependency interface
func (module *sdkLibrary) ImplementationJars(linkType linkType) android.Paths { func (module *sdkLibrary) ImplementationJars(ctx android.BaseContext, sdkVersion string) android.Paths {
// This module is just a wrapper for the stubs. // This module is just a wrapper for the stubs.
if linkType == javaSystem { if ctx.Config().UnbundledBuild() {
return module.systemApiStubsImplPath return module.PrebuiltJars(ctx, sdkVersion)
} else if linkType == javaPlatform {
return module.implLibImplPath
} else { } else {
return module.publicApiStubsImplPath if strings.HasPrefix(sdkVersion, "system_") {
return module.systemApiStubsImplPath
} else if sdkVersion == "" {
return module.Library.ImplementationJars()
} else {
return module.publicApiStubsImplPath
}
} }
} }
@ -642,28 +636,29 @@ func javaSdkLibraries(config android.Config) *[]string {
// once for public API level and once for system API level // once for public API level and once for system API level
func sdkLibraryMutator(mctx android.TopDownMutatorContext) { func sdkLibraryMutator(mctx android.TopDownMutatorContext) {
if module, ok := mctx.Module().(*sdkLibrary); ok { if module, ok := mctx.Module().(*sdkLibrary); ok {
if module.properties.Srcs == nil { if module.Library.Module.properties.Srcs == nil {
mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs") mctx.PropertyErrorf("srcs", "java_sdk_library must specify srcs")
} }
if module.properties.Api_packages == nil {
if module.sdkLibraryProperties.Api_packages == nil {
mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages") mctx.PropertyErrorf("api_packages", "java_sdk_library must specify api_packages")
} }
// for public API stubs // for public API stubs
module.createStubsLibrary(mctx, apiScopePublic) module.createStubsLibrary(mctx, apiScopePublic)
module.createDocs(mctx, apiScopePublic) module.createDocs(mctx, apiScopePublic)
// for system API stubs if !Bool(module.properties.No_standard_libs) {
module.createStubsLibrary(mctx, apiScopeSystem) // for system API stubs
module.createDocs(mctx, apiScopeSystem) module.createStubsLibrary(mctx, apiScopeSystem)
module.createDocs(mctx, apiScopeSystem)
// for test API stubs // for test API stubs
module.createStubsLibrary(mctx, apiScopeTest) module.createStubsLibrary(mctx, apiScopeTest)
module.createDocs(mctx, apiScopeTest) module.createDocs(mctx, apiScopeTest)
// for runtime // for runtime
module.createXmlFile(mctx) module.createXmlFile(mctx)
module.createImplLibrary(mctx) }
// record java_sdk_library modules so that they are exported to make // record java_sdk_library modules so that they are exported to make
javaSdkLibraries := javaSdkLibraries(mctx.Config()) javaSdkLibraries := javaSdkLibraries(mctx.Config())
@ -675,9 +670,17 @@ func sdkLibraryMutator(mctx android.TopDownMutatorContext) {
func sdkLibraryFactory() android.Module { func sdkLibraryFactory() android.Module {
module := &sdkLibrary{} module := &sdkLibrary{}
module.AddProperties(&module.properties) module.AddProperties(
module.AddProperties(&module.deviceProperties) &module.sdkLibraryProperties,
module.AddProperties(&module.dexpreoptProperties) &module.Library.Module.properties,
InitJavaModule(module, android.DeviceSupported) &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
InitJavaModule(module, android.HostAndDeviceSupported)
return module return module
} }