summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go119
1 files changed, 90 insertions, 29 deletions
diff --git a/java/java.go b/java/java.go
index f6c94840b..b4b8feb23 100644
--- a/java/java.go
+++ b/java/java.go
@@ -75,7 +75,7 @@ type CompilerProperties struct {
// list of files to use as Java resources
Java_resources []string `android:"arch_variant"`
- // list of files that should be excluded from java_resources
+ // list of files that should be excluded from java_resources and java_resource_dirs
Exclude_java_resources []string `android:"arch_variant"`
// don't build against the default libraries (bootclasspath, legacy-test, core-junit,
@@ -95,6 +95,9 @@ type CompilerProperties struct {
// list of java libraries that will be compiled into the resulting jar
Static_libs []string `android:"arch_variant"`
+ // list of native libraries that will be provided in or alongside the resulting jar
+ Jni_libs []string `android:"arch_variant"`
+
// manifest file to be included in resulting jar
Manifest *string
@@ -138,7 +141,7 @@ type CompilerProperties struct {
// supported at compile time. It should only be needed to compile tests in
// packages that exist in libcore and which are inconvenient to move
// elsewhere.
- Patch_module *string
+ Patch_module *string `android:"arch_variant"`
Jacoco struct {
// List of classes to include for instrumentation with jacoco to collect coverage
@@ -311,6 +314,10 @@ type Module struct {
// list of SDK lib names that this java moudule is exporting
exportedSdkLibs []string
+
+ // list of source files, collected from compiledJavaSrcs and compiledSrcJars
+ // filter out Exclude_srcs, will be used by android.IDEInfo struct
+ expandIDEInfoCompiledSrcs []string
}
func (j *Module) Srcs() android.Paths {
@@ -412,7 +419,7 @@ type sdkContext interface {
func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
switch v {
- case "", "current", "system_current", "test_current", "core_current":
+ case "", "current", "system_current", "test_current", "core_current", "core_platform_current":
return ctx.Config().DefaultAppTargetSdk()
default:
return v
@@ -423,7 +430,7 @@ func sdkVersionOrDefault(ctx android.BaseContext, v string) string {
// it returns android.FutureApiLevel (10000).
func sdkVersionToNumber(ctx android.BaseContext, v string) (int, error) {
switch v {
- case "", "current", "test_current", "system_current", "core_current":
+ case "", "current", "test_current", "system_current", "core_current", "core_platform_current":
return ctx.Config().DefaultAppTargetSdkInt(), nil
default:
n := android.GetNumericSdkVersion(v)
@@ -520,6 +527,8 @@ func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
}
if m == "core.current.stubs" {
ret.systemModules = "core-system-modules"
+ } else if m == "core.platform.api.stubs" {
+ ret.systemModules = "core-platform-api-stubs-system-modules"
}
return ret
}
@@ -542,6 +551,8 @@ func decodeSdkDep(ctx android.BaseContext, sdkContext sdkContext) sdkDep {
return toModule("android_test_stubs_current", "framework-res")
case "core_current":
return toModule("core.current.stubs", "")
+ case "core_platform_current":
+ return toModule("core.platform.api.stubs", "")
default:
return toPrebuilt(v)
}
@@ -553,16 +564,12 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
sdkDep := decodeSdkDep(ctx, sdkContext(j))
if sdkDep.useDefaultLibs {
ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
- if ctx.Config().TargetOpenJDK9() {
- ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
- }
+ ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
if !Bool(j.properties.No_framework_libs) {
ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
}
} else if sdkDep.useModule {
- if ctx.Config().TargetOpenJDK9() {
- ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
- }
+ ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
if Bool(j.deviceProperties.Optimize.Enabled) {
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
@@ -572,10 +579,10 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
} else if j.deviceProperties.System_modules == nil {
ctx.PropertyErrorf("no_standard_libs",
"system_modules is required to be set when no_standard_libs is true, did you mean no_framework_libs?")
- } else if *j.deviceProperties.System_modules != "none" && ctx.Config().TargetOpenJDK9() {
+ } else if *j.deviceProperties.System_modules != "none" {
ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules)
}
- if ctx.ModuleName() == "framework" {
+ if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res")
}
if ctx.ModuleName() == "android_stubs_current" ||
@@ -708,8 +715,9 @@ func getLinkType(m *Module, name string) linkType {
ver := m.sdkVersion()
noStdLibs := Bool(m.properties.No_standard_libs)
switch {
- case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations" ||
- name == "private-stub-annotations-jar":
+ case name == "core.current.stubs" || ver == "core_current" ||
+ name == "core.platform.api.stubs" || ver == "core_platform_current" ||
+ noStdLibs || name == "stub-annotations" || name == "private-stub-annotations-jar":
return javaCore
case name == "android_system_stubs_current" || strings.HasPrefix(ver, "system_"):
return javaSystem
@@ -804,7 +812,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
case annoTag:
deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
case frameworkResTag:
- if ctx.ModuleName() == "framework" {
+ if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
// framework.jar has a one-off dependency on the R.java and Manifest.java files
// generated by framework-res.apk
deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
@@ -884,7 +892,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sd
ret = javaVersion
} else if ctx.Device() && sdk <= 23 {
ret = "1.7"
- } else if ctx.Device() && sdk <= 26 || !ctx.Config().TargetOpenJDK9() {
+ } else if ctx.Device() && sdk <= 28 || !ctx.Config().TargetOpenJDK9() {
ret = "1.8"
} else if ctx.Device() && sdkContext.sdkVersion() != "" && sdk == android.FutureApiLevel {
// TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
@@ -900,9 +908,12 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
var flags javaBuilderFlags
+ // javaVersion flag.
+ flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
+
// javac flags.
javacFlags := j.properties.Javacflags
- if ctx.Config().TargetOpenJDK9() {
+ if flags.javaVersion == "1.9" {
javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
}
if ctx.Config().MinimizeJavaDebugInfo() {
@@ -927,15 +938,12 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
}
- // javaVersion flag.
- flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
-
// classpath
flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
flags.classpath = append(flags.classpath, deps.classpath...)
flags.processorPath = append(flags.processorPath, deps.processorPath...)
- if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
+ if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
!Bool(j.properties.No_standard_libs) &&
inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
// Give host-side tools a version of OpenJDK's standard libraries
@@ -961,7 +969,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
}
}
- if j.properties.Patch_module != nil && ctx.Config().TargetOpenJDK9() {
+ if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
patchClasspath := ".:" + flags.classpath.FormJavaClassPath("")
javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchClasspath)
}
@@ -995,7 +1003,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
deps := j.collectDeps(ctx)
flags := j.collectBuilderFlags(ctx, deps)
- if ctx.Config().TargetOpenJDK9() {
+ if flags.javaVersion == "1.9" {
j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
}
srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs)
@@ -1009,6 +1017,10 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
srcJars = append(srcJars, deps.srcJars...)
srcJars = append(srcJars, extraSrcJars...)
+ // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
+ // that IDEInfo struct will use
+ j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
+
jarName := ctx.ModuleName() + ".jar"
javaSrcFiles := srcFiles.FilterByExt(".java")
@@ -1118,7 +1130,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
}
}
- dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, j.properties.Exclude_java_resource_dirs)
+ dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
+ j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
var resArgs []string
@@ -1360,6 +1373,23 @@ func (j *Module) logtags() android.Paths {
return j.logtagsSrcs
}
+// Collect information for opening IDE project files in java/jdeps.go.
+func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
+ dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
+ dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
+ dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
+ if j.properties.Jarjar_rules != nil {
+ dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, *j.properties.Jarjar_rules)
+ }
+}
+
+func (j *Module) CompilerDeps() []string {
+ jdeps := []string{}
+ jdeps = append(jdeps, j.properties.Libs...)
+ jdeps = append(jdeps, j.properties.Static_libs...)
+ return jdeps
+}
+
//
// Java libraries (.jar file)
//
@@ -1419,6 +1449,10 @@ type testProperties struct {
// installed with the module.
Test_config *string `android:"arch_variant"`
+ // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
+ // should be installed with the module.
+ Test_config_template *string `android:"arch_variant"`
+
// list of files or filegroup modules that provide data that should be installed alongside
// the test
Data []string
@@ -1434,7 +1468,7 @@ type Test struct {
}
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config)
+ j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template)
j.data = ctx.ExpandSources(j.testProperties.Data, nil)
j.Library.GenerateAndroidBuildActions(ctx)
@@ -1443,6 +1477,7 @@ func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
j.deps(ctx)
android.ExtractSourceDeps(ctx, j.testProperties.Test_config)
+ android.ExtractSourceDeps(ctx, j.testProperties.Test_config_template)
android.ExtractSourcesDeps(ctx, j.testProperties.Data)
}
@@ -1458,7 +1493,6 @@ func TestFactory() android.Module {
module.Module.properties.Installable = proptools.BoolPtr(true)
InitJavaModule(module, android.HostAndDeviceSupported)
- android.InitDefaultableModule(module)
return module
}
@@ -1473,7 +1507,6 @@ func TestHostFactory() android.Module {
module.Module.properties.Installable = proptools.BoolPtr(true)
InitJavaModule(module, android.HostSupported)
- android.InitDefaultableModule(module)
return module
}
@@ -1589,6 +1622,7 @@ type ImportProperties struct {
type Import struct {
android.ModuleBase
+ android.DefaultableModuleBase
prebuilt android.Prebuilt
properties ImportProperties
@@ -1689,6 +1723,26 @@ func (j *Import) ExportedSdkLibs() []string {
return j.exportedSdkLibs
}
+// Collect information for opening IDE project files in java/jdeps.go.
+const (
+ removedPrefix = "prebuilt_"
+)
+
+func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
+ dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
+}
+
+func (j *Import) IDECustomizedModuleName() string {
+ // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
+ // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
+ // solution to get the Import name.
+ name := j.Name()
+ if strings.HasPrefix(name, removedPrefix) {
+ name = strings.Trim(name, removedPrefix)
+ }
+ return name
+}
+
var _ android.PrebuiltInterface = (*Import)(nil)
func ImportFactory() android.Module {
@@ -1697,7 +1751,7 @@ func ImportFactory() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon)
+ InitJavaModule(module, android.HostAndDeviceSupported)
return module
}
@@ -1707,7 +1761,7 @@ func ImportFactoryHost() android.Module {
module.AddProperties(&module.properties)
android.InitPrebuiltModule(module, &module.properties.Jars)
- android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon)
+ InitJavaModule(module, android.HostSupported)
return module
}
@@ -1737,6 +1791,13 @@ func DefaultsFactory(props ...interface{}) android.Module {
&CompilerProperties{},
&CompilerDeviceProperties{},
&android.ProtoProperties{},
+ &aaptProperties{},
+ &androidLibraryProperties{},
+ &appProperties{},
+ &appTestProperties{},
+ &ImportProperties{},
+ &AARImportProperties{},
+ &sdkLibraryProperties{},
)
android.InitDefaultsModule(module)