Merge changes I94f66e3e,I233a4fe1,Idbb37485
* changes:
Group all the preparations needed for testing dexpreopt
Separate methods used for fixture based and legacy tests
Use more inclusive language in dexpreopt/testing.go
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index e94b20c..17499ee 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -15,6 +15,7 @@
package java
import (
+ "fmt"
"path/filepath"
"sort"
"strings"
@@ -449,46 +450,61 @@
// be needed there too.
//
// TODO(b/177892522): Avoid having to perform this type of check or if necessary dedup it.
-func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, module android.Module) (int, android.Path) {
+func getBootJar(ctx android.SingletonContext, bootjars android.ConfiguredJarList,
+ module android.Module, fromWhere string) (int, android.Path, *android.ApexInfo) {
+
name := ctx.ModuleName(module)
// Strip a prebuilt_ prefix so that this can access the dex jar from a prebuilt module.
name = android.RemoveOptionalPrebuiltPrefix(name)
// Ignore any module that is not listed in the boot image configuration.
- index := image.modules.IndexOfJar(name)
+ index := bootjars.IndexOfJar(name)
if index == -1 {
- return -1, nil
+ return -1, nil, nil
}
// It is an error if a module configured in the boot image does not support accessing the dex jar.
// This is safe because every module that has the same name has to have the same module type.
jar, hasJar := module.(interface{ DexJarBuildPath() android.Path })
if !hasJar {
- ctx.Errorf("module %q configured in boot image %q does not support accessing dex jar", module, image.name)
- return -1, nil
+ ctx.Errorf("module %q %sdoes not support accessing dex jar", module, fromWhere)
+ return -1, nil, nil
}
// It is also an error if the module is not an ApexModule.
if _, ok := module.(android.ApexModule); !ok {
- ctx.Errorf("module %q configured in boot image %q does not support being added to an apex", module, image.name)
- return -1, nil
+ ctx.Errorf("module %q %sdoes not support being added to an apex", module, fromWhere)
+ return -1, nil, nil
}
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
// Now match the apex part of the boot image configuration.
- requiredApex := image.modules.Apex(index)
+ requiredApex := bootjars.Apex(index)
if requiredApex == "platform" {
if len(apexInfo.InApexes) != 0 {
// A platform variant is required but this is for an apex so ignore it.
- return -1, nil
+ return -1, nil, nil
}
} else if !apexInfo.InApexByBaseName(requiredApex) {
// An apex variant for a specific apex is required but this is the wrong apex.
+ return -1, nil, nil
+ }
+
+ return index, jar.DexJarBuildPath(), &apexInfo
+}
+
+// Inspect this module to see if it contains a bootclasspath dex jar from a given boot image.
+func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, module android.Module) (int, android.Path) {
+ fromImage := fmt.Sprintf("configured in boot image %q ", image.name)
+ index, jarPath, apexInfo := getBootJar(ctx, image.modules, module, fromImage)
+ if index == -1 {
return -1, nil
}
+ name := ctx.ModuleName(module)
+
// Check that this module satisfies any boot image specific constraints.
fromUpdatableApex := apexInfo.Updatable
@@ -525,39 +541,40 @@
panic("unknown boot image: " + image.name)
}
- return index, jar.DexJarBuildPath()
+ return index, jarPath
}
-// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
-func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
- // Collect dex jar paths for the boot image modules.
+// Generate commands that will copy boot jars to predefined paths in the global config.
+func findAndCopyBootJars(ctx android.SingletonContext, bootjars android.ConfiguredJarList,
+ jarPathsPredefined android.WritablePaths,
+ getBootJar func(module android.Module) (int, android.Path)) []string {
+
// This logic is tested in the apex package to avoid import cycle apex <-> java.
- bootDexJars := make(android.Paths, image.modules.Len())
+ jarPaths := make(android.Paths, bootjars.Len())
ctx.VisitAllModules(func(module android.Module) {
if !isActiveModule(module) {
return
}
-
- if i, j := getBootImageJar(ctx, image, module); i != -1 {
- if existing := bootDexJars[i]; existing != nil {
- ctx.Errorf("Multiple dex jars found for %s:%s - %s and %s",
- image.modules.Apex(i), image.modules.Jar(i), existing, j)
+ if i, j := getBootJar(module); i != -1 {
+ if existing := jarPaths[i]; existing != nil {
+ ctx.Errorf("Multiple dex jars found for %s:%s - %q and %q",
+ bootjars.Apex(i), bootjars.Jar(i), existing, j)
return
}
-
- bootDexJars[i] = j
+ jarPaths[i] = j
}
})
var missingDeps []string
// Ensure all modules were converted to paths
- for i := range bootDexJars {
- if bootDexJars[i] == nil {
- m := image.modules.Jar(i)
+ for i := range jarPaths {
+ if jarPaths[i] == nil {
+ m := bootjars.Jar(i)
if ctx.Config().AllowMissingDependencies() {
missingDeps = append(missingDeps, m)
- bootDexJars[i] = android.PathForOutput(ctx, "missing/module", m, "from/apex", image.modules.Apex(i))
+ jarPaths[i] = android.PathForOutput(ctx, "missing/module", m, "from/apex",
+ bootjars.Apex(i))
} else {
ctx.Errorf("failed to find a dex jar path for module '%s'"+
", note that some jars may be filtered out by module constraints", m)
@@ -569,14 +586,24 @@
// time, before the boot images are built (these paths are used in dexpreopt rule generation for
// Java libraries and apps). Generate rules that copy bootclasspath DEX jars to the predefined
// paths.
- for i := range bootDexJars {
+ for i := range jarPaths {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
- Input: bootDexJars[i],
- Output: image.dexPaths[i],
+ Input: jarPaths[i],
+ Output: jarPathsPredefined[i],
})
}
+ return missingDeps
+}
+
+// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
+func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
+ getBootJarFunc := func(module android.Module) (int, android.Path) {
+ return getBootImageJar(ctx, image, module)
+ }
+ missingDeps := findAndCopyBootJars(ctx, image.modules, image.dexPaths, getBootJarFunc)
+
profile := bootImageProfileRule(ctx, image, missingDeps)
bootFrameworkProfileRule(ctx, image, missingDeps)
updatableBcpPackagesRule(ctx, image, missingDeps)
diff --git a/rust/binary.go b/rust/binary.go
index df48916..dfe8744 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -87,7 +87,7 @@
deps = binary.baseCompiler.compilerDeps(ctx, deps)
if ctx.toolchain().Bionic() {
- deps = bionicDeps(deps, Bool(binary.Properties.Static_executable))
+ deps = bionicDeps(ctx, deps, Bool(binary.Properties.Static_executable))
if Bool(binary.Properties.Static_executable) {
deps.CrtBegin = "crtbegin_static"
} else {
diff --git a/rust/bindgen.go b/rust/bindgen.go
index db69e23..bcc26b8 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -260,7 +260,7 @@
func (b *bindgenDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
deps = b.BaseSourceProvider.SourceProviderDeps(ctx, deps)
if ctx.toolchain().Bionic() {
- deps = bionicDeps(deps, false)
+ deps = bionicDeps(ctx, deps, false)
}
deps.SharedLibs = append(deps.SharedLibs, b.ClangProperties.Shared_libs...)
diff --git a/rust/compiler.go b/rust/compiler.go
index 98ad7ad..200af90 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -281,7 +281,7 @@
return deps
}
-func bionicDeps(deps Deps, static bool) Deps {
+func bionicDeps(ctx DepsContext, deps Deps, static bool) Deps {
bionicLibs := []string{}
bionicLibs = append(bionicLibs, "liblog")
bionicLibs = append(bionicLibs, "libc")
@@ -294,9 +294,9 @@
deps.SharedLibs = append(deps.SharedLibs, bionicLibs...)
}
- //TODO(b/141331117) libstd requires libgcc on Android
- deps.StaticLibs = append(deps.StaticLibs, "libgcc")
-
+ if libRuntimeBuiltins := config.BuiltinsRuntimeLibrary(ctx.toolchain()); libRuntimeBuiltins != "" {
+ deps.StaticLibs = append(deps.StaticLibs, libRuntimeBuiltins)
+ }
return deps
}
diff --git a/rust/config/global.go b/rust/config/global.go
index 12f4972..9208ddb 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -53,6 +53,7 @@
deviceGlobalRustFlags = []string{
"-C panic=abort",
+ "-Z link-native-libraries=no",
}
deviceGlobalLinkFlags = []string{
@@ -62,7 +63,7 @@
// Override cc's --no-undefined-version to allow rustc's generated alloc functions
"-Wl,--undefined-version",
- "-Bdynamic",
+ "-Wl,-Bdynamic",
"-nostdlib",
"-Wl,--pack-dyn-relocs=android+relr",
"-Wl,--use-android-relr-tags",
diff --git a/rust/config/toolchain.go b/rust/config/toolchain.go
index 9525c38..a769f12 100644
--- a/rust/config/toolchain.go
+++ b/rust/config/toolchain.go
@@ -112,6 +112,10 @@
return ""
}
+func BuiltinsRuntimeLibrary(t Toolchain) string {
+ return LibclangRuntimeLibrary(t, "builtins")
+}
+
func LibFuzzerRuntimeLibrary(t Toolchain) string {
return LibclangRuntimeLibrary(t, "fuzzer")
}
diff --git a/rust/library.go b/rust/library.go
index 7ff13ec..71fe1f5 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -404,7 +404,7 @@
deps = library.baseCompiler.compilerDeps(ctx, deps)
if ctx.toolchain().Bionic() && (library.dylib() || library.shared()) {
- deps = bionicDeps(deps, false)
+ deps = bionicDeps(ctx, deps, false)
deps.CrtBegin = "crtbegin_so"
deps.CrtEnd = "crtend_so"
}