Merge changes from topic "java_test_junit"

am: a192c7370c

Change-Id: I5d0b031e9daded8c973cc7b65c5c44330fe1c293
This commit is contained in:
Colin Cross
2018-08-16 21:52:17 -07:00
committed by android-build-merger
5 changed files with 109 additions and 19 deletions

View File

@@ -498,6 +498,14 @@ func (a *AARImport) ImplementationJars() android.Paths {
return android.Paths{a.classpathFile} return android.Paths{a.classpathFile}
} }
func (a *AARImport) ResourceJars() android.Paths {
return nil
}
func (a *AARImport) ImplementationAndResourcesJars() android.Paths {
return android.Paths{a.classpathFile}
}
func (a *AARImport) AidlIncludeDirs() android.Paths { func (a *AARImport) AidlIncludeDirs() android.Paths {
return nil return nil
} }

View File

@@ -25,7 +25,7 @@ import (
func (library *Library) AndroidMk() android.AndroidMkData { func (library *Library) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{ return android.AndroidMkData{
Class: "JAVA_LIBRARIES", Class: "JAVA_LIBRARIES",
OutputFile: android.OptionalPathForPath(library.implementationJarFile), OutputFile: android.OptionalPathForPath(library.implementationAndResourcesJar),
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Extra: []android.AndroidMkExtraFunc{ Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) { func(w io.Writer, outputFile android.Path) {
@@ -84,14 +84,14 @@ func (library *Library) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex") fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES") fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationJarFile.String()) fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationAndResourcesJar.String())
if library.installFile == nil { if library.installFile == nil {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
} }
if library.dexJarFile != nil { if library.dexJarFile != nil {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
} }
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.implementationJarFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " ")) fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
} }
@@ -159,8 +159,13 @@ func (binary *Binary) AndroidMk() android.AndroidMkData {
if !binary.isWrapperVariant { if !binary.isWrapperVariant {
return android.AndroidMkData{ return android.AndroidMkData{
Class: "JAVA_LIBRARIES", Class: "JAVA_LIBRARIES",
OutputFile: android.OptionalPathForPath(binary.implementationJarFile), OutputFile: android.OptionalPathForPath(binary.outputFile),
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
},
},
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
android.WriteAndroidMkData(w, data) android.WriteAndroidMkData(w, data)
@@ -198,8 +203,8 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData {
if app.dexJarFile != nil { if app.dexJarFile != nil {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", app.dexJarFile.String())
} }
if app.implementationJarFile != nil { if app.implementationAndResourcesJar != nil {
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationJarFile) fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", app.implementationAndResourcesJar.String())
} }
if app.headerJarFile != nil { if app.headerJarFile != nil {
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", app.headerJarFile.String())

View File

@@ -183,6 +183,5 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
}) })
} }
j.dexJarFile = javalibJar
return javalibJar return javalibJar
} }

View File

@@ -272,13 +272,22 @@ type Module struct {
protoProperties android.ProtoProperties protoProperties android.ProtoProperties
deviceProperties CompilerDeviceProperties deviceProperties CompilerDeviceProperties
// header jar file suitable for inserting into the bootclasspath/classpath of another compile // jar file containing header classes including static library dependencies, suitable for
// inserting into the bootclasspath/classpath of another compile
headerJarFile android.Path headerJarFile android.Path
// full implementation jar file suitable for static dependency of another module compile // jar file containing implementation classes including static library dependencies but no
// resources
implementationJarFile android.Path implementationJarFile android.Path
// output file containing classes.dex // jar file containing only resources including from static library dependencies
resourceJar android.Path
// jar file containing implementation classes and resources including static library
// dependencies
implementationAndResourcesJar android.Path
// output file containing classes.dex and resources
dexJarFile android.Path dexJarFile android.Path
// output file containing uninstrumented classes that will be instrumented by jacoco // output file containing uninstrumented classes that will be instrumented by jacoco
@@ -287,7 +296,7 @@ type Module struct {
// output file containing mapping of obfuscated names // output file containing mapping of obfuscated names
proguardDictionary android.Path proguardDictionary android.Path
// output file suitable for installing or running // output file of the module, which may be a classes jar or a dex jar
outputFile android.Path outputFile android.Path
exportAidlIncludeDirs android.Paths exportAidlIncludeDirs android.Paths
@@ -317,6 +326,8 @@ var _ android.SourceFileProducer = (*Module)(nil)
type Dependency interface { type Dependency interface {
HeaderJars() android.Paths HeaderJars() android.Paths
ImplementationJars() android.Paths ImplementationJars() android.Paths
ResourceJars() android.Paths
ImplementationAndResourcesJars() android.Paths
AidlIncludeDirs() android.Paths AidlIncludeDirs() android.Paths
ExportedSdkLibs() []string ExportedSdkLibs() []string
} }
@@ -673,7 +684,7 @@ type deps struct {
processorPath classpath processorPath classpath
staticJars android.Paths staticJars android.Paths
staticHeaderJars android.Paths staticHeaderJars android.Paths
staticJarResources android.Paths staticResourceJars android.Paths
aidlIncludeDirs android.Paths aidlIncludeDirs android.Paths
srcs android.Paths srcs android.Paths
srcJars android.Paths srcJars android.Paths
@@ -794,10 +805,11 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.classpath = append(deps.classpath, dep.HeaderJars()...) deps.classpath = append(deps.classpath, dep.HeaderJars()...)
deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...) deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...) deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
// sdk lib names from dependencies are re-exported // sdk lib names from dependencies are re-exported
j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...) j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
case annoTag: case annoTag:
deps.processorPath = append(deps.processorPath, dep.ImplementationJars()...) deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
case frameworkResTag: case frameworkResTag:
if ctx.ModuleName() == "framework" { if ctx.ModuleName() == "framework" {
// framework.jar has a one-off dependency on the R.java and Manifest.java files // framework.jar has a one-off dependency on the R.java and Manifest.java files
@@ -817,7 +829,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
// Normally the package rule runs aapt, which includes the resource, // Normally the package rule runs aapt, which includes the resource,
// but we're not running that in our package rule so just copy in the // but we're not running that in our package rule so just copy in the
// resource files here. // resource files here.
deps.staticJarResources = append(deps.staticJarResources, dep.(*AndroidApp).exportPackage) deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
} }
case kotlinStdlibTag: case kotlinStdlibTag:
deps.kotlinStdlib = dep.HeaderJars() deps.kotlinStdlib = dep.HeaderJars()
@@ -1149,16 +1161,27 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
if len(resArgs) > 0 { if len(resArgs) > 0 {
resourceJar := android.PathForModuleOut(ctx, "res", jarName) resourceJar := android.PathForModuleOut(ctx, "res", jarName)
TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps) TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
j.resourceJar = resourceJar
if ctx.Failed() { if ctx.Failed() {
return return
} }
jars = append(jars, resourceJar)
} }
// static classpath jars have the resources in them, so the resource jars aren't necessary here if len(deps.staticResourceJars) > 0 {
var jars android.Paths
if j.resourceJar != nil {
jars = append(jars, j.resourceJar)
}
jars = append(jars, deps.staticResourceJars...)
combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
false, nil, nil)
j.resourceJar = combinedJar
}
jars = append(jars, deps.staticJars...) jars = append(jars, deps.staticJars...)
jars = append(jars, deps.staticJarResources...) jars = append(jars, deps.staticResourceJars...)
var manifest android.OptionalPath var manifest android.OptionalPath
if j.properties.Manifest != nil { if j.properties.Manifest != nil {
@@ -1203,12 +1226,21 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
} }
} }
// jarjar implementation jar if necessary
if j.properties.Jarjar_rules != nil { if j.properties.Jarjar_rules != nil {
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
// Transform classes.jar into classes-jarjar.jar // Transform classes.jar into classes-jarjar.jar
jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName) jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules) TransformJarJar(ctx, jarjarFile, outputFile, jarjar_rules)
outputFile = jarjarFile outputFile = jarjarFile
// jarjar resource jar if necessary
if j.resourceJar != nil {
resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, jarjar_rules)
j.resourceJar = resourceJarJarFile
}
if ctx.Failed() { if ctx.Failed() {
return return
} }
@@ -1228,14 +1260,41 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
outputFile = j.instrument(ctx, flags, outputFile, jarName) outputFile = j.instrument(ctx, flags, outputFile, jarName)
} }
// merge implementation jar with resources if necessary
implementationAndResourcesJar := outputFile
if j.resourceJar != nil {
jars := android.Paths{implementationAndResourcesJar, j.resourceJar}
combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{},
false, nil, nil)
implementationAndResourcesJar = combinedJar
}
j.implementationAndResourcesJar = implementationAndResourcesJar
if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) { if ctx.Device() && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
var dexOutputFile android.ModuleOutPath var dexOutputFile android.ModuleOutPath
dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName) dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
if ctx.Failed() { if ctx.Failed() {
return return
} }
outputFile = dexOutputFile
// merge dex jar with resources if necessary
if j.resourceJar != nil {
jars := android.Paths{dexOutputFile, j.resourceJar}
combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
false, nil, nil)
dexOutputFile = combinedJar
} }
j.dexJarFile = dexOutputFile
outputFile = dexOutputFile
} else {
outputFile = implementationAndResourcesJar
}
ctx.CheckbuildFile(outputFile) ctx.CheckbuildFile(outputFile)
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
@@ -1307,6 +1366,17 @@ func (j *Module) ImplementationJars() android.Paths {
return android.Paths{j.implementationJarFile} return android.Paths{j.implementationJarFile}
} }
func (j *Module) ResourceJars() android.Paths {
if j.resourceJar == nil {
return nil
}
return android.Paths{j.resourceJar}
}
func (j *Module) ImplementationAndResourcesJars() android.Paths {
return android.Paths{j.implementationAndResourcesJar}
}
func (j *Module) AidlIncludeDirs() android.Paths { func (j *Module) AidlIncludeDirs() android.Paths {
return j.exportAidlIncludeDirs return j.exportAidlIncludeDirs
} }
@@ -1625,6 +1695,14 @@ func (j *Import) ImplementationJars() android.Paths {
return android.Paths{j.combinedClasspathFile} return android.Paths{j.combinedClasspathFile}
} }
func (j *Import) ResourceJars() android.Paths {
return nil
}
func (j *Import) ImplementationAndResourcesJars() android.Paths {
return android.Paths{j.combinedClasspathFile}
}
func (j *Import) AidlIncludeDirs() android.Paths { func (j *Import) AidlIncludeDirs() android.Paths {
return nil return nil
} }

View File

@@ -719,7 +719,7 @@ func TestResources(t *testing.T) {
} }
`+test.extra) `+test.extra)
foo := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar") foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
if !inList(fooRes.Output.String(), foo.Inputs.Strings()) { if !inList(fooRes.Output.String(), foo.Inputs.Strings()) {