From 44b481b81bff20fc530b00859852d40d726663c6 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 17 Jun 2020 16:59:43 +0100 Subject: [PATCH] Fix check-boot-jars when a boot jar is provided by prebuilt Previously, when a boot jar was provided by a java_sdk_library_import module the check-boot-jars check failed because the file it depended on was not available. In an incremental build the build failed due to the file in the out directory not having a rule to generate it. That was because the module was named prebuilt_. instead of .. This was fixed by simply removing prebuilt_ prefix from the name if it was present. After fixing that the check-boot-jars still did not work properly because it was expecting a jar file containing .class files but instead was given a jar file containing .dex files which meant the check did not work properly. This was fixed by defining a new ApexDependency interface for use by the apex/apex.go code to use instead of java.Dependency for generating the androidmk entries. The *SdkLibraryImport type then implemented those, by delegating to the implementation library. Bug: 158304459 Bug: 159112414 Test: m check-boot-jars m checkbuild manual inspection of the .jar file used by check-boot-jars to ensure it contained .class files and not .dex files. Change-Id: I545c5c9072dd472337d2f9b4dfdf08f53c981662 --- apex/androidmk.go | 2 +- apex/apex.go | 4 +++- java/java.go | 9 +++++++-- java/sdk_library.go | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/apex/androidmk.go b/apex/androidmk.go index 91a405c58..4dd14d856 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -184,7 +184,7 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo // we need to remove the suffix from LOCAL_MODULE_STEM, otherwise // we will have foo.jar.jar fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", strings.TrimSuffix(fi.Stem(), ".jar")) - if javaModule, ok := fi.module.(java.Dependency); ok { + if javaModule, ok := fi.module.(java.ApexDependency); ok { fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", javaModule.ImplementationAndResourcesJars()[0].String()) fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", javaModule.HeaderJars()[0].String()) } else { diff --git a/apex/apex.go b/apex/apex.go index ce5d663cf..a4af7aa35 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1652,7 +1652,9 @@ type javaDependency interface { func apexFileForJavaLibrary(ctx android.BaseModuleContext, lib javaDependency, module android.Module) apexFile { dirInApex := "javalib" fileToCopy := lib.DexJarBuildPath() - af := newApexFile(ctx, fileToCopy, module.Name(), dirInApex, javaSharedLib, module) + // Remove prebuilt_ if necessary so the source and prebuilt modules have the same name. + name := strings.TrimPrefix(module.Name(), "prebuilt_") + af := newApexFile(ctx, fileToCopy, name, dirInApex, javaSharedLib, module) af.jacocoReportClassesFile = lib.JacocoReportClassesFile() af.stem = lib.Stem() + ".jar" return af diff --git a/java/java.go b/java/java.go index bd5f6b7d5..d7f09f970 100644 --- a/java/java.go +++ b/java/java.go @@ -496,11 +496,16 @@ func (j *Module) OutputFiles(tag string) (android.Paths, error) { var _ android.OutputFileProducer = (*Module)(nil) -type Dependency interface { +// Methods that need to be implemented for a module that is added to apex java_libs property. +type ApexDependency interface { HeaderJars() android.Paths + ImplementationAndResourcesJars() android.Paths +} + +type Dependency interface { + ApexDependency ImplementationJars() android.Paths ResourceJars() android.Paths - ImplementationAndResourcesJars() android.Paths DexJarBuildPath() android.Path DexJarInstallPath() android.Path AidlIncludeDirs() android.Paths diff --git a/java/sdk_library.go b/java/sdk_library.go index 503ad5914..e83ec0eba 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1999,6 +1999,26 @@ func (module *SdkLibraryImport) Stem() string { return module.BaseModuleName() } +var _ ApexDependency = (*SdkLibraryImport)(nil) + +// to satisfy java.ApexDependency interface +func (module *SdkLibraryImport) HeaderJars() android.Paths { + if module.implLibraryModule == nil { + return nil + } else { + return module.implLibraryModule.HeaderJars() + } +} + +// to satisfy java.ApexDependency interface +func (module *SdkLibraryImport) ImplementationAndResourcesJars() android.Paths { + if module.implLibraryModule == nil { + return nil + } else { + return module.implLibraryModule.ImplementationAndResourcesJars() + } +} + // // java_sdk_library_xml //