summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go170
1 files changed, 141 insertions, 29 deletions
diff --git a/java/java.go b/java/java.go
index c10b30587..5cd074ab1 100644
--- a/java/java.go
+++ b/java/java.go
@@ -54,6 +54,18 @@ func init() {
android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
}
+func (j *Module) checkSdkVersion(ctx android.ModuleContext) {
+ if j.SocSpecific() || j.DeviceSpecific() ||
+ (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) {
+ if sc, ok := ctx.Module().(sdkContext); ok {
+ if sc.sdkVersion() == "" {
+ ctx.PropertyErrorf("sdk_version",
+ "sdk_version must have a value when the module is located at vendor or product(only if PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE is set).")
+ }
+ }
+ }
+}
+
func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
if sc, ok := ctx.Module().(sdkContext); ok {
usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
@@ -133,6 +145,9 @@ type CompilerProperties struct {
// List of modules to use as annotation processors
Plugins []string
+ // List of modules to export to libraries that directly depend on this library as annotation processors
+ Exported_plugins []string
+
// The number of Java source entries each Javac instance can process
Javac_shard_size *int64
@@ -348,10 +363,16 @@ type Module struct {
// manifest file to use instead of properties.Manifest
overrideManifest android.OptionalPath
- // list of SDK lib names that this java moudule is exporting
+ // list of SDK lib names that this java module is exporting
exportedSdkLibs []string
- // list of source files, collected from srcFiles with uniqie java and all kt files,
+ // list of plugins that this java module is exporting
+ exportedPluginJars android.Paths
+
+ // list of plugins that this java module is exporting
+ exportedPluginClasses []string
+
+ // list of source files, collected from srcFiles with unique java and all kt files,
// will be used by android.IDEInfo struct
expandIDEInfoCompiledSrcs []string
@@ -398,6 +419,7 @@ type Dependency interface {
DexJar() android.Path
AidlIncludeDirs() android.Paths
ExportedSdkLibs() []string
+ ExportedPlugins() (android.Paths, []string)
SrcJarArgs() ([]string, android.Paths)
BaseModuleName() string
}
@@ -430,11 +452,17 @@ type jniDependencyTag struct {
target android.Target
}
+func IsJniDepTag(depTag blueprint.DependencyTag) bool {
+ _, ok := depTag.(*jniDependencyTag)
+ return ok
+}
+
var (
staticLibTag = dependencyTag{name: "staticlib"}
libTag = dependencyTag{name: "javalib"}
java9LibTag = dependencyTag{name: "java9lib"}
pluginTag = dependencyTag{name: "plugin"}
+ exportedPluginTag = dependencyTag{name: "exported-plugin"}
bootClasspathTag = dependencyTag{name: "bootclasspath"}
systemModulesTag = dependencyTag{name: "system modules"}
frameworkResTag = dependencyTag{name: "framework-res"}
@@ -447,18 +475,6 @@ var (
usesLibTag = dependencyTag{name: "uses-library"}
)
-func defaultSdkVersion(ctx checkVendorModuleContext) string {
- if ctx.SocSpecific() || ctx.DeviceSpecific() {
- return "system_current"
- }
- return ""
-}
-
-type checkVendorModuleContext interface {
- SocSpecific() bool
- DeviceSpecific() bool
-}
-
type sdkDep struct {
useModule, useFiles, useDefaultLibs, invalidVersion bool
@@ -505,7 +521,7 @@ func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
}
func (j *Module) sdkVersion() string {
- return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j))
+ return String(j.deviceProperties.Sdk_version)
}
func (j *Module) systemModules() string {
@@ -556,6 +572,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
+ ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), exportedPluginTag, j.properties.Exported_plugins...)
android.ProtoDeps(ctx, &j.protoProperties)
if j.hasSrcExt(".proto") {
@@ -803,6 +820,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
// sdk lib names from dependencies are re-exported
j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
+ pluginJars, pluginClasses := dep.ExportedPlugins()
+ addPlugins(&deps, pluginJars, pluginClasses...)
case java9LibTag:
deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars()...)
case staticLibTag:
@@ -813,16 +832,31 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
// sdk lib names from dependencies are re-exported
j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
+ pluginJars, pluginClasses := dep.ExportedPlugins()
+ addPlugins(&deps, pluginJars, pluginClasses...)
case pluginTag:
if plugin, ok := dep.(*Plugin); ok {
- deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
if plugin.pluginProperties.Processor_class != nil {
- deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
+ addPlugins(&deps, plugin.ImplementationAndResourcesJars(), *plugin.pluginProperties.Processor_class)
+ } else {
+ addPlugins(&deps, plugin.ImplementationAndResourcesJars())
}
deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
} else {
ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
}
+ case exportedPluginTag:
+ if plugin, ok := dep.(*Plugin); ok {
+ if plugin.pluginProperties.Generates_api != nil && *plugin.pluginProperties.Generates_api {
+ ctx.PropertyErrorf("exported_plugins", "Cannot export plugins with generates_api = true, found %v", otherName)
+ }
+ j.exportedPluginJars = append(j.exportedPluginJars, plugin.ImplementationAndResourcesJars()...)
+ if plugin.pluginProperties.Processor_class != nil {
+ j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class)
+ }
+ } else {
+ ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName)
+ }
case frameworkApkTag:
if ctx.ModuleName() == "android_stubs_current" ||
ctx.ModuleName() == "android_system_stubs_current" ||
@@ -878,6 +912,11 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
return deps
}
+func addPlugins(deps *deps, pluginJars android.Paths, pluginClasses ...string) {
+ deps.processorPath = append(deps.processorPath, pluginJars...)
+ deps.processorClasses = append(deps.processorClasses, pluginClasses...)
+}
+
func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) javaVersion {
v := sdkContext.sdkVersion()
// For PDK builds, use the latest SDK version instead of "current"
@@ -975,6 +1014,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
// disk and memory usage.
javacFlags = append(javacFlags, "-g:source,lines")
}
+ javacFlags = append(javacFlags, "-Xlint:-dep-ann")
if ctx.Config().RunErrorProne() {
if config.ErrorProneClasspath == nil {
@@ -1571,6 +1611,10 @@ func (j *Module) ExportedSdkLibs() []string {
return j.exportedSdkLibs
}
+func (j *Module) ExportedPlugins() (android.Paths, []string) {
+ return j.exportedPluginJars, j.exportedPluginClasses
+}
+
func (j *Module) SrcJarArgs() ([]string, android.Paths) {
return j.srcJarArgs, j.srcJarDeps
}
@@ -1610,6 +1654,10 @@ func (j *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Modu
return depTag == staticLibTag
}
+func (j *Module) Stem() string {
+ return proptools.StringDefault(j.deviceProperties.Stem, j.Name())
+}
+
//
// Java libraries (.jar file)
//
@@ -1639,8 +1687,8 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo
}
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework",
- proptools.StringDefault(j.deviceProperties.Stem, ctx.ModuleName())+".jar")
+ j.checkSdkVersion(ctx)
+ j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
j.dexpreopter.isInstallable = Bool(j.properties.Installable)
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
@@ -1662,6 +1710,59 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
j.deps(ctx)
}
+const (
+ aidlIncludeDir = "aidl"
+ javaStubDir = "java"
+ javaStubFileSuffix = ".jar"
+)
+
+// path to the stub file of a java library. Relative to <sdk_root>/<api_dir>
+func (j *Library) javaStubFilePathFor() string {
+ return filepath.Join(javaStubDir, j.Name()+javaStubFileSuffix)
+}
+
+func (j *Library) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder) {
+ headerJars := j.HeaderJars()
+ if len(headerJars) != 1 {
+ panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
+ }
+ snapshotRelativeJavaLibPath := j.javaStubFilePathFor()
+ builder.CopyToSnapshot(headerJars[0], snapshotRelativeJavaLibPath)
+
+ for _, dir := range j.AidlIncludeDirs() {
+ // TODO(jiyong): copy parcelable declarations only
+ aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
+ for _, file := range aidlFiles {
+ builder.CopyToSnapshot(android.PathForSource(sdkModuleContext, file), filepath.Join(aidlIncludeDir, file))
+ }
+ }
+
+ j.generateJavaImport(builder, snapshotRelativeJavaLibPath, true)
+
+ // This module is for the case when the source tree for the unversioned module
+ // doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
+ // so that this module does not eclipse the unversioned module if it exists.
+ j.generateJavaImport(builder, snapshotRelativeJavaLibPath, false)
+}
+
+func (j *Library) generateJavaImport(builder android.SnapshotBuilder, snapshotRelativeJavaLibPath string, versioned bool) {
+ bp := builder.AndroidBpFile()
+ name := j.Name()
+ bp.Printfln("java_import {")
+ bp.Indent()
+ if versioned {
+ bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
+ bp.Printfln("sdk_member_name: %q,", name)
+ } else {
+ bp.Printfln("name: %q,", name)
+ bp.Printfln("prefer: false,")
+ }
+ bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath)
+ bp.Dedent()
+ bp.Printfln("}")
+ bp.Printfln("")
+}
+
// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
//
// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
@@ -1682,9 +1783,9 @@ func LibraryFactory() android.Module {
&module.Module.dexpreoptProperties,
&module.Module.protoProperties)
- InitJavaModule(module, android.HostAndDeviceSupported)
android.InitApexModule(module)
android.InitSdkAwareModule(module)
+ InitJavaModule(module, android.HostAndDeviceSupported)
return module
}
@@ -1706,8 +1807,8 @@ func LibraryHostFactory() android.Module {
module.Module.properties.Installable = proptools.BoolPtr(true)
- InitJavaModule(module, android.HostSupported)
android.InitApexModule(module)
+ InitJavaModule(module, android.HostSupported)
return module
}
@@ -1983,7 +2084,7 @@ type Import struct {
}
func (j *Import) sdkVersion() string {
- return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j))
+ return String(j.properties.Sdk_version)
}
func (j *Import) minSdkVersion() string {
@@ -2002,6 +2103,10 @@ func (j *Import) Name() string {
return j.prebuilt.Name(j.ModuleBase.Name())
}
+func (j *Import) Stem() string {
+ return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
+}
+
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
}
@@ -2009,7 +2114,7 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
- jarName := proptools.StringDefault(j.properties.Stem, ctx.ModuleName()) + ".jar"
+ jarName := j.Stem() + ".jar"
outputFile := android.PathForModuleOut(ctx, "combined", jarName)
TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
false, j.properties.Exclude_files, j.properties.Exclude_dirs)
@@ -2086,6 +2191,10 @@ func (j *Import) ExportedSdkLibs() []string {
return j.exportedSdkLibs
}
+func (j *Import) ExportedPlugins() (android.Paths, []string) {
+ return nil, nil
+}
+
func (j *Import) SrcJarArgs() ([]string, android.Paths) {
return nil, nil
}
@@ -2129,9 +2238,9 @@ func ImportFactory() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- InitJavaModule(module, android.HostAndDeviceSupported)
android.InitApexModule(module)
android.InitSdkAwareModule(module)
+ InitJavaModule(module, android.HostAndDeviceSupported)
return module
}
@@ -2146,8 +2255,8 @@ func ImportFactoryHost() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- InitJavaModule(module, android.HostSupported)
android.InitApexModule(module)
+ InitJavaModule(module, android.HostSupported)
return module
}
@@ -2186,13 +2295,16 @@ func (j *DexImport) Name() string {
return j.prebuilt.Name(j.ModuleBase.Name())
}
+func (j *DexImport) Stem() string {
+ return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name())
+}
+
func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
if len(j.properties.Jars) != 1 {
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
}
- j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework",
- proptools.StringDefault(j.properties.Stem, ctx.ModuleName())+".jar")
+ j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.isInstallable = true
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
@@ -2255,8 +2367,8 @@ func DexImportFactory() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- InitJavaModule(module, android.DeviceSupported)
android.InitApexModule(module)
+ InitJavaModule(module, android.DeviceSupported)
return module
}
@@ -2322,10 +2434,10 @@ func DefaultsFactory(props ...interface{}) android.Module {
&AARImportProperties{},
&sdkLibraryProperties{},
&DexImportProperties{},
+ &android.ApexProperties{},
)
android.InitDefaultsModule(module)
- android.InitApexModule(module)
return module
}