From 4c61d9745723e2d50e6d763a3d5509d0813bf1a6 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 19 Aug 2019 14:56:02 +0900 Subject: [PATCH 1/3] Prepare to be able to put framework-res in srcs This change introduces two changes required to put framework-res explicitly in srcs property, without relying on the build system to specially add framework-res as a dependency to framework-minus-apex, etc. 1) R.java and Manifest.java generated from aapt were packaged to the file R.jar directly under the gen directory. With this change, the file becomes android/R.srcjar under the gen directory. 2) android_app module now overrides OutputFileProducer interface so that it can recognize "{.aapt.srcjar}" tag to reference the generated srcjar file. Being able to put framework-res in srcs allows us to pass all the source files (both in the source tree and the ones generates) via a filegroup. Previously, the source files could only be passed via the java_library module type. This caused a circular dependency problem when the java library was used as an input (src_libs) of the droiddoc module. Using filegroup eliminates the circular dependency. Bug: 70046217 Test: m Merged-In: I9ab6116bcc6fa3da60933d427575463b05ae69b4 (cherry picked from commit 94f37f33ed9dc5c7ad6ff901f5aa613970513ead) Change-Id: I9ab6116bcc6fa3da60933d427575463b05ae69b4 --- java/aar.go | 6 ++++-- java/app.go | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/java/aar.go b/java/aar.go index a4e6f910d..f5d7e9761 100644 --- a/java/aar.go +++ b/java/aar.go @@ -249,7 +249,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex } packageRes := android.PathForModuleOut(ctx, "package-res.apk") - srcJar := android.PathForModuleGen(ctx, "R.jar") + // the subdir "android" is required to be filtered by package names + srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") rTxt := android.PathForModuleOut(ctx, "R.txt") // This file isn't used by Soong, but is generated for exporting @@ -620,7 +621,8 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { aapt2CompileZip(ctx, flata, aar, "res", compileFlags) a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk") - srcJar := android.PathForModuleGen(ctx, "R.jar") + // the subdir "android" is required to be filtered by package names + srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") rTxt := android.PathForModuleOut(ctx, "R.txt") a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") diff --git a/java/app.go b/java/app.go index 7df4358d7..0af89fd2a 100644 --- a/java/app.go +++ b/java/app.go @@ -539,6 +539,15 @@ func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string { return String(a.overridableAppProperties.Certificate) } +// For OutputFileProducer interface +func (a *AndroidApp) OutputFiles(tag string) (android.Paths, error) { + switch tag { + case ".aapt.srcjar": + return []android.Path{a.aaptSrcJar}, nil + } + return a.Library.OutputFiles(tag) +} + // android_app compiles sources and Android resources into an Android application package `.apk` file. func AndroidAppFactory() android.Module { module := &AndroidApp{} From 0650aca86aa0159e5b5d9f51991e2eb6b56d3259 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 23 Aug 2019 16:08:57 +0900 Subject: [PATCH 2/3] Remove the automatic dependency to framework-res.apk for R/Manifest framework-minus-apex and framework-annotation-proc had automatic dependency to framework-res.apk to get the generated R.java and Manifest.java as their inputs. That is no longer needed as the sources are fed from framework-srcs filegroup. Bug: 70046217 Test: m Merged-In: Ibb03db01c177d6e908cbbdf91f18be8744f02c03 (cherry picked from commit 8cc55bdffe1ebb4cfcfa412d3733fd918c58db60) Change-Id: Ibb03db01c177d6e908cbbdf91f18be8744f02c03 --- java/java.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/java/java.go b/java/java.go index 2193a2bd7..494a4e7c0 100644 --- a/java/java.go +++ b/java/java.go @@ -550,9 +550,6 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } else if *j.deviceProperties.System_modules != "none" { ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules) } - if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") { - ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res") - } if ctx.ModuleName() == "android_stubs_current" || ctx.ModuleName() == "android_system_stubs_current" || ctx.ModuleName() == "android_test_stubs_current" { @@ -833,12 +830,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { } else { ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) } - case frameworkResTag: - 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) - } case frameworkApkTag: if ctx.ModuleName() == "android_stubs_current" || ctx.ModuleName() == "android_system_stubs_current" || From 01d5401dc0ac3a7d8672497813fc50599f1dff76 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 23 Aug 2019 19:12:42 +0900 Subject: [PATCH 3/3] Remove srcs_lib and srcs_lib_whitelist_pkgs They are no longer used. Sources are provided via filegroup. Also removing the SrcDependency interface as it is no longer used. Bug: 135922046 Test: m Merged-In: I81f9614d20fbdd2f7d18340d6dbdb592e7acde06 (cherry picked from commit fa21cba64a3a14164642a7067c071f861b7ac96e) Change-Id: I81f9614d20fbdd2f7d18340d6dbdb592e7acde06 --- java/droiddoc.go | 30 ------------------------------ java/java.go | 18 +----------------- java/sdk_library.go | 10 ---------- 3 files changed, 1 insertion(+), 57 deletions(-) diff --git a/java/droiddoc.go b/java/droiddoc.go index 8b15e0fa5..63da6d275 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -61,12 +61,6 @@ type JavadocProperties struct { // list of java libraries that will be in the classpath. Libs []string `android:"arch_variant"` - // the java library (in classpath) for documentation that provides java srcs and srcjars. - Srcs_lib *string - - // List of packages to document from srcs_lib - Srcs_lib_whitelist_pkgs []string - // If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true. Installable *bool @@ -422,9 +416,6 @@ func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { } ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) - if j.properties.Srcs_lib != nil { - ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib) - } } func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags { @@ -518,27 +509,6 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { default: ctx.ModuleErrorf("depends on non-java module %q", otherName) } - case srcsLibTag: - switch dep := module.(type) { - case Dependency: - srcs := dep.(SrcDependency).CompiledSrcs() - for _, src := range srcs { - if _, ok := src.(android.WritablePath); ok { // generated sources - deps.srcs = append(deps.srcs, src) - } else { // select source path for documentation based on whitelist path prefixs. - for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs { - pkgAsPath := filepath.Join(strings.Split(pkg, ".")...) - if strings.HasPrefix(src.Rel(), pkgAsPath) { - deps.srcs = append(deps.srcs, src) - break - } - } - } - } - deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...) - default: - ctx.ModuleErrorf("depends on non-java module %q", otherName) - } case systemModulesTag: if deps.systemModules != nil { panic("Found two system module dependencies") diff --git a/java/java.go b/java/java.go index 494a4e7c0..4ae40bf0b 100644 --- a/java/java.go +++ b/java/java.go @@ -404,29 +404,14 @@ type SdkLibraryDependency interface { SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths } -type SrcDependency interface { - CompiledSrcs() android.Paths - CompiledSrcJars() android.Paths -} - type xref interface { XrefJavaFiles() android.Paths } -func (j *Module) CompiledSrcs() android.Paths { - return j.compiledJavaSrcs -} - -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) { android.InitAndroidArchModule(module, hod, android.MultilibCommon) android.InitDefaultableModule(module) @@ -1033,8 +1018,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { srcJars = append(srcJars, aaptSrcJar) } - // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs - // that IDEInfo struct will use + // Collect source files and filter out Exclude_srcs that IDEInfo struct will use j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...) if j.properties.Jarjar_rules != nil { diff --git a/java/sdk_library.go b/java/sdk_library.go index 56b30b2cf..30fd1c4e2 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -100,12 +100,6 @@ type sdkLibraryProperties struct { // $(location