From be1da475d0b1a398b8d05f93b9b76cab2b45f3a3 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 7 Jul 2017 15:59:46 -0700 Subject: Use dependency tags for java modules Test: java_test.go Change-Id: Id265a2acd6e6c4ce7764f77c888e22b1fddc02c4 --- java/app.go | 5 +-- java/java.go | 103 ++++++++++++++++++++++++++--------------------------------- 2 files changed, 47 insertions(+), 61 deletions(-) (limited to 'java') diff --git a/java/app.go b/java/app.go index 2f2b899d..fccd3823 100644 --- a/java/app.go +++ b/java/app.go @@ -68,17 +68,14 @@ type AndroidApp struct { func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { a.Module.deps(ctx) - var deps []string if !a.properties.No_standard_libraries { switch a.deviceProperties.Sdk_version { // TODO: Res_sdk_version? case "current", "system_current", "": - deps = append(deps, "framework-res") + ctx.AddDependency(ctx.Module(), frameworkResTag, "framework-res") default: // We'll already have a dependency on an sdk prebuilt android.jar } } - - ctx.AddDependency(ctx.Module(), nil, deps...) } func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { diff --git a/java/java.go b/java/java.go index 195a0783..73490650 100644 --- a/java/java.go +++ b/java/java.go @@ -147,45 +147,46 @@ type JavaDependency interface { AidlIncludeDirs() android.Paths } -func (j *Module) BootClasspath(ctx android.BaseContext) string { - if ctx.Device() { - switch j.deviceProperties.Sdk_version { - case "": - return "core-libart" - case "current": - // TODO: !TARGET_BUILD_APPS - // TODO: export preprocessed framework.aidl from android_stubs_current - return "android_stubs_current" - case "system_current": - return "android_system_stubs_current" - default: - return "sdk_v" + j.deviceProperties.Sdk_version - } - } else { - if j.deviceProperties.Dex { - return "core-libart" - } else { - return "" - } - } +type dependencyTag struct { + blueprint.BaseDependencyTag + name string } -func (j *Module) deps(ctx android.BottomUpMutatorContext) { - var deps []string +var ( + javaStaticLibTag = dependencyTag{name: "staticlib"} + javaLibTag = dependencyTag{name: "javalib"} + bootClasspathTag = dependencyTag{name: "bootclasspath"} + frameworkResTag = dependencyTag{name: "framework-res"} + sdkDependencyTag = dependencyTag{name: "sdk"} +) +func (j *Module) deps(ctx android.BottomUpMutatorContext) { if !j.properties.No_standard_libraries { - bootClasspath := j.BootClasspath(ctx) - if bootClasspath != "" { - deps = append(deps, bootClasspath) + if ctx.Device() { + switch j.deviceProperties.Sdk_version { + case "": + ctx.AddDependency(ctx.Module(), bootClasspathTag, "core-libart") + case "current": + // TODO: !TARGET_BUILD_APPS + // TODO: export preprocessed framework.aidl from android_stubs_current + ctx.AddDependency(ctx.Module(), bootClasspathTag, "android_stubs_current") + case "system_current": + ctx.AddDependency(ctx.Module(), bootClasspathTag, "android_system_stubs_current") + default: + ctx.AddDependency(ctx.Module(), sdkDependencyTag, "sdk_v"+j.deviceProperties.Sdk_version) + } + } else { + if j.deviceProperties.Dex { + ctx.AddDependency(ctx.Module(), bootClasspathTag, "core-libart") + } } + if ctx.Device() && j.deviceProperties.Sdk_version == "" { - deps = append(deps, config.DefaultLibraries...) + ctx.AddDependency(ctx.Module(), javaLibTag, config.DefaultLibraries...) } } - deps = append(deps, j.properties.Java_libs...) - deps = append(deps, j.properties.Java_static_libs...) - - ctx.AddDependency(ctx.Module(), nil, deps...) + ctx.AddDependency(ctx.Module(), javaLibTag, j.properties.Java_libs...) + ctx.AddDependency(ctx.Module(), javaStaticLibTag, j.properties.Java_static_libs...) } func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, @@ -228,27 +229,23 @@ func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths return } - if otherName == j.BootClasspath(ctx) { + switch tag { + case bootClasspathTag: bootClasspath = android.OptionalPathForPath(javaDep.ClasspathFile()) - } else if inList(otherName, config.DefaultLibraries) { + case javaLibTag: classpath = append(classpath, javaDep.ClasspathFile()) - } else if inList(otherName, j.properties.Java_libs) { - classpath = append(classpath, javaDep.ClasspathFile()) - } else if inList(otherName, j.properties.Java_static_libs) { + case javaStaticLibTag: classpath = append(classpath, javaDep.ClasspathFile()) classJarSpecs = append(classJarSpecs, javaDep.ClassJarSpecs()...) resourceJarSpecs = append(resourceJarSpecs, javaDep.ResourceJarSpecs()...) - } else if otherName == "framework-res" { + case frameworkResTag: if ctx.ModuleName() == "framework" { // framework.jar has a one-off dependency on the R.java and Manifest.java files // generated by framework-res.apk srcFileLists = append(srcFileLists, module.(*AndroidApp).aaptJavaFileList) } - } else { - panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) - } - aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...) - if sdkDep, ok := module.(sdkDependency); ok { + case sdkDependencyTag: + sdkDep := module.(sdkDependency) if sdkDep.AidlPreprocessed().Valid() { if aidlPreprocess.Valid() { ctx.ModuleErrorf("multiple dependencies with preprocessed aidls:\n %q\n %q", @@ -257,7 +254,11 @@ func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths aidlPreprocess = sdkDep.AidlPreprocessed() } } + default: + panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) } + + aidlIncludeDirs = append(aidlIncludeDirs, javaDep.AidlIncludeDirs()...) }) return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess, @@ -510,16 +511,10 @@ func JavaBinaryHostFactory() android.Module { // Java prebuilts // -type JavaPrebuiltProperties struct { - Srcs []string -} - type JavaPrebuilt struct { android.ModuleBase prebuilt android.Prebuilt - properties JavaPrebuiltProperties - classpathFile android.Path classJarSpecs, resourceJarSpecs []jarSpec } @@ -532,11 +527,7 @@ func (j *JavaPrebuilt) DepsMutator(ctx android.BottomUpMutatorContext) { } func (j *JavaPrebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { - if len(j.properties.Srcs) != 1 { - ctx.ModuleErrorf("expected exactly one jar in srcs") - return - } - prebuilt := android.PathForModuleSrc(ctx, j.properties.Srcs[0]) + prebuilt := j.prebuilt.Path(ctx) classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, prebuilt) @@ -567,9 +558,7 @@ func (j *JavaPrebuilt) AidlIncludeDirs() android.Paths { func JavaPrebuiltFactory() android.Module { module := &JavaPrebuilt{} - module.AddProperties( - &module.properties, - &module.prebuilt.Properties) + module.AddProperties(&module.prebuilt.Properties) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) return module @@ -612,7 +601,7 @@ func SdkPrebuiltFactory() android.Module { module := &sdkPrebuilt{} module.AddProperties( - &module.properties, + &module.prebuilt.Properties, &module.sdkProperties) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) -- cgit v1.2.3