Merge "Add compile_dex for java_import" into mainline-prod
This commit is contained in:
commit
9a611122c8
76
java/java.go
76
java/java.go
|
@ -636,11 +636,8 @@ func (j *Module) AvailableFor(what string) bool {
|
||||||
return j.ApexModuleBase.AvailableFor(what)
|
return j.ApexModuleBase.AvailableFor(what)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
func sdkDeps(ctx android.BottomUpMutatorContext, sdkContext sdkContext, d dexer) {
|
||||||
if ctx.Device() {
|
sdkDep := decodeSdkDep(ctx, sdkContext)
|
||||||
j.linter.deps(ctx)
|
|
||||||
|
|
||||||
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
|
||||||
if sdkDep.useDefaultLibs {
|
if sdkDep.useDefaultLibs {
|
||||||
ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
|
||||||
ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
|
ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
|
||||||
|
@ -650,7 +647,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
||||||
} else if sdkDep.useModule {
|
} else if sdkDep.useModule {
|
||||||
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
|
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
|
||||||
ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
|
ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
|
||||||
if j.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
|
if d.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
|
||||||
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
|
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
|
||||||
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
|
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
|
||||||
}
|
}
|
||||||
|
@ -658,6 +655,13 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
||||||
if sdkDep.systemModules != "" {
|
if sdkDep.systemModules != "" {
|
||||||
ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
|
ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
||||||
|
if ctx.Device() {
|
||||||
|
j.linter.deps(ctx)
|
||||||
|
|
||||||
|
sdkDeps(ctx, sdkContext(j), j.dexer)
|
||||||
|
|
||||||
if ctx.ModuleName() == "android_stubs_current" ||
|
if ctx.ModuleName() == "android_stubs_current" ||
|
||||||
ctx.ModuleName() == "android_system_stubs_current" ||
|
ctx.ModuleName() == "android_system_stubs_current" ||
|
||||||
|
@ -2139,6 +2143,7 @@ type JavaTestImport struct {
|
||||||
prebuiltTestProperties prebuiltTestProperties
|
prebuiltTestProperties prebuiltTestProperties
|
||||||
|
|
||||||
testConfig android.Path
|
testConfig android.Path
|
||||||
|
dexJarFile android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
@ -2437,8 +2442,14 @@ type Import struct {
|
||||||
// Functionality common to Module and Import.
|
// Functionality common to Module and Import.
|
||||||
embeddableInModuleAndImport
|
embeddableInModuleAndImport
|
||||||
|
|
||||||
|
hiddenAPI
|
||||||
|
dexer
|
||||||
|
|
||||||
properties ImportProperties
|
properties ImportProperties
|
||||||
|
|
||||||
|
// output file containing classes.dex and resources
|
||||||
|
dexJarFile android.Path
|
||||||
|
|
||||||
combinedClasspathFile android.Path
|
combinedClasspathFile android.Path
|
||||||
exportedSdkLibs []string
|
exportedSdkLibs []string
|
||||||
}
|
}
|
||||||
|
@ -2451,10 +2462,18 @@ func (j *Import) makeSdkVersion() string {
|
||||||
return j.sdkVersion().raw
|
return j.sdkVersion().raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Import) systemModules() string {
|
||||||
|
return "none"
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Import) minSdkVersion() sdkSpec {
|
func (j *Import) minSdkVersion() sdkSpec {
|
||||||
return j.sdkVersion()
|
return j.sdkVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *Import) targetSdkVersion() sdkSpec {
|
||||||
|
return j.sdkVersion()
|
||||||
|
}
|
||||||
|
|
||||||
func (j *Import) MinSdkVersion() string {
|
func (j *Import) MinSdkVersion() string {
|
||||||
return j.minSdkVersion().version.String()
|
return j.minSdkVersion().version.String()
|
||||||
}
|
}
|
||||||
|
@ -2481,6 +2500,10 @@ func (a *Import) JacocoReportClassesFile() android.Path {
|
||||||
|
|
||||||
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
|
||||||
|
|
||||||
|
if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
|
||||||
|
sdkDeps(ctx, sdkContext(j), j.dexer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
|
@ -2503,6 +2526,8 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
// added to the Android manifest.
|
// added to the Android manifest.
|
||||||
j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...)
|
j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...)
|
||||||
|
|
||||||
|
var flags javaBuilderFlags
|
||||||
|
|
||||||
ctx.VisitDirectDeps(func(module android.Module) {
|
ctx.VisitDirectDeps(func(module android.Module) {
|
||||||
otherName := ctx.OtherModuleName(module)
|
otherName := ctx.OtherModuleName(module)
|
||||||
tag := ctx.OtherModuleDependencyTag(module)
|
tag := ctx.OtherModuleDependencyTag(module)
|
||||||
|
@ -2511,12 +2536,16 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
case Dependency:
|
case Dependency:
|
||||||
switch tag {
|
switch tag {
|
||||||
case libTag, staticLibTag:
|
case libTag, staticLibTag:
|
||||||
|
flags.classpath = append(flags.classpath, dep.HeaderJars()...)
|
||||||
// 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 bootClasspathTag:
|
||||||
|
flags.bootClasspath = append(flags.bootClasspath, dep.HeaderJars()...)
|
||||||
}
|
}
|
||||||
case SdkLibraryDependency:
|
case SdkLibraryDependency:
|
||||||
switch tag {
|
switch tag {
|
||||||
case libTag:
|
case libTag:
|
||||||
|
flags.classpath = append(flags.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
|
||||||
// names of sdk libs that are directly depended are exported
|
// names of sdk libs that are directly depended are exported
|
||||||
j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
|
j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
|
||||||
}
|
}
|
||||||
|
@ -2528,6 +2557,32 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
|
||||||
jarName, outputFile)
|
jarName, outputFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this is a component library (impl, stubs, etc.) for a java_sdk_library then
|
||||||
|
// add the name of that java_sdk_library to the exported sdk libs to make sure
|
||||||
|
// that, if necessary, a <uses-library> element for that java_sdk_library is
|
||||||
|
// added to the Android manifest.
|
||||||
|
j.exportedSdkLibs = append(j.exportedSdkLibs, j.OptionalImplicitSdkLibrary()...)
|
||||||
|
|
||||||
|
if ctx.Device() && Bool(j.dexProperties.Compile_dex) {
|
||||||
|
sdkDep := decodeSdkDep(ctx, sdkContext(j))
|
||||||
|
if sdkDep.invalidVersion {
|
||||||
|
ctx.AddMissingDependencies(sdkDep.bootclasspath)
|
||||||
|
ctx.AddMissingDependencies(sdkDep.java9Classpath)
|
||||||
|
} else if sdkDep.useFiles {
|
||||||
|
// sdkDep.jar is actually equivalent to turbine header.jar.
|
||||||
|
flags.classpath = append(flags.classpath, sdkDep.jars...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dex compilation
|
||||||
|
var dexOutputFile android.ModuleOutPath
|
||||||
|
dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
|
||||||
|
if ctx.Failed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
j.dexJarFile = dexOutputFile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Dependency = (*Import)(nil)
|
var _ Dependency = (*Import)(nil)
|
||||||
|
@ -2558,7 +2613,7 @@ func (j *Import) ImplementationAndResourcesJars() android.Paths {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) DexJar() android.Path {
|
func (j *Import) DexJar() android.Path {
|
||||||
return nil
|
return j.dexJarFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) AidlIncludeDirs() android.Paths {
|
func (j *Import) AidlIncludeDirs() android.Paths {
|
||||||
|
@ -2617,10 +2672,15 @@ var _ android.PrebuiltInterface = (*Import)(nil)
|
||||||
func ImportFactory() android.Module {
|
func ImportFactory() android.Module {
|
||||||
module := &Import{}
|
module := &Import{}
|
||||||
|
|
||||||
module.AddProperties(&module.properties)
|
module.AddProperties(
|
||||||
|
&module.properties,
|
||||||
|
&module.dexer.dexProperties,
|
||||||
|
)
|
||||||
|
|
||||||
module.initModuleAndImport(&module.ModuleBase)
|
module.initModuleAndImport(&module.ModuleBase)
|
||||||
|
|
||||||
|
module.dexProperties.Optimize.EnabledByDefault = false
|
||||||
|
|
||||||
android.InitPrebuiltModule(module, &module.properties.Jars)
|
android.InitPrebuiltModule(module, &module.properties.Jars)
|
||||||
android.InitApexModule(module)
|
android.InitApexModule(module)
|
||||||
android.InitSdkAwareModule(module)
|
android.InitSdkAwareModule(module)
|
||||||
|
|
|
@ -486,6 +486,8 @@ func TestPrebuilts(t *testing.T) {
|
||||||
java_import {
|
java_import {
|
||||||
name: "baz",
|
name: "baz",
|
||||||
jars: ["b.jar"],
|
jars: ["b.jar"],
|
||||||
|
sdk_version: "current",
|
||||||
|
compile_dex: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
dex_import {
|
dex_import {
|
||||||
|
@ -516,8 +518,10 @@ func TestPrebuilts(t *testing.T) {
|
||||||
fooModule := ctx.ModuleForTests("foo", "android_common")
|
fooModule := ctx.ModuleForTests("foo", "android_common")
|
||||||
javac := fooModule.Rule("javac")
|
javac := fooModule.Rule("javac")
|
||||||
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
|
||||||
barJar := ctx.ModuleForTests("bar", "android_common").Rule("combineJar").Output
|
barModule := ctx.ModuleForTests("bar", "android_common")
|
||||||
bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output
|
barJar := barModule.Rule("combineJar").Output
|
||||||
|
bazModule := ctx.ModuleForTests("baz", "android_common")
|
||||||
|
bazJar := bazModule.Rule("combineJar").Output
|
||||||
sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output
|
sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output
|
||||||
|
|
||||||
fooLibrary := fooModule.Module().(*Library)
|
fooLibrary := fooModule.Module().(*Library)
|
||||||
|
@ -532,6 +536,11 @@ func TestPrebuilts(t *testing.T) {
|
||||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
barDexJar := barModule.Module().(*Import).DexJar()
|
||||||
|
if barDexJar != nil {
|
||||||
|
t.Errorf("bar dex jar build path expected to be nil, got %q", barDexJar)
|
||||||
|
}
|
||||||
|
|
||||||
if !strings.Contains(javac.Args["classpath"], sdklibStubsJar.String()) {
|
if !strings.Contains(javac.Args["classpath"], sdklibStubsJar.String()) {
|
||||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], sdklibStubsJar.String())
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], sdklibStubsJar.String())
|
||||||
}
|
}
|
||||||
|
@ -540,6 +549,12 @@ func TestPrebuilts(t *testing.T) {
|
||||||
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String())
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bazDexJar := bazModule.Module().(*Import).DexJar().String()
|
||||||
|
expectedDexJar := buildDir + "/.intermediates/baz/android_common/dex/baz.jar"
|
||||||
|
if bazDexJar != expectedDexJar {
|
||||||
|
t.Errorf("baz dex jar build path expected %q, got %q", expectedDexJar, bazDexJar)
|
||||||
|
}
|
||||||
|
|
||||||
ctx.ModuleForTests("qux", "android_common").Rule("Cp")
|
ctx.ModuleForTests("qux", "android_common").Rule("Cp")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue