diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/java/java.go b/java/java.go index 5f4a09093..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 { @@ -343,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) { @@ -383,6 +402,10 @@ type SrcDependency interface { CompiledSrcJars() android.Paths } +type xref interface { + XrefJavaFiles() android.Paths +} + func (j *Module) CompiledSrcs() android.Paths { return j.compiledJavaSrcs } @@ -391,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) { @@ -1139,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 } @@ -2213,6 +2246,30 @@ func DefaultsFactory(props ...interface{}) android.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 |