diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 152 |
1 files changed, 83 insertions, 69 deletions
diff --git a/java/java.go b/java/java.go index 805e06a17..5393b065f 100644 --- a/java/java.go +++ b/java/java.go @@ -28,15 +28,14 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" - "android/soong/genrule" "android/soong/java/config" ) func init() { android.RegisterModuleType("java_defaults", defaultsFactory) - android.RegisterModuleType("java_library", LibraryFactory) - android.RegisterModuleType("java_library_static", LibraryFactory) + android.RegisterModuleType("java_library", LibraryFactory(true)) + android.RegisterModuleType("java_library_static", LibraryFactory(false)) android.RegisterModuleType("java_library_host", LibraryHostFactory) android.RegisterModuleType("java_binary", BinaryFactory) android.RegisterModuleType("java_binary_host", BinaryHostFactory) @@ -49,7 +48,6 @@ func init() { // TODO: // Autogenerated files: -// Proto // Renderscript // Post-jar passes: // Proguard @@ -81,10 +79,14 @@ type CompilerProperties struct { // list of files that should be excluded from java_resources Exclude_java_resources []string `android:"arch_variant"` - // don't build against the default libraries (legacy-test, core-junit, + // don't build against the default libraries (bootclasspath, legacy-test, core-junit, // ext, and framework for device targets) No_standard_libs *bool + // don't build against the framework libraries (legacy-test, core-junit, + // ext, and framework for device targets) + No_framework_libs *bool + // list of module-specific flags that will be used for javac compiles Javacflags []string `android:"arch_variant"` @@ -123,16 +125,15 @@ type CompilerDeviceProperties struct { // if not blank, set to the version of the sdk to compile against Sdk_version string - // Set for device java libraries, and for host versions of device java libraries - // built for testing - Dex bool `blueprint:"mutated"` - // directories to pass to aidl tool Aidl_includes []string // directories that should be added as include directories // for any aidl sources of modules that depend on this module Export_aidl_include_dirs []string + + // If true, export a copy of the module as a -hostdex module for host testing. + Hostdex *bool } // Module contains the properties and members used by all java module types @@ -141,6 +142,7 @@ type Module struct { android.DefaultableModuleBase properties CompilerProperties + protoProperties android.ProtoProperties deviceProperties CompilerDeviceProperties // output file suitable for inserting into the classpath of another compile @@ -149,9 +151,6 @@ type Module struct { // output file containing classes.dex dexJarFile android.Path - // output files containing resources - resourceJarFiles android.Paths - // output file suitable for installing or running outputFile android.Path @@ -169,7 +168,6 @@ type Module struct { type Dependency interface { ClasspathFiles() android.Paths - ResourceJarFiles() android.Paths AidlIncludeDirs() android.Paths } @@ -191,10 +189,11 @@ var ( ) type sdkDep struct { - useModule, useFiles, useDefaultLibs bool - module string - jar android.Path - aidl android.Path + useModule, useFiles, useDefaultLibs, invalidVersion bool + + module string + jar android.Path + aidl android.Path } func decodeSdkDep(ctx android.BaseContext, v string) sdkDep { @@ -214,14 +213,24 @@ func decodeSdkDep(ctx android.BaseContext, v string) sdkDep { aidl := filepath.Join(dir, "framework.aidl") jarPath := android.ExistentPathForSource(ctx, "sdkdir", jar) aidlPath := android.ExistentPathForSource(ctx, "sdkdir", aidl) + + if (!jarPath.Valid() || !aidlPath.Valid()) && ctx.AConfig().AllowMissingDependencies() { + return sdkDep{ + invalidVersion: true, + module: "sdk_v" + v, + } + } + if !jarPath.Valid() { ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, jar) return sdkDep{} } + if !aidlPath.Valid() { ctx.PropertyErrorf("sdk_version", "invalid sdk version %q, %q does not exist", v, aidl) return sdkDep{} } + return sdkDep{ useFiles: true, jar: jarPath.Path(), @@ -262,15 +271,13 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) if sdkDep.useDefaultLibs { ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) - ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) + if !proptools.Bool(j.properties.No_framework_libs) { + ctx.AddDependency(ctx.Module(), libTag, config.DefaultLibraries...) + } } if sdkDep.useModule { ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module) } - } else { - if j.deviceProperties.Dex { - ctx.AddDependency(ctx.Module(), bootClasspathTag, config.DefaultBootclasspathLibraries...) - } } } ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...) @@ -279,6 +286,24 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { android.ExtractSourcesDeps(ctx, j.properties.Srcs) android.ExtractSourcesDeps(ctx, j.properties.Java_resources) + + if j.hasSrcExt(".proto") { + protoDeps(ctx, &j.protoProperties) + } +} + +func hasSrcExt(srcs []string, ext string) bool { + for _, src := range srcs { + if filepath.Ext(src) == ext { + return true + } + } + + return false +} + +func (j *Module) hasSrcExt(ext string) bool { + return hasSrcExt(j.properties.Srcs, ext) } func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, @@ -317,7 +342,9 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { var deps deps sdkDep := decodeSdkDep(ctx, j.deviceProperties.Sdk_version) - if sdkDep.useFiles { + if sdkDep.invalidVersion { + ctx.AddMissingDependencies([]string{sdkDep.module}) + } else if sdkDep.useFiles { deps.classpath = append(deps.classpath, sdkDep.jar) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, sdkDep.aidl) } @@ -345,7 +372,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case staticLibTag: deps.classpath = append(deps.classpath, dep.ClasspathFiles()...) deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...) - deps.staticJarResources = append(deps.staticJarResources, dep.ResourceJarFiles()...) case frameworkResTag: if ctx.ModuleName() == "framework" { // framework.jar has a one-off dependency on the R.java and Manifest.java files @@ -397,15 +423,17 @@ func (j *Module) compile(ctx android.ModuleContext) { srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) - srcFiles = j.genSources(ctx, srcFiles, flags) + if hasSrcExt(srcFiles.Strings(), ".proto") { + flags = protoFlags(ctx, &j.protoProperties, flags) + } - ctx.VisitDirectDeps(func(module blueprint.Module) { - if gen, ok := module.(genrule.SourceFileGenerator); ok { - srcFiles = append(srcFiles, gen.GeneratedSourceFiles()...) - } - }) + var srcFileLists android.Paths + + srcFiles, srcFileLists = j.genSources(ctx, srcFiles, flags) + + srcFileLists = append(srcFileLists, deps.srcFileLists...) - deps.srcFileLists = append(deps.srcFileLists, j.ExtraSrcLists...) + srcFileLists = append(srcFileLists, j.ExtraSrcLists...) var jars android.Paths @@ -417,12 +445,12 @@ func (j *Module) compile(ctx android.ModuleContext) { // a rebuild when error-prone is turned off). // TODO(ccross): Once we always compile with javac9 we may be able to conditionally // enable error-prone without affecting the output class files. - errorprone := RunErrorProne(ctx, srcFiles, deps.srcFileLists, flags, nil) + errorprone := RunErrorProne(ctx, srcFiles, srcFileLists, flags) extraJarDeps = append(extraJarDeps, errorprone) } // Compile java sources into .class files - classes := TransformJavaToClasses(ctx, srcFiles, deps.srcFileLists, flags, extraJarDeps) + classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, extraJarDeps) if ctx.Failed() { return } @@ -443,26 +471,20 @@ func (j *Module) compile(ctx android.ModuleContext) { resDeps = append(resDeps, fileDeps...) if proptools.Bool(j.properties.Include_srcs) { - srcArgs, srcDeps := ResourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) + srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs) resArgs = append(resArgs, srcArgs...) resDeps = append(resDeps, srcDeps...) } if len(resArgs) > 0 { - // Combine classes + resources into classes-full-debug.jar resourceJar := TransformResourcesToJar(ctx, resArgs, resDeps) if ctx.Failed() { return } - j.resourceJarFiles = append(j.resourceJarFiles, resourceJar) jars = append(jars, resourceJar) } - // Propagate the resources from the transitive closure of static dependencies for copying - // into dex jars - j.resourceJarFiles = append(j.resourceJarFiles, deps.staticJarResources...) - // static classpath jars have the resources in them, so the resource jars aren't necessary here jars = append(jars, deps.staticJars...) @@ -483,8 +505,7 @@ func (j *Module) compile(ctx android.ModuleContext) { j.classpathFile = outputFile - // TODO(ccross): handle hostdex - if ctx.Device() && len(srcFiles) > 0 && j.installable() { + if ctx.Device() && j.installable() { dxFlags := j.deviceProperties.Dxflags if false /* emma enabled */ { // If you instrument class files that have local variable debug information in @@ -537,17 +558,12 @@ func (j *Module) compile(ctx android.ModuleContext) { return } - // Compile classes.jar into classes.dex - dexJarFile := TransformClassesJarToDexJar(ctx, desugarJar, flags) + // Compile classes.jar into classes.dex and then javalib.jar + outputFile = TransformClassesJarToDexJar(ctx, "javalib.jar", desugarJar, flags) if ctx.Failed() { return } - jars := android.Paths{dexJarFile} - jars = append(jars, j.resourceJarFiles...) - - outputFile = TransformJarsToJar(ctx, "javalib.jar", jars, android.OptionalPath{}, true) - j.dexJarFile = outputFile } ctx.CheckbuildFile(outputFile) @@ -564,10 +580,6 @@ func (j *Module) ClasspathFiles() android.Paths { return android.Paths{j.classpathFile} } -func (j *Module) ResourceJarFiles() android.Paths { - return j.resourceJarFiles -} - func (j *Module) AidlIncludeDirs() android.Paths { return j.exportAidlIncludeDirs } @@ -599,23 +611,30 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) { j.deps(ctx) } -func LibraryFactory() android.Module { - module := &Library{} +func LibraryFactory(installable bool) func() android.Module { + return func() android.Module { + module := &Library{} - module.deviceProperties.Dex = true + if !installable { + module.properties.Installable = proptools.BoolPtr(false) + } - module.AddProperties( - &module.Module.properties, - &module.Module.deviceProperties) + module.AddProperties( + &module.Module.properties, + &module.Module.deviceProperties, + &module.Module.protoProperties) - InitJavaModule(module, android.HostAndDeviceSupported) - return module + InitJavaModule(module, android.HostAndDeviceSupported) + return module + } } func LibraryHostFactory() android.Module { module := &Library{} - module.AddProperties(&module.Module.properties) + module.AddProperties( + &module.Module.properties, + &module.Module.protoProperties) InitJavaModule(module, android.HostSupported) return module @@ -656,11 +675,10 @@ func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) { func BinaryFactory() android.Module { module := &Binary{} - module.deviceProperties.Dex = true - module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, + &module.Module.protoProperties, &module.binaryProperties) InitJavaModule(module, android.HostAndDeviceSupported) @@ -673,6 +691,7 @@ func BinaryHostFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, + &module.Module.protoProperties, &module.binaryProperties) InitJavaModule(module, android.HostSupported) @@ -724,11 +743,6 @@ func (j *Import) ClasspathFiles() android.Paths { return j.classpathFiles } -func (j *Import) ResourceJarFiles() android.Paths { - // resources are in the ClasspathFiles - return nil -} - func (j *Import) AidlIncludeDirs() android.Paths { return nil } |