Additional fixes for java_sdk_library

am: 82484c0771

Change-Id: Ic327990f5955b8efaa2236931ecf1cc2a945b026
This commit is contained in:
Jiyong Park
2018-04-23 19:38:36 -07:00
committed by android-build-merger
2 changed files with 61 additions and 8 deletions

View File

@@ -256,7 +256,9 @@ func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {
func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
prefix := filepath.Join(dir, pkg)
// convert foo.bar.baz to foo/bar/baz
pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
prefix := filepath.Join(dir, pkgAsPath)
if _, found := whitelistPathPrefixes[prefix]; !found {
whitelistPathPrefixes[prefix] = true
}

View File

@@ -18,8 +18,11 @@ import (
"android/soong/android"
"android/soong/genrule"
"fmt"
"io"
"path"
"sort"
"strings"
"sync"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -43,6 +46,10 @@ var (
systemApiStubsTag = dependencyTag{name: "system"}
)
var (
javaSdkLibrariesLock sync.Mutex
)
// 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
@@ -62,6 +69,12 @@ func init() {
android.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
ctx.TopDown("java_sdk_library", sdkLibraryMutator).Parallel()
})
android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
javaSdkLibraries := javaSdkLibraries(ctx.Config())
sort.Strings(*javaSdkLibraries)
ctx.Strict("JAVA_SDK_LIBRARIES", strings.Join(*javaSdkLibraries, " "))
})
}
type sdkLibraryProperties struct {
@@ -120,6 +133,20 @@ func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
})
}
func (module *sdkLibrary) AndroidMk() android.AndroidMkData {
// Create a phony module that installs the impl library, for the case when this lib is
// in PRODUCT_PACKAGES.
return android.AndroidMkData{
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
fmt.Fprintln(w, "LOCAL_MODULE :=", name)
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+module.implName())
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
},
}
}
// Module name of the stubs library
func (module *sdkLibrary) stubsName(forSystemApi bool) string {
stubsName := module.BaseModuleName() + sdkStubsLibrarySuffix
@@ -210,6 +237,9 @@ func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext,
Unbundled_build struct {
Enabled *bool
}
Pdk struct {
Enabled *bool
}
}
}{}
@@ -219,6 +249,7 @@ func (module *sdkLibrary) createStubsLibrary(mctx android.TopDownMutatorContext,
props.Sdk_version = proptools.StringPtr(module.sdkVersion(forSystemApi))
// Unbundled apps will use the prebult one from /prebuilts/sdk
props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false)
props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false)
if module.SocSpecific() {
props.Soc_specific = proptools.BoolPtr(true)
@@ -281,17 +312,25 @@ func (module *sdkLibrary) createDocs(mctx android.TopDownMutatorContext, forSyst
props.Api_filename = proptools.StringPtr(currentApiFileName)
props.Removed_api_filename = proptools.StringPtr(removedApiFileName)
// Includes the main framework source to ensure that doclava has access to the
// visibility information for the base classes of the mock classes. Without it
// otherwise hidden methods could be visible.
// TODO: remove the need for this
// Include the part of the framework source. This is required for the case when
// API class is extending from the framework class. In that case, doclava needs
// to know whether the base class is hidden or not. Since that information is
// encoded as @hide string in the comment, we need source files for the classes,
// not the compiled ones. Also there are rare cases where part of SDK library is
// implemented in the framework (e.g. org.apache.http.legacy). In that case,
// we need framework source to make API stubs, though the sources are not
// required to build the runtime library.
props.Srcs_lib = proptools.StringPtr("framework")
props.Srcs_lib_whitelist_dirs = []string{"core/java"}
props.Srcs_lib_whitelist_pkgs = []string{"android"}
// These libs are required by doclava to parse the sources from framework.
props.Srcs_lib_whitelist_pkgs = module.properties.Api_packages
// Add android.annotation package to give access to the framework-defined
// annotations such as SystemApi, NonNull, etc.
props.Srcs_lib_whitelist_pkgs = append(props.Srcs_lib_whitelist_pkgs, "android.annotation")
// These libs are required by doclava to parse the framework sources add via
// Src_lib and Src_lib_whitelist_* properties just above.
// If we don't add them to the classpath, errors messages are generated by doclava,
// though they don't break the build.
props.Libs = append(props.Libs, "conscrypt", "bouncycastle", "okhttp")
props.Libs = append(props.Libs, "conscrypt", "bouncycastle", "okhttp", "framework")
mctx.CreateModule(android.ModuleFactoryAdaptor(DroiddocFactory), &props)
}
@@ -397,6 +436,12 @@ func (module *sdkLibrary) HeaderJars(linkType linkType) android.Paths {
}
}
func javaSdkLibraries(config android.Config) *[]string {
return config.Once("javaSdkLibraries", func() interface{} {
return &[]string{}
}).(*[]string)
}
// 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
@@ -413,6 +458,12 @@ func sdkLibraryMutator(mctx android.TopDownMutatorContext) {
// for runtime
module.createXmlFile(mctx)
module.createImplLibrary(mctx)
// 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())
}
}