diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 106 |
1 files changed, 81 insertions, 25 deletions
diff --git a/java/java.go b/java/java.go index 7c84e766f..fea38b51f 100644 --- a/java/java.go +++ b/java/java.go @@ -50,6 +50,21 @@ func init() { android.RegisterModuleType("dex_import", DexImportFactory) android.RegisterSingletonType("logtags", LogtagsSingleton) + android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) +} + +func (j *Module) checkPlatformAPI(ctx android.ModuleContext) { + if sc, ok := ctx.Module().(sdkContext); ok { + usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis) + if usePlatformAPI != (sc.sdkVersion() == "") { + if usePlatformAPI { + ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.") + } else { + ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.") + } + } + + } } // TODO: @@ -178,8 +193,8 @@ type CompilerDeviceProperties struct { // list of module-specific flags that will be used for dex compiles Dxflags []string `android:"arch_variant"` - // if not blank, set to the version of the sdk to compile against. Defaults to compiling against the current - // sdk if platform_apis is not set. + // if not blank, set to the version of the sdk to compile against. + // Defaults to compiling against the current platform. Sdk_version *string // if not blank, set the minimum version of the sdk that the compiled artifacts will run against. @@ -190,7 +205,8 @@ type CompilerDeviceProperties struct { // Defaults to sdk_version if not set. Target_sdk_version *string - // if true, compile against the platform APIs instead of an SDK. + // It must be true only if sdk_version is empty. + // This field works in only android_app, otherwise nothing happens. Platform_apis *bool Aidl struct { @@ -267,6 +283,7 @@ func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool { type Module struct { android.ModuleBase android.DefaultableModuleBase + android.ApexModuleBase properties CompilerProperties protoProperties android.ProtoProperties @@ -342,6 +359,9 @@ type Module struct { hiddenAPI dexpreopter + + // list of the xref extraction files + kytheFiles android.Paths } func (j *Module) OutputFiles(tag string) (android.Paths, error) { @@ -382,6 +402,10 @@ type SrcDependency interface { CompiledSrcJars() android.Paths } +type xref interface { + XrefJavaFiles() android.Paths +} + func (j *Module) CompiledSrcs() android.Paths { return j.compiledJavaSrcs } @@ -390,6 +414,10 @@ func (j *Module) CompiledSrcJars() android.Paths { return j.compiledSrcJars } +func (j *Module) XrefJavaFiles() android.Paths { + return j.kytheFiles +} + var _ SrcDependency = (*Module)(nil) func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { @@ -632,8 +660,7 @@ type deps struct { aidlIncludeDirs android.Paths srcs android.Paths srcJars android.Paths - systemModules android.Path - systemModulesDeps android.Paths + systemModules *systemModules aidlPreprocess android.OptionalPath kotlinStdlib android.Paths kotlinAnnotations android.Paths @@ -844,8 +871,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { if sm.outputDir == nil || len(sm.outputDeps) == 0 { panic("Missing directory for system module dependency") } - deps.systemModules = sm.outputDir - deps.systemModulesDeps = sm.outputDeps + deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps} } } }) @@ -973,10 +999,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB } // systemModules - if deps.systemModules != nil { - flags.systemModules = append(flags.systemModules, deps.systemModules) - flags.systemModulesDeps = append(flags.systemModulesDeps, deps.systemModulesDeps...) - } + flags.systemModules = deps.systemModules // aidl flags. flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) @@ -1143,6 +1166,12 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps) jars = append(jars, classes) } + if ctx.Config().EmitXrefRules() { + extractionFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".kzip") + emitXrefRule(ctx, extractionFile, uniqueSrcFiles, srcJars, flags, extraJarDeps, "xref") + j.kytheFiles = append(j.kytheFiles, extractionFile) + + } if ctx.Failed() { return } @@ -1322,11 +1351,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { return } - if !ctx.Config().UnbundledBuild() { - // Hidden API CSV generation and dex encoding - dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile, - j.deviceProperties.UncompressDex) - } + // Hidden API CSV generation and dex encoding + dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile, + j.deviceProperties.UncompressDex) // merge dex jar with resources if necessary if j.resourceJar != nil { @@ -1557,7 +1584,8 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex j.compile(ctx, nil) - if (Bool(j.properties.Installable) || ctx.Host()) && !android.DirectlyInAnyApex(ctx, ctx.ModuleName()) { + exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform() + if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile) } @@ -1588,6 +1616,7 @@ func LibraryFactory() android.Module { &module.Module.protoProperties) InitJavaModule(module, android.HostAndDeviceSupported) + android.InitApexModule(module) return module } @@ -1610,6 +1639,7 @@ func LibraryHostFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) InitJavaModule(module, android.HostSupported) + android.InitApexModule(module) return module } @@ -1865,6 +1895,7 @@ type ImportProperties struct { type Import struct { android.ModuleBase android.DefaultableModuleBase + android.ApexModuleBase prebuilt android.Prebuilt properties ImportProperties @@ -2021,6 +2052,7 @@ func ImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Jars) InitJavaModule(module, android.HostAndDeviceSupported) + android.InitApexModule(module) return module } @@ -2036,18 +2068,20 @@ func ImportFactoryHost() android.Module { android.InitPrebuiltModule(module, &module.properties.Jars) InitJavaModule(module, android.HostSupported) + android.InitApexModule(module) return module } // dex_import module type DexImportProperties struct { - Jars []string + Jars []string `android:"path"` } type DexImport struct { android.ModuleBase android.DefaultableModuleBase + android.ApexModuleBase prebuilt android.Prebuilt properties DexImportProperties @@ -2070,10 +2104,6 @@ func (j *DexImport) Name() string { return j.prebuilt.Name(j.ModuleBase.Name()) } -func (j *DexImport) DepsMutator(ctx android.BottomUpMutatorContext) { - android.ExtractSourcesDeps(ctx, j.properties.Jars) -} - func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { if len(j.properties.Jars) != 1 { ctx.PropertyErrorf("jars", "exactly one jar must be provided") @@ -2094,14 +2124,14 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { // use zip2zip to uncompress classes*.dex files rule.Command(). - Tool(ctx.Config().HostToolPath(ctx, "zip2zip")). + BuiltTool(ctx, "zip2zip"). FlagWithInput("-i ", inputJar). FlagWithOutput("-o ", temporary). FlagWithArg("-0 ", "'classes*.dex'") // use zipalign to align uncompressed classes*.dex files rule.Command(). - Tool(ctx.Config().HostToolPath(ctx, "zipalign")). + BuiltTool(ctx, "zipalign"). Flag("-f"). Text("4"). Input(temporary). @@ -2143,6 +2173,7 @@ func DexImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Jars) InitJavaModule(module, android.DeviceSupported) + android.InitApexModule(module) return module } @@ -2152,6 +2183,7 @@ func DexImportFactory() android.Module { type Defaults struct { android.ModuleBase android.DefaultsModuleBase + android.ApexModuleBase } // java_defaults provides a set of properties that can be inherited by other java or android modules. @@ -2210,10 +2242,34 @@ func DefaultsFactory(props ...interface{}) android.Module { ) android.InitDefaultsModule(module) - + android.InitApexModule(module) return module } +func kytheExtractJavaFactory() android.Singleton { + return &kytheExtractJavaSingleton{} +} + +type kytheExtractJavaSingleton struct { +} + +func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) { + var xrefTargets android.Paths + ctx.VisitAllModules(func(module android.Module) { + if javaModule, ok := module.(xref); ok { + xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...) + } + }) + // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets + if len(xrefTargets) > 0 { + ctx.Build(pctx, android.BuildParams{ + Rule: blueprint.Phony, + Output: android.PathForPhony(ctx, "xref_java"), + Inputs: xrefTargets, + }) + } +} + var Bool = proptools.Bool var BoolDefault = proptools.BoolDefault var String = proptools.String |