Merge "Export SOONG_CC_API_XML to Make outside androidmk"
diff --git a/android/arch.go b/android/arch.go
index 6add1b1..54242e5 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -1999,38 +1999,79 @@
// Create a new instance of the requested property set
value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
- // Merge all the structs together
- for _, propertyStruct := range propertyStructs {
- mergePropertyStruct(ctx, value, propertyStruct)
- }
-
- archToProp[arch.Name] = value
+ archToProp[arch.Name] = mergeStructs(ctx, propertyStructs, value)
}
axisToProps[bazel.ArchConfigurationAxis] = archToProp
osToProp := ArchVariantProperties{}
archOsToProp := ArchVariantProperties{}
+
+ var linuxStructs, bionicStructs []reflect.Value
+ var ok bool
+
+ linuxStructs, ok = getTargetStructs(ctx, archProperties, "Linux")
+ if !ok {
+ linuxStructs = make([]reflect.Value, 0)
+ }
+ bionicStructs, ok = getTargetStructs(ctx, archProperties, "Bionic")
+ if !ok {
+ bionicStructs = make([]reflect.Value, 0)
+ }
+
// For android, linux, ...
for _, os := range osTypeList {
if os == CommonOS {
// It looks like this OS value is not used in Blueprint files
continue
}
- osToProp[os.Name] = getTargetStruct(ctx, propertySet, archProperties, os.Field)
+ osStructs := make([]reflect.Value, 0)
+ osSpecificStructs, ok := getTargetStructs(ctx, archProperties, os.Field)
+ if ok {
+ osStructs = append(osStructs, osSpecificStructs...)
+ }
+ if os.Linux() {
+ osStructs = append(osStructs, linuxStructs...)
+ }
+ if os.Bionic() {
+ osStructs = append(osStructs, bionicStructs...)
+ }
+ osToProp[os.Name] = mergeStructs(ctx, osStructs, propertySet)
+
// For arm, x86, ...
for _, arch := range osArchTypeMap[os] {
+ osArchStructs := make([]reflect.Value, 0)
+
targetField := GetCompoundTargetField(os, arch)
targetName := fmt.Sprintf("%s_%s", os.Name, arch.Name)
- archOsToProp[targetName] = getTargetStruct(ctx, propertySet, archProperties, targetField)
+ targetStructs, ok := getTargetStructs(ctx, archProperties, targetField)
+ if ok {
+ osArchStructs = append(osArchStructs, targetStructs...)
+ }
+
+ // Auto-combine with Linux_ and Bionic_ targets. This potentially results in
+ // repetition and select() bloat, but use of Linux_* and Bionic_* targets is rare.
+ // TODO(b/201423152): Look into cleanup.
+ if os.Linux() {
+ targetField := "Linux_" + arch.Name
+ targetStructs, ok := getTargetStructs(ctx, archProperties, targetField)
+ if ok {
+ osArchStructs = append(osArchStructs, targetStructs...)
+ }
+ }
+ if os.Bionic() {
+ targetField := "Bionic_" + arch.Name
+ targetStructs, ok := getTargetStructs(ctx, archProperties, targetField)
+ if ok {
+ osArchStructs = append(osArchStructs, targetStructs...)
+ }
+ }
+
+ archOsToProp[targetName] = mergeStructs(ctx, osArchStructs, propertySet)
}
}
+
axisToProps[bazel.OsConfigurationAxis] = osToProp
axisToProps[bazel.OsArchConfigurationAxis] = archOsToProp
-
- axisToProps[bazel.BionicConfigurationAxis] = map[string]interface{}{
- "bionic": getTargetStruct(ctx, propertySet, archProperties, "Bionic"),
- }
-
return axisToProps
}
@@ -2048,7 +2089,7 @@
// }
// }
// This would return a BaseCompilerProperties with BaseCompilerProperties.Srcs = ["foo.c"]
-func getTargetStruct(ctx ArchVariantContext, propertySet interface{}, archProperties []interface{}, targetName string) interface{} {
+func getTargetStructs(ctx ArchVariantContext, archProperties []interface{}, targetName string) ([]reflect.Value, bool) {
propertyStructs := make([]reflect.Value, 0)
for _, archProperty := range archProperties {
archPropValues := reflect.ValueOf(archProperty).Elem()
@@ -2056,9 +2097,15 @@
targetStruct, ok := getChildPropertyStruct(ctx, targetProp, targetName, targetName)
if ok {
propertyStructs = append(propertyStructs, targetStruct)
+ } else {
+ return propertyStructs, false
}
}
+ return propertyStructs, true
+}
+
+func mergeStructs(ctx ArchVariantContext, propertyStructs []reflect.Value, propertySet interface{}) interface{} {
// Create a new instance of the requested property set
value := reflect.New(reflect.ValueOf(propertySet).Elem().Type()).Interface()
diff --git a/android/bazel.go b/android/bazel.go
index 86b4e14..28fdcbb 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -175,27 +175,45 @@
// Configure modules in these directories to enable bp2build_available: true or false by default.
bp2buildDefaultConfig = Bp2BuildConfig{
- "bionic": Bp2BuildDefaultTrueRecursively,
- "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
- "development/sdk": Bp2BuildDefaultTrueRecursively,
- "external/gwp_asan": Bp2BuildDefaultTrueRecursively,
- "external/brotli": Bp2BuildDefaultTrue,
- "system/core/libcutils": Bp2BuildDefaultTrueRecursively,
- "system/core/libprocessgroup": Bp2BuildDefaultTrue,
+ "bionic": Bp2BuildDefaultTrueRecursively,
+ "build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
+ "development/sdk": Bp2BuildDefaultTrueRecursively,
+ "external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively,
+ "external/boringssl": Bp2BuildDefaultTrueRecursively,
+ "external/brotli": Bp2BuildDefaultTrue,
+ "external/fmtlib": Bp2BuildDefaultTrueRecursively,
+ "external/googletest/googletest": Bp2BuildDefaultTrueRecursively,
+ "external/gwp_asan": Bp2BuildDefaultTrueRecursively,
+ "external/jemalloc_new": Bp2BuildDefaultTrueRecursively,
+ "external/libcap": Bp2BuildDefaultTrueRecursively,
+ "external/libcxx": Bp2BuildDefaultTrueRecursively,
+ "external/libcxxabi": Bp2BuildDefaultTrueRecursively,
+ "external/lz4/lib": Bp2BuildDefaultTrue,
+ "external/protobuf": Bp2BuildDefaultTrueRecursively,
+ "external/python/six": Bp2BuildDefaultTrueRecursively,
+ "external/scudo": Bp2BuildDefaultTrueRecursively,
+ "external/zlib": Bp2BuildDefaultTrueRecursively,
+ "frameworks/native/libs/adbd_auth": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb": Bp2BuildDefaultTrue,
+ "packages/modules/adb/crypto": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/libs": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/pairing_auth": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/pairing_connection": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/proto": Bp2BuildDefaultTrueRecursively,
+ "packages/modules/adb/tls": Bp2BuildDefaultTrueRecursively,
+ "prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
+ "system/core/diagnose_usb": Bp2BuildDefaultTrueRecursively,
+ "system/core/libasyncio": Bp2BuildDefaultTrue,
+ "system/core/libcrypto_utils": Bp2BuildDefaultTrueRecursively,
+ "system/core/libcutils": Bp2BuildDefaultTrueRecursively,
+ "system/core/libprocessgroup": Bp2BuildDefaultTrue,
"system/core/property_service/libpropertyinfoparser": Bp2BuildDefaultTrueRecursively,
- "system/libbase": Bp2BuildDefaultTrueRecursively,
- "system/logging/liblog": Bp2BuildDefaultTrueRecursively,
- "system/sepolicy/apex": Bp2BuildDefaultTrueRecursively,
- "system/timezone/apex": Bp2BuildDefaultTrueRecursively,
- "system/timezone/output_data": Bp2BuildDefaultTrueRecursively,
- "external/arm-optimized-routines": Bp2BuildDefaultTrueRecursively,
- "external/fmtlib": Bp2BuildDefaultTrueRecursively,
- "external/jemalloc_new": Bp2BuildDefaultTrueRecursively,
- "external/libcxx": Bp2BuildDefaultTrueRecursively,
- "external/libcxxabi": Bp2BuildDefaultTrueRecursively,
- "external/libcap": Bp2BuildDefaultTrueRecursively,
- "external/scudo": Bp2BuildDefaultTrueRecursively,
- "prebuilts/clang/host/linux-x86": Bp2BuildDefaultTrueRecursively,
+ "system/libbase": Bp2BuildDefaultTrueRecursively,
+ "system/libziparchive": Bp2BuildDefaultTrueRecursively,
+ "system/logging/liblog": Bp2BuildDefaultTrueRecursively,
+ "system/sepolicy/apex": Bp2BuildDefaultTrueRecursively,
+ "system/timezone/apex": Bp2BuildDefaultTrueRecursively,
+ "system/timezone/output_data": Bp2BuildDefaultTrueRecursively,
}
// Per-module denylist to always opt modules out of both bp2build and mixed builds.
@@ -204,34 +222,18 @@
"libbionic_spawn_benchmark", // http://b/186824595, cc_library_static, depends on //external/google-benchmark (http://b/186822740)
// also depends on //system/logging/liblog:liblog (http://b/186822772)
- "libc_malloc_debug", // http://b/186824339, cc_library_static, depends on //system/libbase:libbase (http://b/186823646)
- "libc_malloc_debug_backtrace", // http://b/186824112, cc_library_static, depends on //external/libcxxabi:libc++demangle (http://b/186823773)
+ "libc_malloc_debug", // depends on libunwindstack, which depends on unsupported module art_cc_library_statics
- "libcutils", // http://b/186827426, cc_library, depends on //system/core/libprocessgroup:libprocessgroup_headers (http://b/186826841)
- "libcutils_sockets", // http://b/186826853, cc_library, depends on //system/libbase:libbase (http://b/186826479)
-
- "liblinker_debuggerd_stub", // http://b/186824327, cc_library_static, depends on //external/zlib:libz (http://b/186823782)
- // also depends on //system/libziparchive:libziparchive (http://b/186823656)
- // also depends on //system/logging/liblog:liblog (http://b/186822772)
- "liblinker_main", // http://b/186825989, cc_library_static, depends on //external/zlib:libz (http://b/186823782)
- // also depends on //system/libziparchive:libziparchive (http://b/186823656)
- // also depends on//system/logging/liblog:liblog (http://b/186822772)
- "liblinker_malloc", // http://b/186826466, cc_library_static, depends on //external/zlib:libz (http://b/186823782)
- // also depends on //system/libziparchive:libziparchive (http://b/186823656)
- // also depends on //system/logging/liblog:liblog (http://b/186822772)
- "libc_ndk", // http://b/187013218, cc_library_static, depends on //bionic/libm:libm (http://b/183064661)
"libc_malloc_hooks", // http://b/187016307, cc_library, ld.lld: error: undefined symbol: __malloc_hook
- // http://b/186823769: Needs C++ STL support, includes from unconverted standard libraries in //external/libcxx
- // c++_static
- "libbase_ndk", // http://b/186826477, cc_library, no such target '//build/bazel/platforms/os:darwin' when --platforms //build/bazel/platforms:android_x86 is added
- // libcxx
- "libBionicBenchmarksUtils", // cc_library_static, fatal error: 'map' file not found, from libcxx
- "libbase", // Depends on fmtlib via static_libs and also whole_static_libs, which results in bazel errors.
+ "libbase_ndk", // http://b/186826477, fails to link libctscamera2_jni for device (required for CtsCameraTestCases)
- "libfdtrack", // depends on liblzma and libbase
+ "libprotobuf-python", // contains .proto sources
+ "libprotobuf-internal-protos", // we don't handle path property for fileegroups
+ "libprotobuf-internal-python-srcs", // we don't handle path property for fileegroups
- "libseccomp_policy", // depends on libbase
+ "libseccomp_policy", // b/201094425: depends on func_to_syscall_nrs, which depends on py_binary, which is unsupported in mixed builds.
+ "libfdtrack", // depends on libunwindstack, which depends on unsupported module art_cc_library_statics
"gwp_asan_crash_handler", // cc_library, ld.lld: error: undefined symbol: memset
@@ -253,6 +255,23 @@
// APEX support
"com.android.runtime", // http://b/194746715, apex, depends on 'libc_malloc_debug' and 'libc_malloc_hooks'
+
+ "libadb_crypto", // Depends on libadb_protos
+ "libadb_crypto_static", // Depends on libadb_protos_static
+ "libadb_pairing_connection", // Depends on libadb_protos
+ "libadb_pairing_connection_static", // Depends on libadb_protos_static
+ "libadb_pairing_server", // Depends on libadb_protos
+ "libadb_pairing_server_static", // Depends on libadb_protos_static
+ "libadbd", // Depends on libadbd_core
+ "libadbd_core", // Depends on libadb_protos
+ "libadbd_services", // Depends on libadb_protos
+
+ "libadb_protos_static", // b/200601772: Requires cc_library proto support
+ "libadb_protos", // b/200601772: Requires cc_library proto support
+ "libapp_processes_protos_lite", // b/200601772: Requires cc_library proto support
+
+ "libgtest_ndk_c++", // b/201816222: Requires sdk_version support.
+ "libgtest_main_ndk_c++", // b/201816222: Requires sdk_version support.
}
// Per-module denylist of cc_library modules to only generate the static
@@ -269,6 +288,7 @@
"libseccomp_policy_app_zygote_sources", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module.
"libseccomp_policy_app_sources", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module.
"libseccomp_policy_system_sources", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module.
+
}
// Used for quicker lookups
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 2241255..6648a2f 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -815,7 +815,7 @@
if len(buildStatement.OutputPaths) > 0 {
cmd.Text("rm -f")
for _, outputPath := range buildStatement.OutputPaths {
- cmd.Text(PathForBazelOut(ctx, outputPath).String())
+ cmd.Text(outputPath)
}
cmd.Text("&&")
}
diff --git a/android/bazel_paths.go b/android/bazel_paths.go
index b5746f7..9957369 100644
--- a/android/bazel_paths.go
+++ b/android/bazel_paths.go
@@ -393,9 +393,19 @@
OutputPath
}
+// ensure BazelOutPath implements Path
var _ Path = BazelOutPath{}
+
+// ensure BazelOutPath implements genPathProvider
+var _ genPathProvider = BazelOutPath{}
+
+// ensure BazelOutPath implements objPathProvider
var _ objPathProvider = BazelOutPath{}
+func (p BazelOutPath) genPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleGenPath {
+ return PathForModuleGen(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
+}
+
func (p BazelOutPath) objPathWithExt(ctx ModuleOutPathContext, subdir, ext string) ModuleObjPath {
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
}
diff --git a/android/config.go b/android/config.go
index e7ebdef..c8d7cfd 100644
--- a/android/config.go
+++ b/android/config.go
@@ -854,11 +854,6 @@
return Bool(c.productVariables.Always_use_prebuilt_sdks)
}
-// Returns true if the boot jars check should be skipped.
-func (c *config) SkipBootJarsCheck() bool {
- return Bool(c.productVariables.Skip_boot_jars_check)
-}
-
func (c *config) MinimizeJavaDebugInfo() bool {
return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng)
}
diff --git a/android/rule_builder.go b/android/rule_builder.go
index 6605869..c9a9ddd 100644
--- a/android/rule_builder.go
+++ b/android/rule_builder.go
@@ -769,16 +769,25 @@
paths Paths
}
+func checkPathNotNil(path Path) {
+ if path == nil {
+ panic("rule_builder paths cannot be nil")
+ }
+}
+
func (c *RuleBuilderCommand) addInput(path Path) string {
+ checkPathNotNil(path)
c.inputs = append(c.inputs, path)
return c.PathForInput(path)
}
func (c *RuleBuilderCommand) addImplicit(path Path) {
+ checkPathNotNil(path)
c.implicits = append(c.implicits, path)
}
func (c *RuleBuilderCommand) addOrderOnly(path Path) {
+ checkPathNotNil(path)
c.orderOnlys = append(c.orderOnlys, path)
}
@@ -1004,19 +1013,23 @@
// Tool adds the specified tool path to the command line. The path will be also added to the dependencies returned by
// RuleBuilder.Tools.
func (c *RuleBuilderCommand) Tool(path Path) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.tools = append(c.tools, path)
return c.Text(c.PathForTool(path))
}
// Tool adds the specified tool path to the dependencies returned by RuleBuilder.Tools.
func (c *RuleBuilderCommand) ImplicitTool(path Path) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.tools = append(c.tools, path)
return c
}
// Tool adds the specified tool path to the dependencies returned by RuleBuilder.Tools.
func (c *RuleBuilderCommand) ImplicitTools(paths Paths) *RuleBuilderCommand {
- c.tools = append(c.tools, paths...)
+ for _, path := range paths {
+ c.ImplicitTool(path)
+ }
return c
}
@@ -1093,6 +1106,7 @@
// Validation adds the specified input path to the validation dependencies by
// RuleBuilder.Validations without modifying the command line.
func (c *RuleBuilderCommand) Validation(path Path) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.validations = append(c.validations, path)
return c
}
@@ -1100,13 +1114,16 @@
// Validations adds the specified input paths to the validation dependencies by
// RuleBuilder.Validations without modifying the command line.
func (c *RuleBuilderCommand) Validations(paths Paths) *RuleBuilderCommand {
- c.validations = append(c.validations, paths...)
+ for _, path := range paths {
+ c.Validation(path)
+ }
return c
}
// Output adds the specified output path to the command line. The path will also be added to the outputs returned by
// RuleBuilder.Outputs.
func (c *RuleBuilderCommand) Output(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.outputs = append(c.outputs, path)
return c.Text(c.PathForOutput(path))
}
@@ -1133,6 +1150,7 @@
// line, and causes RuleBuilder.Build file to set the depfile flag for ninja. If multiple depfiles are added to
// commands in a single RuleBuilder then RuleBuilder.Build will add an extra command to merge the depfiles together.
func (c *RuleBuilderCommand) DepFile(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.depFiles = append(c.depFiles, path)
return c.Text(c.PathForOutput(path))
}
@@ -1155,6 +1173,7 @@
// will be a symlink instead of a regular file. Does not modify the command
// line.
func (c *RuleBuilderCommand) ImplicitSymlinkOutput(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.symlinkOutputs = append(c.symlinkOutputs, path)
return c.ImplicitOutput(path)
}
@@ -1172,6 +1191,7 @@
// SymlinkOutput declares the specified path as an output that will be a symlink
// instead of a regular file. Modifies the command line.
func (c *RuleBuilderCommand) SymlinkOutput(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.symlinkOutputs = append(c.symlinkOutputs, path)
return c.Output(path)
}
diff --git a/apex/builder.go b/apex/builder.go
index 6df40f4..c05c20c 100644
--- a/apex/builder.go
+++ b/apex/builder.go
@@ -824,10 +824,8 @@
a.outputFile = signedCompressedOutputFile
}
- // Install to $OUT/soong/{target,host}/.../apex
- if a.installable() {
- ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
- }
+ // Install to $OUT/soong/{target,host}/.../apex.
+ ctx.InstallFile(a.installDir, a.Name()+suffix, a.outputFile)
// installed-files.txt is dist'ed
a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir)
diff --git a/apex/prebuilt.go b/apex/prebuilt.go
index d59f8bf..55a9e42 100644
--- a/apex/prebuilt.go
+++ b/apex/prebuilt.go
@@ -103,6 +103,10 @@
// List of bootclasspath fragments inside this prebuilt APEX bundle and for which this APEX
// bundle will create an APEX variant.
Exported_bootclasspath_fragments []string
+
+ // List of systemserverclasspath fragments inside this prebuilt APEX bundle and for which this
+ // APEX bundle will create an APEX variant.
+ Exported_systemserverclasspath_fragments []string
}
// initPrebuiltCommon initializes the prebuiltCommon structure and performs initialization of the
@@ -174,7 +178,8 @@
tag := ctx.OtherModuleDependencyTag(child)
name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(child))
- if java.IsBootclasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
+ if java.IsBootclasspathFragmentContentDepTag(tag) ||
+ java.IsSystemServerClasspathFragmentContentDepTag(tag) || tag == exportedJavaLibTag {
// If the exported java module provides a dex jar path then add it to the list of apexFiles.
path := child.(interface {
DexJarBuildPath() java.OptionalDexJarPath
@@ -194,8 +199,9 @@
}
p.apexFilesForAndroidMk = append(p.apexFilesForAndroidMk, af)
}
- } else if tag == exportedBootclasspathFragmentTag {
- // Visit the children of the bootclasspath_fragment.
+ } else if tag == exportedBootclasspathFragmentTag ||
+ tag == exportedSystemserverclasspathFragmentTag {
+ // Visit the children of the bootclasspath_fragment and systemserver_fragment.
return true
}
@@ -311,21 +317,31 @@
}
}
+func (p *prebuiltCommon) getExportedDependencies() map[string]exportedDependencyTag {
+ dependencies := make(map[string]exportedDependencyTag)
+
+ for _, dep := range p.prebuiltCommonProperties.Exported_java_libs {
+ dependencies[dep] = exportedJavaLibTag
+ }
+
+ for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
+ dependencies[dep] = exportedBootclasspathFragmentTag
+ }
+
+ for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments {
+ dependencies[dep] = exportedSystemserverclasspathFragmentTag
+ }
+
+ return dependencies
+}
+
// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
module := ctx.Module()
- // Add dependencies onto the java modules that represent the java libraries that are provided by
- // and exported from this prebuilt apex.
- for _, exported := range p.prebuiltCommonProperties.Exported_java_libs {
- dep := android.PrebuiltNameFromSource(exported)
- ctx.AddDependency(module, exportedJavaLibTag, dep)
- }
- // Add dependencies onto the bootclasspath fragment modules that are exported from this prebuilt
- // apex.
- for _, exported := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
- dep := android.PrebuiltNameFromSource(exported)
- ctx.AddDependency(module, exportedBootclasspathFragmentTag, dep)
+ for dep, tag := range p.getExportedDependencies() {
+ prebuiltDep := android.PrebuiltNameFromSource(dep)
+ ctx.AddDependency(module, tag, prebuiltDep)
}
}
@@ -576,9 +592,9 @@
// A deapexer module is only needed when the prebuilt apex specifies one or more modules in either
// the `exported_java_libs` or `exported_bootclasspath_fragments` properties as that indicates that
// the listed modules need access to files from within the prebuilt .apex file.
-func createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string, properties *PrebuiltCommonProperties) {
+func (p *prebuiltCommon) createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string) {
// Only create the deapexer module if it is needed.
- if len(properties.Exported_java_libs)+len(properties.Exported_bootclasspath_fragments) == 0 {
+ if len(p.getExportedDependencies()) == 0 {
return
}
@@ -674,8 +690,9 @@
var _ android.RequiresFilesFromPrebuiltApexTag = exportedDependencyTag{}
var (
- exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
- exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
+ exportedJavaLibTag = exportedDependencyTag{name: "exported_java_libs"}
+ exportedBootclasspathFragmentTag = exportedDependencyTag{name: "exported_bootclasspath_fragments"}
+ exportedSystemserverclasspathFragmentTag = exportedDependencyTag{name: "exported_systemserverclasspath_fragments"}
)
var _ prebuiltApexModuleCreator = (*Prebuilt)(nil)
@@ -716,7 +733,7 @@
createApexSelectorModule(ctx, apexSelectorModuleName, &p.properties.ApexFileProperties)
apexFileSource := ":" + apexSelectorModuleName
- createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, p.prebuiltCommonProperties)
+ p.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource)
// Add a source reference to retrieve the selected apex from the selector module.
p.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
@@ -919,7 +936,7 @@
createApexExtractorModule(ctx, apexExtractorModuleName, &a.properties.ApexExtractorProperties)
apexFileSource := ":" + apexExtractorModuleName
- createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource, a.prebuiltCommonProperties)
+ a.createDeapexerModuleIfNeeded(ctx, deapexerModuleName(baseModuleName), apexFileSource)
// After passing the arch specific src properties to the creating the apex selector module
a.prebuiltCommonProperties.Selected_apex = proptools.StringPtr(apexFileSource)
diff --git a/apex/systemserver_classpath_fragment_test.go b/apex/systemserver_classpath_fragment_test.go
index a8d5931..412fa0e 100644
--- a/apex/systemserver_classpath_fragment_test.go
+++ b/apex/systemserver_classpath_fragment_test.go
@@ -138,7 +138,7 @@
dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
).
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
- `in contents must also be declared in PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS`)).
+ `in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS`)).
RunTestWithBp(t, `
apex {
name: "myapex",
@@ -181,3 +181,53 @@
}
`)
}
+
+func TestPrebuiltSystemserverclasspathFragmentContents(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForTestWithSystemserverclasspathFragment,
+ prepareForTestWithMyapex,
+ dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"),
+ ).RunTestWithBp(t, `
+ prebuilt_apex {
+ name: "myapex",
+ arch: {
+ arm64: {
+ src: "myapex-arm64.apex",
+ },
+ arm: {
+ src: "myapex-arm.apex",
+ },
+ },
+ exported_systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
+ }
+
+ java_import {
+ name: "foo",
+ jars: ["foo.jar"],
+ apex_available: [
+ "myapex",
+ ],
+ }
+
+ prebuilt_systemserverclasspath_fragment {
+ name: "mysystemserverclasspathfragment",
+ prefer: true,
+ contents: [
+ "foo",
+ ],
+ apex_available: [
+ "myapex",
+ ],
+ }
+ `)
+
+ java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex", []string{
+ `myapex.apex.selector`,
+ `prebuilt_mysystemserverclasspathfragment`,
+ })
+
+ java.CheckModuleDependencies(t, result.TestContext, "mysystemserverclasspathfragment", "android_common_myapex", []string{
+ `myapex.deapexer`,
+ `prebuilt_foo`,
+ })
+}
diff --git a/bazel/configurability.go b/bazel/configurability.go
index 7aaff9a..e9641e7 100644
--- a/bazel/configurability.go
+++ b/bazel/configurability.go
@@ -91,11 +91,6 @@
ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
}
- platformBionicMap = map[string]string{
- "bionic": "//build/bazel/platforms/os:bionic",
- ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
- }
-
platformOsArchMap = map[string]string{
osArchAndroidArm: "//build/bazel/platforms/os_arch:android_arm",
osArchAndroidArm64: "//build/bazel/platforms/os_arch:android_arm64",
@@ -122,7 +117,6 @@
arch
os
osArch
- bionic
productVariables
)
@@ -132,7 +126,6 @@
arch: "arch",
os: "os",
osArch: "arch_os",
- bionic: "bionic",
productVariables: "product_variables",
}[ct]
}
@@ -155,10 +148,6 @@
if _, ok := platformOsArchMap[config]; !ok {
panic(fmt.Errorf("Unknown os+arch: %s", config))
}
- case bionic:
- if _, ok := platformBionicMap[config]; !ok {
- panic(fmt.Errorf("Unknown for %s: %s", ct.String(), config))
- }
case productVariables:
// do nothing
default:
@@ -178,8 +167,6 @@
return platformOsMap[config]
case osArch:
return platformOsArchMap[config]
- case bionic:
- return platformBionicMap[config]
case productVariables:
if config == ConditionsDefaultConfigKey {
return ConditionsDefaultSelectKey
@@ -199,8 +186,6 @@
OsConfigurationAxis = ConfigurationAxis{configurationType: os}
// An axis for arch+os-specific configurations
OsArchConfigurationAxis = ConfigurationAxis{configurationType: osArch}
- // An axis for bionic os-specific configurations
- BionicConfigurationAxis = ConfigurationAxis{configurationType: bionic}
)
// ProductVariableConfigurationAxis returns an axis for the given product variable
diff --git a/bazel/properties.go b/bazel/properties.go
index bd8ef0d..ee32e73 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -264,7 +264,7 @@
switch axis.configurationType {
case noConfig:
la.Value = &value
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
if la.ConfigurableValues == nil {
la.ConfigurableValues = make(configurableLabels)
}
@@ -280,7 +280,7 @@
switch axis.configurationType {
case noConfig:
return *la.Value
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
return *la.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
@@ -337,7 +337,7 @@
switch axis.configurationType {
case noConfig:
ba.Value = value
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
if ba.ConfigurableValues == nil {
ba.ConfigurableValues = make(configurableBools)
}
@@ -353,7 +353,7 @@
switch axis.configurationType {
case noConfig:
return ba.Value
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
if v, ok := ba.ConfigurableValues[axis][config]; ok {
return &v
} else {
@@ -459,7 +459,7 @@
switch axis.configurationType {
case noConfig:
lla.Value = list
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
if lla.ConfigurableValues == nil {
lla.ConfigurableValues = make(configurableLabelLists)
}
@@ -475,7 +475,7 @@
switch axis.configurationType {
case noConfig:
return lla.Value
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
return lla.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
@@ -773,7 +773,7 @@
switch axis.configurationType {
case noConfig:
sla.Value = list
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
if sla.ConfigurableValues == nil {
sla.ConfigurableValues = make(configurableStringLists)
}
@@ -789,7 +789,7 @@
switch axis.configurationType {
case noConfig:
return sla.Value
- case arch, os, osArch, bionic, productVariables:
+ case arch, os, osArch, productVariables:
return sla.ConfigurableValues[axis][config]
default:
panic(fmt.Errorf("Unrecognized ConfigurationAxis %s", axis))
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 5952b15..0d65822 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -131,12 +131,13 @@
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
"//conditions:default": [],
}) + select({
- "//build/bazel/platforms/os:android": ["android.cpp"],
+ "//build/bazel/platforms/os:android": [
+ "android.cpp",
+ "bionic.cpp",
+ ],
"//build/bazel/platforms/os:darwin": ["darwin.cpp"],
"//build/bazel/platforms/os:linux": ["linux.cpp"],
- "//conditions:default": [],
- }) + select({
- "//build/bazel/platforms/os:bionic": ["bionic.cpp"],
+ "//build/bazel/platforms/os:linux_bionic": ["bionic.cpp"],
"//conditions:default": [],
}),
)`}})
@@ -1571,3 +1572,68 @@
)`},
})
}
+
+func TestCcLibraryOsSelects(t *testing.T) {
+ runCcLibraryTestCase(t, bp2buildTestCase{
+ description: "cc_library - selects for all os targets",
+ moduleTypeUnderTest: "cc_library",
+ moduleTypeUnderTestFactory: cc.LibraryFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
+ filesystem: map[string]string{},
+ blueprint: soongCcLibraryPreamble + `
+cc_library_headers { name: "some-headers" }
+cc_library {
+ name: "foo-lib",
+ srcs: ["base.cpp"],
+ target: {
+ android: {
+ srcs: ["android.cpp"],
+ },
+ linux: {
+ srcs: ["linux.cpp"],
+ },
+ linux_glibc: {
+ srcs: ["linux_glibc.cpp"],
+ },
+ darwin: {
+ srcs: ["darwin.cpp"],
+ },
+ bionic: {
+ srcs: ["bionic.cpp"],
+ },
+ linux_musl: {
+ srcs: ["linux_musl.cpp"],
+ },
+ windows: {
+ srcs: ["windows.cpp"],
+ },
+ },
+ include_build_directory: false,
+}
+`,
+ expectedBazelTargets: []string{`cc_library(
+ name = "foo-lib",
+ srcs = ["base.cpp"] + select({
+ "//build/bazel/platforms/os:android": [
+ "android.cpp",
+ "bionic.cpp",
+ "linux.cpp",
+ ],
+ "//build/bazel/platforms/os:darwin": ["darwin.cpp"],
+ "//build/bazel/platforms/os:linux": [
+ "linux.cpp",
+ "linux_glibc.cpp",
+ ],
+ "//build/bazel/platforms/os:linux_bionic": [
+ "bionic.cpp",
+ "linux.cpp",
+ ],
+ "//build/bazel/platforms/os:linux_musl": [
+ "linux.cpp",
+ "linux_musl.cpp",
+ ],
+ "//build/bazel/platforms/os:windows": ["windows.cpp"],
+ "//conditions:default": [],
+ }),
+)`}})
+}
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 91b7478..f02ce4d 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1382,7 +1382,8 @@
expectedBazelTargets: []string{`cc_library_static(
name = "target_bionic",
system_dynamic_deps = select({
- "//build/bazel/platforms/os:bionic": [":libc"],
+ "//build/bazel/platforms/os:android": [":libc"],
+ "//build/bazel/platforms/os:linux_bionic": [":libc"],
"//conditions:default": [],
}),
)`},
diff --git a/bp2build/cc_object_conversion_test.go b/bp2build/cc_object_conversion_test.go
index b0a88ae..63a0b8a 100644
--- a/bp2build/cc_object_conversion_test.go
+++ b/bp2build/cc_object_conversion_test.go
@@ -71,6 +71,7 @@
".",
],
srcs = ["a/b/c.c"],
+ system_dynamic_deps = [],
)`,
},
})
@@ -116,6 +117,7 @@
],
local_includes = ["."],
srcs = ["a/b/c.c"],
+ system_dynamic_deps = [],
)`,
}})
}
@@ -149,11 +151,13 @@
name = "bar",
copts = ["-fno-addrsig"],
srcs = ["x/y/z.c"],
+ system_dynamic_deps = [],
)`, `cc_object(
name = "foo",
copts = ["-fno-addrsig"],
deps = [":bar"],
srcs = ["a/b/c.c"],
+ system_dynamic_deps = [],
)`,
},
})
@@ -180,6 +184,7 @@
name = "foo",
copts = ["-fno-addrsig"],
srcs = ["a/b/c.c"],
+ system_dynamic_deps = [],
)`,
},
})
@@ -211,6 +216,7 @@
}),
copts = ["-fno-addrsig"],
srcs_as = ["src.S"],
+ system_dynamic_deps = [],
)`,
},
})
@@ -248,6 +254,7 @@
"//build/bazel/platforms/arch:arm": ["arch/arm/file.cpp"],
"//conditions:default": [],
}),
+ system_dynamic_deps = [],
)`,
},
})
@@ -301,30 +308,126 @@
"//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
"//conditions:default": [],
}),
+ system_dynamic_deps = [],
)`,
},
})
}
-func TestCcObjectCflagsMultiOs(t *testing.T) {
+func TestCcObjectLinkerScript(t *testing.T) {
runCcObjectTestCase(t, bp2buildTestCase{
- description: "cc_object setting cflags for multiple OSes",
+ description: "cc_object setting linker_script",
moduleTypeUnderTest: "cc_object",
moduleTypeUnderTestFactory: cc.ObjectFactory,
moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
blueprint: `cc_object {
name: "foo",
+ srcs: ["base.cpp"],
+ linker_script: "bunny.lds",
+ include_build_directory: false,
+}
+`,
+ expectedBazelTargets: []string{
+ `cc_object(
+ name = "foo",
+ copts = ["-fno-addrsig"],
+ linker_script = "bunny.lds",
+ srcs = ["base.cpp"],
+)`,
+ },
+ })
+}
+
+func TestCcObjectDepsAndLinkerScriptSelects(t *testing.T) {
+ runCcObjectTestCase(t, bp2buildTestCase{
+ description: "cc_object setting deps and linker_script across archs",
+ moduleTypeUnderTest: "cc_object",
+ moduleTypeUnderTestFactory: cc.ObjectFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
+ blueprint: `cc_object {
+ name: "foo",
+ srcs: ["base.cpp"],
+ arch: {
+ x86: {
+ objs: ["x86_obj"],
+ linker_script: "x86.lds",
+ },
+ x86_64: {
+ objs: ["x86_64_obj"],
+ linker_script: "x86_64.lds",
+ },
+ arm: {
+ objs: ["arm_obj"],
+ linker_script: "arm.lds",
+ },
+ },
+ include_build_directory: false,
+}
+
+cc_object {
+ name: "x86_obj",
system_shared_libs: [],
+ srcs: ["x86.cpp"],
+ include_build_directory: false,
+ bazel_module: { bp2build_available: false },
+}
+
+cc_object {
+ name: "x86_64_obj",
+ system_shared_libs: [],
+ srcs: ["x86_64.cpp"],
+ include_build_directory: false,
+ bazel_module: { bp2build_available: false },
+}
+
+cc_object {
+ name: "arm_obj",
+ system_shared_libs: [],
+ srcs: ["arm.cpp"],
+ include_build_directory: false,
+ bazel_module: { bp2build_available: false },
+}
+`,
+ expectedBazelTargets: []string{
+ `cc_object(
+ name = "foo",
+ copts = ["-fno-addrsig"],
+ deps = select({
+ "//build/bazel/platforms/arch:arm": [":arm_obj"],
+ "//build/bazel/platforms/arch:x86": [":x86_obj"],
+ "//build/bazel/platforms/arch:x86_64": [":x86_64_obj"],
+ "//conditions:default": [],
+ }),
+ linker_script = select({
+ "//build/bazel/platforms/arch:arm": "arm.lds",
+ "//build/bazel/platforms/arch:x86": "x86.lds",
+ "//build/bazel/platforms/arch:x86_64": "x86_64.lds",
+ "//conditions:default": None,
+ }),
+ srcs = ["base.cpp"],
+)`,
+ },
+ })
+}
+
+func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
+ runCcObjectTestCase(t, bp2buildTestCase{
+ description: "cc_object setting srcs based on linux and bionic archs",
+ moduleTypeUnderTest: "cc_object",
+ moduleTypeUnderTestFactory: cc.ObjectFactory,
+ moduleTypeUnderTestBp2BuildMutator: cc.ObjectBp2Build,
+ blueprint: `cc_object {
+ name: "foo",
srcs: ["base.cpp"],
target: {
- android: {
- cflags: ["-fPIC"],
+ linux_arm64: {
+ srcs: ["linux_arm64.cpp",]
},
- windows: {
- cflags: ["-fPIC"],
+ linux_x86: {
+ srcs: ["linux_x86.cpp",]
},
- darwin: {
- cflags: ["-Wall"],
+ bionic_arm64: {
+ srcs: ["bionic_arm64.cpp",]
},
},
include_build_directory: false,
@@ -333,13 +436,21 @@
expectedBazelTargets: []string{
`cc_object(
name = "foo",
- copts = ["-fno-addrsig"] + select({
- "//build/bazel/platforms/os:android": ["-fPIC"],
- "//build/bazel/platforms/os:darwin": ["-Wall"],
- "//build/bazel/platforms/os:windows": ["-fPIC"],
+ copts = ["-fno-addrsig"],
+ srcs = ["base.cpp"] + select({
+ "//build/bazel/platforms/os_arch:android_arm64": [
+ "bionic_arm64.cpp",
+ "linux_arm64.cpp",
+ ],
+ "//build/bazel/platforms/os_arch:android_x86": ["linux_x86.cpp"],
+ "//build/bazel/platforms/os_arch:linux_bionic_arm64": [
+ "bionic_arm64.cpp",
+ "linux_arm64.cpp",
+ ],
+ "//build/bazel/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"],
+ "//build/bazel/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"],
"//conditions:default": [],
}),
- srcs = ["base.cpp"],
)`,
},
})
diff --git a/bp2build/python_binary_conversion_test.go b/bp2build/python_binary_conversion_test.go
index 6f6fc11..5b4829e 100644
--- a/bp2build/python_binary_conversion_test.go
+++ b/bp2build/python_binary_conversion_test.go
@@ -116,3 +116,37 @@
},
})
}
+
+func TestPythonBinaryHostArchVariance(t *testing.T) {
+ runBp2BuildTestCaseSimple(t, bp2buildTestCase{
+ description: "test arch variants",
+ moduleTypeUnderTest: "python_binary_host",
+ moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
+ moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build,
+ filesystem: map[string]string{
+ "dir/arm.py": "",
+ "dir/x86.py": "",
+ },
+ blueprint: `python_binary_host {
+ name: "foo-arm",
+ arch: {
+ arm: {
+ srcs: ["arm.py"],
+ },
+ x86: {
+ srcs: ["x86.py"],
+ },
+ },
+ }`,
+ expectedBazelTargets: []string{
+ `py_binary(
+ name = "foo-arm",
+ srcs = select({
+ "//build/bazel/platforms/arch:arm": ["arm.py"],
+ "//build/bazel/platforms/arch:x86": ["x86.py"],
+ "//conditions:default": [],
+ }),
+)`,
+ },
+ })
+}
diff --git a/bp2build/python_library_conversion_test.go b/bp2build/python_library_conversion_test.go
index b6f45e5..7f983ad 100644
--- a/bp2build/python_library_conversion_test.go
+++ b/bp2build/python_library_conversion_test.go
@@ -154,3 +154,54 @@
},
})
}
+
+func TestPythonLibraryArchVariance(t *testing.T) {
+ testPythonArchVariance(t, "python_library", "py_library",
+ python.PythonLibraryFactory, python.PythonLibraryBp2Build,
+ func(ctx android.RegistrationContext) {})
+}
+
+func TestPythonLibraryHostArchVariance(t *testing.T) {
+ testPythonArchVariance(t, "python_library_host", "py_library",
+ python.PythonLibraryHostFactory, python.PythonLibraryHostBp2Build,
+ func(ctx android.RegistrationContext) {})
+}
+
+// TODO: refactor python_binary_conversion_test to use this
+func testPythonArchVariance(t *testing.T, modType, bazelTarget string,
+ factory android.ModuleFactory, mutator PythonLibBp2Build,
+ registration func(ctx android.RegistrationContext)) {
+ t.Helper()
+ runBp2BuildTestCase(t, registration, bp2buildTestCase{
+ description: fmt.Sprintf("test %s arch variants", modType),
+ moduleTypeUnderTest: modType,
+ moduleTypeUnderTestFactory: factory,
+ moduleTypeUnderTestBp2BuildMutator: mutator,
+ filesystem: map[string]string{
+ "dir/arm.py": "",
+ "dir/x86.py": "",
+ },
+ blueprint: fmt.Sprintf(`%s {
+ name: "foo",
+ arch: {
+ arm: {
+ srcs: ["arm.py"],
+ },
+ x86: {
+ srcs: ["x86.py"],
+ },
+ },
+ }`, modType),
+ expectedBazelTargets: []string{
+ fmt.Sprintf(`%s(
+ name = "foo",
+ srcs = select({
+ "//build/bazel/platforms/arch:arm": ["arm.py"],
+ "//build/bazel/platforms/arch:x86": ["x86.py"],
+ "//conditions:default": [],
+ }),
+ srcs_version = "PY3",
+)`, bazelTarget),
+ },
+ })
+}
diff --git a/cc/androidmk.go b/cc/androidmk.go
index e95d5a7..93283d0 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -391,6 +391,8 @@
if Bool(test.Properties.Test_options.Unit_test) {
entries.SetBool("LOCAL_IS_UNIT_TEST", true)
}
+
+ entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", Bool(test.Properties.Per_testcase_directory))
})
AndroidMkWriteTestData(test.data, entries)
diff --git a/cc/cc.go b/cc/cc.go
index 57e7887..b410834 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -95,6 +95,7 @@
// Used for data dependencies adjacent to tests
DataLibs []string
+ DataBins []string
// Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
SystemSharedLibs []string
@@ -718,6 +719,7 @@
staticVariantTag = dependencyTag{name: "static variant"}
vndkExtDepTag = dependencyTag{name: "vndk extends"}
dataLibDepTag = dependencyTag{name: "data lib"}
+ dataBinDepTag = dependencyTag{name: "data bin"}
runtimeDepTag = installDependencyTag{name: "runtime lib"}
testPerSrcDepTag = dependencyTag{name: "test_per_src"}
stubImplDepTag = dependencyTag{name: "stub_impl"}
@@ -2274,6 +2276,8 @@
{Mutator: "link", Variation: "shared"},
}, dataLibDepTag, deps.DataLibs...)
+ actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
+
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "shared"},
}, runtimeDepTag, deps.RuntimeLibs...)
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 84c3a86..4c9f579 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -3869,10 +3869,99 @@
}
func TestIncludeDirectoryOrdering(t *testing.T) {
- bp := `
+ baseExpectedFlags := []string{
+ "${config.ArmThumbCflags}",
+ "${config.ArmCflags}",
+ "${config.CommonGlobalCflags}",
+ "${config.DeviceGlobalCflags}",
+ "${config.ExternalCflags}",
+ "${config.ArmToolchainCflags}",
+ "${config.ArmArmv7ANeonCflags}",
+ "${config.ArmGenericCflags}",
+ "-target",
+ "armv7a-linux-androideabi20",
+ "-B${config.ArmGccRoot}/arm-linux-androideabi/bin",
+ }
+
+ expectedIncludes := []string{
+ "external/foo/android_arm_export_include_dirs",
+ "external/foo/lib32_export_include_dirs",
+ "external/foo/arm_export_include_dirs",
+ "external/foo/android_export_include_dirs",
+ "external/foo/linux_export_include_dirs",
+ "external/foo/export_include_dirs",
+ "external/foo/android_arm_local_include_dirs",
+ "external/foo/lib32_local_include_dirs",
+ "external/foo/arm_local_include_dirs",
+ "external/foo/android_local_include_dirs",
+ "external/foo/linux_local_include_dirs",
+ "external/foo/local_include_dirs",
+ "external/foo",
+ "external/foo/libheader1",
+ "external/foo/libheader2",
+ "external/foo/libwhole1",
+ "external/foo/libwhole2",
+ "external/foo/libstatic1",
+ "external/foo/libstatic2",
+ "external/foo/libshared1",
+ "external/foo/libshared2",
+ "external/foo/liblinux",
+ "external/foo/libandroid",
+ "external/foo/libarm",
+ "external/foo/lib32",
+ "external/foo/libandroid_arm",
+ "defaults/cc/common/ndk_libc++_shared",
+ "defaults/cc/common/ndk_libandroid_support",
+ }
+
+ conly := []string{"-fPIC", "${config.CommonGlobalConlyflags}"}
+ cppOnly := []string{"-fPIC", "${config.CommonGlobalCppflags}", "${config.DeviceGlobalCppflags}", "${config.ArmCppflags}"}
+
+ cflags := []string{"-Wall", "-Werror"}
+ cstd := []string{"-std=gnu99"}
+ cppstd := []string{"-std=gnu++17", "-fno-rtti"}
+
+ lastIncludes := []string{
+ "out/soong/ndk/sysroot/usr/include",
+ "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
+ }
+
+ combineSlices := func(slices ...[]string) []string {
+ var ret []string
+ for _, s := range slices {
+ ret = append(ret, s...)
+ }
+ return ret
+ }
+
+ testCases := []struct {
+ name string
+ src string
+ expected []string
+ }{
+ {
+ name: "c",
+ src: "foo.c",
+ expected: combineSlices(baseExpectedFlags, conly, expectedIncludes, cflags, cstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}"}),
+ },
+ {
+ name: "cc",
+ src: "foo.cc",
+ expected: combineSlices(baseExpectedFlags, cppOnly, expectedIncludes, cflags, cppstd, lastIncludes, []string{"${config.NoOverrideGlobalCflags}"}),
+ },
+ {
+ name: "assemble",
+ src: "foo.s",
+ expected: combineSlices(baseExpectedFlags, []string{"-D__ASSEMBLY__"}, expectedIncludes, lastIncludes),
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ bp := fmt.Sprintf(`
cc_library {
name: "libfoo",
- srcs: ["foo.c"],
+ srcs: ["%s"],
local_include_dirs: ["local_include_dirs"],
export_include_dirs: ["export_include_dirs"],
export_system_include_dirs: ["export_system_include_dirs"],
@@ -3928,24 +4017,24 @@
sdk_version: "20",
stl: "none",
}
- `
+ `, tc.src)
- libs := []string{
- "libstatic1",
- "libstatic2",
- "libwhole1",
- "libwhole2",
- "libshared1",
- "libshared2",
- "libandroid",
- "libandroid_arm",
- "liblinux",
- "lib32",
- "libarm",
- }
+ libs := []string{
+ "libstatic1",
+ "libstatic2",
+ "libwhole1",
+ "libwhole2",
+ "libshared1",
+ "libshared2",
+ "libandroid",
+ "libandroid_arm",
+ "liblinux",
+ "lib32",
+ "libarm",
+ }
- for _, lib := range libs {
- bp += fmt.Sprintf(`
+ for _, lib := range libs {
+ bp += fmt.Sprintf(`
cc_library {
name: "%s",
export_include_dirs: ["%s"],
@@ -3953,69 +4042,30 @@
stl: "none",
}
`, lib, lib)
+ }
+
+ ctx := android.GroupFixturePreparers(
+ PrepareForIntegrationTestWithCc,
+ android.FixtureAddTextFile("external/foo/Android.bp", bp),
+ ).RunTest(t)
+ // Use the arm variant instead of the arm64 variant so that it gets headers from
+ // ndk_libandroid_support to test LateStaticLibs.
+ cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"]
+
+ var includes []string
+ flags := strings.Split(cflags, " ")
+ for _, flag := range flags {
+ if strings.HasPrefix(flag, "-I") {
+ includes = append(includes, strings.TrimPrefix(flag, "-I"))
+ } else if flag == "-isystem" {
+ // skip isystem, include next
+ } else if len(flag) > 0 {
+ includes = append(includes, flag)
+ }
+ }
+
+ android.AssertArrayString(t, "includes", tc.expected, includes)
+ })
}
- ctx := android.GroupFixturePreparers(
- PrepareForIntegrationTestWithCc,
- android.FixtureAddTextFile("external/foo/Android.bp", bp),
- ).RunTest(t)
- // Use the arm variant instead of the arm64 variant so that it gets headers from
- // ndk_libandroid_support to test LateStaticLibs.
- cflags := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_sdk_static").Output("obj/external/foo/foo.o").Args["cFlags"]
-
- var includes []string
- flags := strings.Split(cflags, " ")
- for i, flag := range flags {
- if strings.Contains(flag, "Cflags") {
- includes = append(includes, flag)
- } else if strings.HasPrefix(flag, "-I") {
- includes = append(includes, strings.TrimPrefix(flag, "-I"))
- } else if flag == "-isystem" {
- includes = append(includes, flags[i+1])
- }
- }
-
- want := []string{
- "${config.ArmThumbCflags}",
- "${config.ArmCflags}",
- "${config.CommonGlobalCflags}",
- "${config.DeviceGlobalCflags}",
- "${config.ExternalCflags}",
- "${config.ArmToolchainCflags}",
- "${config.ArmArmv7ANeonCflags}",
- "${config.ArmGenericCflags}",
- "external/foo/android_arm_export_include_dirs",
- "external/foo/lib32_export_include_dirs",
- "external/foo/arm_export_include_dirs",
- "external/foo/android_export_include_dirs",
- "external/foo/linux_export_include_dirs",
- "external/foo/export_include_dirs",
- "external/foo/android_arm_local_include_dirs",
- "external/foo/lib32_local_include_dirs",
- "external/foo/arm_local_include_dirs",
- "external/foo/android_local_include_dirs",
- "external/foo/linux_local_include_dirs",
- "external/foo/local_include_dirs",
- "external/foo",
- "external/foo/libheader1",
- "external/foo/libheader2",
- "external/foo/libwhole1",
- "external/foo/libwhole2",
- "external/foo/libstatic1",
- "external/foo/libstatic2",
- "external/foo/libshared1",
- "external/foo/libshared2",
- "external/foo/liblinux",
- "external/foo/libandroid",
- "external/foo/libarm",
- "external/foo/lib32",
- "external/foo/libandroid_arm",
- "defaults/cc/common/ndk_libc++_shared",
- "defaults/cc/common/ndk_libandroid_support",
- "out/soong/ndk/sysroot/usr/include",
- "out/soong/ndk/sysroot/usr/include/arm-linux-androideabi",
- "${config.NoOverrideGlobalCflags}",
- }
-
- android.AssertArrayString(t, "includes", want, includes)
}
diff --git a/cc/genrule.go b/cc/genrule.go
index 9df5228..239064f 100644
--- a/cc/genrule.go
+++ b/cc/genrule.go
@@ -15,6 +15,8 @@
package cc
import (
+ "fmt"
+
"android/soong/android"
"android/soong/genrule"
"android/soong/snapshot"
@@ -36,13 +38,23 @@
// cc_genrule is a genrule that can depend on other cc_* objects.
// The cmd may be run multiple times, once for each of the different arch/etc
-// variations.
+// variations. The following environment variables will be set when the command
+// execute:
+//
+// CC_ARCH the name of the architecture the command is being executed for
+//
+// CC_MULTILIB "lib32" if the architecture the command is being executed for is 32-bit,
+// "lib64" if it is 64-bit.
+//
+// CC_NATIVE_BRIDGE the name of the subdirectory that native bridge libraries are stored in if
+// the architecture has native bridge enabled, empty if it is disabled.
func GenRuleFactory() android.Module {
module := genrule.NewGenRule()
extra := &GenruleExtraProperties{}
module.Extra = extra
module.ImageInterface = extra
+ module.CmdModifier = genruleCmdModifier
module.AddProperties(module.Extra)
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth)
@@ -53,6 +65,13 @@
return module
}
+func genruleCmdModifier(ctx android.ModuleContext, cmd string) string {
+ target := ctx.Target()
+ arch := target.Arch.ArchType
+ return fmt.Sprintf("CC_ARCH=%s CC_NATIVE_BRIDGE=%s CC_MULTILIB=%s && %s",
+ arch.Name, target.NativeBridgeRelativePath, arch.Multilib, cmd)
+}
+
var _ android.ImageInterface = (*GenruleExtraProperties)(nil)
func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {}
diff --git a/cc/genrule_test.go b/cc/genrule_test.go
index b6afb05..f25f704 100644
--- a/cc/genrule_test.go
+++ b/cc/genrule_test.go
@@ -115,3 +115,75 @@
t.Errorf(`want inputs %v, got %v`, expected, got)
}
}
+
+func TestCmdPrefix(t *testing.T) {
+ bp := `
+ cc_genrule {
+ name: "gen",
+ cmd: "echo foo",
+ out: ["out"],
+ native_bridge_supported: true,
+ }
+ `
+
+ testCases := []struct {
+ name string
+ variant string
+ preparer android.FixturePreparer
+
+ arch string
+ nativeBridge string
+ multilib string
+ }{
+ {
+ name: "arm",
+ variant: "android_arm_armv7-a-neon",
+ arch: "arm",
+ multilib: "lib32",
+ },
+ {
+ name: "arm64",
+ variant: "android_arm64_armv8-a",
+ arch: "arm64",
+ multilib: "lib64",
+ },
+ {
+ name: "nativebridge",
+ variant: "android_native_bridge_arm_armv7-a-neon",
+ preparer: android.FixtureModifyConfig(func(config android.Config) {
+ config.Targets[android.Android] = []android.Target{
+ {
+ Os: android.Android,
+ Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}},
+ NativeBridge: android.NativeBridgeDisabled,
+ },
+ {
+ Os: android.Android,
+ Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}},
+ NativeBridge: android.NativeBridgeEnabled,
+ NativeBridgeHostArchName: "x86",
+ NativeBridgeRelativePath: "arm",
+ },
+ }
+ }),
+ arch: "arm",
+ multilib: "lib32",
+ nativeBridge: "arm",
+ },
+ }
+
+ for _, tt := range testCases {
+ t.Run(tt.name, func(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ PrepareForIntegrationTestWithCc,
+ android.OptionalFixturePreparer(tt.preparer),
+ ).RunTestWithBp(t, bp)
+ gen := result.ModuleForTests("gen", tt.variant)
+ sboxProto := android.RuleBuilderSboxProtoForTests(t, gen.Output("genrule.sbox.textproto"))
+ cmd := *sboxProto.Commands[0].Command
+ android.AssertStringDoesContain(t, "incorrect CC_ARCH", cmd, "CC_ARCH="+tt.arch+" ")
+ android.AssertStringDoesContain(t, "incorrect CC_NATIVE_BRIDGE", cmd, "CC_NATIVE_BRIDGE="+tt.nativeBridge+" ")
+ android.AssertStringDoesContain(t, "incorrect CC_MULTILIB", cmd, "CC_MULTILIB="+tt.multilib+" ")
+ })
+ }
+}
diff --git a/cc/object.go b/cc/object.go
index 99b257a..4ec2b19 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -122,14 +122,17 @@
// For bp2build conversion.
type bazelObjectAttributes struct {
- Srcs bazel.LabelListAttribute
- Srcs_as bazel.LabelListAttribute
- Hdrs bazel.LabelListAttribute
- Deps bazel.LabelListAttribute
- Copts bazel.StringListAttribute
- Asflags bazel.StringListAttribute
- Local_includes bazel.StringListAttribute
- Absolute_includes bazel.StringListAttribute
+ Srcs bazel.LabelListAttribute
+ Srcs_as bazel.LabelListAttribute
+ Hdrs bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
+ System_dynamic_deps bazel.LabelListAttribute
+ Copts bazel.StringListAttribute
+ Asflags bazel.StringListAttribute
+ Local_includes bazel.StringListAttribute
+ Absolute_includes bazel.StringListAttribute
+ Stl *string
+ Linker_script bazel.LabelAttribute
}
// ObjectBp2Build is the bp2build converter from cc_object modules to the
@@ -153,12 +156,26 @@
// Set arch-specific configurable attributes
compilerAttrs := bp2BuildParseCompilerProps(ctx, m)
var deps bazel.LabelListAttribute
- for _, props := range m.linker.linkerProps() {
- if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {
- deps = bazel.MakeLabelListAttribute(
- android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
+ systemDynamicDeps := bazel.LabelListAttribute{ForceSpecifyEmptyList: true}
+
+ var linkerScript bazel.LabelAttribute
+
+ for axis, configToProps := range m.GetArchVariantProperties(ctx, &ObjectLinkerProperties{}) {
+ for config, props := range configToProps {
+ if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {
+ if objectLinkerProps.Linker_script != nil {
+ linkerScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *objectLinkerProps.Linker_script))
+ }
+ deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
+ systemSharedLibs := objectLinkerProps.System_shared_libs
+ if len(systemSharedLibs) > 0 {
+ systemSharedLibs = android.FirstUniqueStrings(systemSharedLibs)
+ }
+ systemDynamicDeps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, systemSharedLibs))
+ }
}
}
+ deps.ResolveExcludes()
// Don't split cc_object srcs across languages. Doing so would add complexity,
// and this isn't typically done for cc_object.
@@ -172,13 +189,16 @@
}
attrs := &bazelObjectAttributes{
- Srcs: srcs,
- Srcs_as: compilerAttrs.asSrcs,
- Deps: deps,
- Copts: compilerAttrs.copts,
- Asflags: asFlags,
- Local_includes: compilerAttrs.localIncludes,
- Absolute_includes: compilerAttrs.absoluteIncludes,
+ Srcs: srcs,
+ Srcs_as: compilerAttrs.asSrcs,
+ Deps: deps,
+ System_dynamic_deps: systemDynamicDeps,
+ Copts: compilerAttrs.copts,
+ Asflags: asFlags,
+ Local_includes: compilerAttrs.localIncludes,
+ Absolute_includes: compilerAttrs.absoluteIncludes,
+ Stl: compilerAttrs.stl,
+ Linker_script: linkerScript,
}
props := bazel.BazelTargetModuleProperties{
diff --git a/cc/test.go b/cc/test.go
index 047a69e..c589165 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -80,6 +80,9 @@
// list of shared library modules that should be installed alongside the test
Data_libs []string `android:"arch_variant"`
+ // list of binary modules that should be installed alongside the test
+ Data_bins []string `android:"arch_variant"`
+
// list of compatibility suites (for example "cts", "vts") that the module should be
// installed into.
Test_suites []string `android:"arch_variant"`
@@ -115,6 +118,9 @@
// Add parameterized mainline modules to auto generated test config. The options will be
// handled by TradeFed to download and install the specified modules on the device.
Test_mainline_modules []string
+
+ // Install the test into a folder named for the module in all test suites.
+ Per_testcase_directory *bool
}
func init() {
@@ -347,6 +353,7 @@
deps = test.testDecorator.linkerDeps(ctx, deps)
deps = test.binaryDecorator.linkerDeps(ctx, deps)
deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...)
+ deps.DataBins = append(deps.DataBins, test.Properties.Data_bins...)
return deps
}
@@ -386,6 +393,18 @@
RelativeInstallPath: ccModule.installer.relativeInstallPath()})
}
})
+ ctx.VisitDirectDepsWithTag(dataBinDepTag, func(dep android.Module) {
+ depName := ctx.OtherModuleName(dep)
+ ccModule, ok := dep.(*Module)
+ if !ok {
+ ctx.ModuleErrorf("data_bin %q is not a cc module", depName)
+ }
+ if ccModule.OutputFile().Valid() {
+ test.data = append(test.data,
+ android.DataPath{SrcPath: ccModule.OutputFile().Path(),
+ RelativeInstallPath: ccModule.installer.relativeInstallPath()})
+ }
+ })
var configs []tradefed.Config
for _, module := range test.Properties.Test_mainline_modules {
diff --git a/genrule/genrule.go b/genrule/genrule.go
index f4bde70..96b610b 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -156,6 +156,11 @@
// For other packages to make their own genrules with extra
// properties
Extra interface{}
+
+ // CmdModifier can be set by wrappers around genrule to modify the command, for example to
+ // prefix environment variables to it.
+ CmdModifier func(ctx android.ModuleContext, cmd string) string
+
android.ImageInterface
properties generatorProperties
@@ -398,8 +403,13 @@
var outputFiles android.WritablePaths
var zipArgs strings.Builder
+ cmd := String(g.properties.Cmd)
+ if g.CmdModifier != nil {
+ cmd = g.CmdModifier(ctx, cmd)
+ }
+
// Generate tasks, either from genrule or gensrcs.
- for _, task := range g.taskGenerator(ctx, String(g.properties.Cmd), srcFiles) {
+ for _, task := range g.taskGenerator(ctx, cmd, srcFiles) {
if len(task.out) == 0 {
ctx.ModuleErrorf("must have at least one output file")
return
diff --git a/java/androidmk.go b/java/androidmk.go
index 1914595..537159e 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -71,23 +71,7 @@
entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
} else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
// Platform variant. If not available for the platform, we don't need Make module.
- // May still need to add some additional dependencies.
- checkedModulePaths := library.additionalCheckedModules
- if len(checkedModulePaths) != 0 {
- entriesList = append(entriesList, android.AndroidMkEntries{
- Class: "FAKE",
- // Need at least one output file in order for this to take effect.
- OutputFile: android.OptionalPathForPath(checkedModulePaths[0]),
- Include: "$(BUILD_PHONY_PACKAGE)",
- ExtraEntries: []android.AndroidMkExtraEntriesFunc{
- func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
- entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", checkedModulePaths.Strings()...)
- },
- },
- })
- } else {
- entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
- }
+ entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
} else {
entriesList = append(entriesList, android.AndroidMkEntries{
Class: "JAVA_LIBRARIES",
@@ -123,10 +107,6 @@
requiredUsesLibs, optionalUsesLibs := library.classLoaderContexts.UsesLibs()
entries.AddStrings("LOCAL_EXPORT_SDK_LIBRARIES", append(requiredUsesLibs, optionalUsesLibs...)...)
- if len(library.additionalCheckedModules) != 0 {
- entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...)
- }
-
entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", library.dexer.proguardDictionary)
entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", library.dexer.proguardUsageZip)
entries.SetString("LOCAL_MODULE_STEM", library.Stem())
@@ -147,20 +127,21 @@
}
// Called for modules that are a component of a test suite.
-func testSuiteComponent(entries *android.AndroidMkEntries, test_suites []string) {
+func testSuiteComponent(entries *android.AndroidMkEntries, test_suites []string, perTestcaseDirectory bool) {
entries.SetString("LOCAL_MODULE_TAGS", "tests")
if len(test_suites) > 0 {
entries.AddCompatibilityTestSuites(test_suites...)
} else {
entries.AddCompatibilityTestSuites("null-suite")
}
+ entries.SetBoolIfTrue("LOCAL_COMPATIBILITY_PER_TESTCASE_DIRECTORY", perTestcaseDirectory)
}
func (j *Test) AndroidMkEntries() []android.AndroidMkEntries {
entriesList := j.Library.AndroidMkEntries()
entries := &entriesList[0]
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
- testSuiteComponent(entries, j.testProperties.Test_suites)
+ testSuiteComponent(entries, j.testProperties.Test_suites, Bool(j.testProperties.Per_testcase_directory))
if j.testConfig != nil {
entries.SetPath("LOCAL_FULL_TEST_CONFIG", j.testConfig)
}
@@ -188,7 +169,7 @@
entriesList := j.Library.AndroidMkEntries()
entries := &entriesList[0]
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
- testSuiteComponent(entries, j.testHelperLibraryProperties.Test_suites)
+ testSuiteComponent(entries, j.testHelperLibraryProperties.Test_suites, Bool(j.testHelperLibraryProperties.Per_testcase_directory))
})
return entriesList
@@ -450,7 +431,7 @@
entriesList := a.AndroidApp.AndroidMkEntries()
entries := &entriesList[0]
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
- testSuiteComponent(entries, a.testProperties.Test_suites)
+ testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory))
if a.testConfig != nil {
entries.SetPath("LOCAL_FULL_TEST_CONFIG", a.testConfig)
}
@@ -466,7 +447,7 @@
entriesList := a.AndroidApp.AndroidMkEntries()
entries := &entriesList[0]
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
- testSuiteComponent(entries, a.appTestHelperAppProperties.Test_suites)
+ testSuiteComponent(entries, a.appTestHelperAppProperties.Test_suites, Bool(a.appTestHelperAppProperties.Per_testcase_directory))
// introduce a flag variable to control the generation of the .config file
entries.SetString("LOCAL_DISABLE_TEST_CONFIG", "true")
})
@@ -677,7 +658,7 @@
entriesList := a.AndroidAppImport.AndroidMkEntries()
entries := &entriesList[0]
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
- testSuiteComponent(entries, a.testProperties.Test_suites)
+ testSuiteComponent(entries, a.testProperties.Test_suites, Bool(a.testProperties.Per_testcase_directory))
androidMkWriteTestData(a.data, entries)
})
return entriesList
diff --git a/java/app.go b/java/app.go
index 2fd6463..bc0f488 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1070,6 +1070,9 @@
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
// explicitly.
Auto_gen_config *bool
+
+ // Install the test into a folder named for the module in all test suites.
+ Per_testcase_directory *bool
}
type AndroidTestHelperApp struct {
diff --git a/java/base.go b/java/base.go
index 579085b..ca34f2e 100644
--- a/java/base.go
+++ b/java/base.go
@@ -433,9 +433,6 @@
// expanded Jarjar_rules
expandJarjarRules android.Path
- // list of additional targets for checkbuild
- additionalCheckedModules android.Paths
-
// Extra files generated by the module type to be added as java resources.
extraResources android.Paths
@@ -1265,10 +1262,25 @@
// Check package restrictions if necessary.
if len(j.properties.Permitted_packages) > 0 {
- // Check packages and copy to package-checked file.
+ // Time stamp file created by the package check rule.
pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
+
+ // Create a rule to copy the output jar to another path and add a validate dependency that
+ // will check that the jar only contains the permitted packages. The new location will become
+ // the output file of this module.
+ inputFile := outputFile
+ outputFile = android.PathForModuleOut(ctx, "package-check", jarName).OutputPath
+ ctx.Build(pctx, android.BuildParams{
+ Rule: android.Cp,
+ Input: inputFile,
+ Output: outputFile,
+ // Make sure that any dependency on the output file will cause ninja to run the package check
+ // rule.
+ Validation: pkgckFile,
+ })
+
+ // Check packages and create a timestamp file when complete.
CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
- j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
if ctx.Failed() {
return
diff --git a/java/java.go b/java/java.go
index 94c12bd..287bcfa 100644
--- a/java/java.go
+++ b/java/java.go
@@ -73,6 +73,7 @@
android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType)
android.RegisterSdkMemberType(javaLibsSdkMemberType)
android.RegisterSdkMemberType(javaBootLibsSdkMemberType)
+ android.RegisterSdkMemberType(javaSystemserverLibsSdkMemberType)
android.RegisterSdkMemberType(javaTestSdkMemberType)
}
@@ -146,6 +147,37 @@
onlyCopyJarToSnapshot,
}
+ // Supports adding java systemserver libraries to module_exports and sdk.
+ //
+ // The build has some implicit dependencies (via the systemserver jars configuration) on a number
+ // of modules that are part of the java systemserver classpath and which are provided by mainline
+ // modules but which are not otherwise used outside those mainline modules.
+ //
+ // As they are not needed outside the mainline modules adding them to the sdk/module-exports as
+ // either java_libs, or java_header_libs would end up exporting more information than was strictly
+ // necessary. The java_systemserver_libs property to allow those modules to be exported as part of
+ // the sdk/module_exports without exposing any unnecessary information.
+ javaSystemserverLibsSdkMemberType = &librarySdkMemberType{
+ android.SdkMemberTypeBase{
+ PropertyName: "java_systemserver_libs",
+ SupportsSdk: true,
+ },
+ func(ctx android.SdkMemberContext, j *Library) android.Path {
+ // Java systemserver libs are only provided in the SDK to provide access to their dex
+ // implementation jar for use by dexpreopting. They do not need to provide an actual
+ // implementation jar but the java_import will need a file that exists so just copy an empty
+ // file. Any attempt to use that file as a jar will cause a build error.
+ return ctx.SnapshotBuilder().EmptyFile()
+ },
+ func(osPrefix, name string) string {
+ // Create a special name for the implementation jar to try and provide some useful information
+ // to a developer that attempts to compile against this.
+ // TODO(b/175714559): Provide a proper error message in Soong not ninja.
+ return filepath.Join(osPrefix, "java_systemserver_libs", "snapshot", "jars", "are", "invalid", name+jarFileSuffix)
+ },
+ onlyCopyJarToSnapshot,
+ }
+
// Supports adding java test libraries to module_exports but not sdk.
javaTestSdkMemberType = &testSdkMemberType{
SdkMemberTypeBase: android.SdkMemberTypeBase{
@@ -749,6 +781,9 @@
// Names of modules containing JNI libraries that should be installed alongside the test.
Jni_libs []string
+
+ // Install the test into a folder named for the module in all test suites.
+ Per_testcase_directory *bool
}
type hostTestProperties struct {
@@ -760,6 +795,9 @@
// list of compatibility suites (for example "cts", "vts") that the module should be
// installed into.
Test_suites []string `android:"arch_variant"`
+
+ // Install the test into a folder named for the module in all test suites.
+ Per_testcase_directory *bool
}
type prebuiltTestProperties struct {
@@ -1360,10 +1398,19 @@
if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(j.BaseModuleName())); dexOutputPath != nil {
dexJarFile := makeDexJarPathFromPath(dexOutputPath)
j.dexJarFile = dexJarFile
- j.dexJarInstallFile = android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName()))
+ installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName()))
+ j.dexJarInstallFile = installPath
// Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, dexJarFile, outputFile, nil)
+
+ j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath)
+ if j.dexProperties.Uncompress_dex == nil {
+ // If the value was not force-set by the user, use reasonable default based on the module.
+ j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
+ }
+ j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
+ j.dexpreopt(ctx, dexOutputPath)
} else {
// This should never happen as a variant for a prebuilt_apex is only created if the
// prebuilt_apex has been configured to export the java library dex file.
diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go
index de2a978..f209f4a 100644
--- a/java/systemserver_classpath_fragment.go
+++ b/java/systemserver_classpath_fragment.go
@@ -23,11 +23,19 @@
func init() {
registerSystemserverClasspathBuildComponents(android.InitRegistrationContext)
+
+ android.RegisterSdkMemberType(&systemServerClasspathFragmentMemberType{
+ SdkMemberTypeBase: android.SdkMemberTypeBase{
+ PropertyName: "systemserverclasspath_fragments",
+ SupportsSdk: true,
+ },
+ })
}
func registerSystemserverClasspathBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("platform_systemserverclasspath", platformSystemServerClasspathFactory)
ctx.RegisterModuleType("systemserverclasspath_fragment", systemServerClasspathFactory)
+ ctx.RegisterModuleType("prebuilt_systemserverclasspath_fragment", prebuiltSystemServerClasspathModuleFactory)
}
type platformSystemServerClasspathModule struct {
@@ -61,6 +69,7 @@
type SystemServerClasspathModule struct {
android.ModuleBase
android.ApexModuleBase
+ android.SdkBase
ClasspathFragmentBase
@@ -85,6 +94,7 @@
m := &SystemServerClasspathModule{}
m.AddProperties(&m.properties)
android.InitApexModule(m)
+ android.InitSdkAwareModule(m)
initClasspathFragment(m, SYSTEMSERVERCLASSPATH)
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
return m
@@ -112,8 +122,8 @@
_, unknown = android.RemoveFromList("geotz", unknown)
// For non test apexes, make sure that all contents are actually declared in make.
- if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 {
- ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS", unknown)
+ if global.ApexSystemServerJars.Len() > 0 && len(unknown) > 0 && !android.IsModuleInVersionedSdk(ctx.Module()) {
+ ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_SYSTEM_SERVER_JARS", unknown)
}
return jars
@@ -128,12 +138,33 @@
return false
}
+// SdkMemberType causes dependencies added with this tag to be automatically added to the sdk as if
+// they were specified using java_systemserver_libs or java_sdk_libs.
+func (b systemServerClasspathFragmentContentDependencyTag) SdkMemberType(child android.Module) android.SdkMemberType {
+ // If the module is a java_sdk_library then treat it as if it was specified in the java_sdk_libs
+ // property, otherwise treat if it was specified in the java_systemserver_libs property.
+ if javaSdkLibrarySdkMemberType.IsInstance(child) {
+ return javaSdkLibrarySdkMemberType
+ }
+
+ return javaSystemserverLibsSdkMemberType
+}
+
+func (b systemServerClasspathFragmentContentDependencyTag) ExportMember() bool {
+ return true
+}
+
// Contents of system server fragments in an apex are considered to be directly in the apex, as if
// they were listed in java_libs.
func (systemServerClasspathFragmentContentDependencyTag) CopyDirectlyInAnyApex() {}
+// Contents of system server fragments require files from prebuilt apex files.
+func (systemServerClasspathFragmentContentDependencyTag) RequiresFilesFromPrebuiltApex() {}
+
var _ android.ReplaceSourceWithPrebuilt = systemServerClasspathFragmentContentDepTag
+var _ android.SdkMemberDependencyTag = systemServerClasspathFragmentContentDepTag
var _ android.CopyDirectlyInAnyApexTag = systemServerClasspathFragmentContentDepTag
+var _ android.RequiresFilesFromPrebuiltApexTag = systemServerClasspathFragmentContentDepTag
// The tag used for the dependency between the systemserverclasspath_fragment module and its contents.
var systemServerClasspathFragmentContentDepTag = systemServerClasspathFragmentContentDependencyTag{}
@@ -144,8 +175,14 @@
func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpMutatorContext) {
module := ctx.Module()
+ _, isSourceModule := module.(*SystemServerClasspathModule)
for _, name := range s.properties.Contents {
+ // A systemserverclasspath_fragment must depend only on other source modules, while the
+ // prebuilt_systemserverclasspath_fragment_fragment must only depend on other prebuilt modules.
+ if !isSourceModule {
+ name = android.PrebuiltNameFromSource(name)
+ }
ctx.AddDependency(module, systemServerClasspathFragmentContentDepTag, name)
}
}
@@ -155,3 +192,80 @@
dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
dpInfo.Paths = append(dpInfo.Paths, s.modulePaths...)
}
+
+type systemServerClasspathFragmentMemberType struct {
+ android.SdkMemberTypeBase
+}
+
+func (s *systemServerClasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
+ ctx.AddVariationDependencies(nil, dependencyTag, names...)
+}
+
+func (s *systemServerClasspathFragmentMemberType) IsInstance(module android.Module) bool {
+ _, ok := module.(*SystemServerClasspathModule)
+ return ok
+}
+
+func (s *systemServerClasspathFragmentMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
+ return ctx.SnapshotBuilder().AddPrebuiltModule(member, "prebuilt_systemserverclasspath_fragment")
+}
+
+func (s *systemServerClasspathFragmentMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
+ return &systemServerClasspathFragmentSdkMemberProperties{}
+}
+
+type systemServerClasspathFragmentSdkMemberProperties struct {
+ android.SdkMemberPropertiesBase
+
+ // Contents of the systemserverclasspath fragment
+ Contents []string
+}
+
+func (s *systemServerClasspathFragmentSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
+ module := variant.(*SystemServerClasspathModule)
+
+ s.Contents = module.properties.Contents
+}
+
+func (s *systemServerClasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
+ builder := ctx.SnapshotBuilder()
+ requiredMemberDependency := builder.SdkMemberReferencePropertyTag(true)
+
+ if len(s.Contents) > 0 {
+ propertySet.AddPropertyWithTag("contents", s.Contents, requiredMemberDependency)
+ }
+}
+
+var _ android.SdkMemberType = (*systemServerClasspathFragmentMemberType)(nil)
+
+// A prebuilt version of the systemserverclasspath_fragment module.
+type prebuiltSystemServerClasspathModule struct {
+ SystemServerClasspathModule
+ prebuilt android.Prebuilt
+}
+
+func (module *prebuiltSystemServerClasspathModule) Prebuilt() *android.Prebuilt {
+ return &module.prebuilt
+}
+
+func (module *prebuiltSystemServerClasspathModule) Name() string {
+ return module.prebuilt.Name(module.ModuleBase.Name())
+}
+
+func (module *prebuiltSystemServerClasspathModule) RequiredFilesFromPrebuiltApex(ctx android.BaseModuleContext) []string {
+ return nil
+}
+
+var _ android.RequiredFilesFromPrebuiltApex = (*prebuiltSystemServerClasspathModule)(nil)
+
+func prebuiltSystemServerClasspathModuleFactory() android.Module {
+ m := &prebuiltSystemServerClasspathModule{}
+ m.AddProperties(&m.properties)
+ // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs
+ // array.
+ android.InitPrebuiltModule(m, &[]string{"placeholder"})
+ android.InitApexModule(m)
+ android.InitSdkAwareModule(m)
+ android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
+ return m
+}
diff --git a/mk2rbc/cmd/mk2rbc.go b/mk2rbc/cmd/mk2rbc.go
index 7b5f298..9d0f0c1 100644
--- a/mk2rbc/cmd/mk2rbc.go
+++ b/mk2rbc/cmd/mk2rbc.go
@@ -154,47 +154,49 @@
}
// Convert!
- ok := true
- if *launcher != "" {
- if len(flag.Args()) != 1 {
- quit(fmt.Errorf("a launcher can be generated only for a single product"))
+ files := flag.Args()
+ productConfigMap := buildProductConfigMap()
+ if *allInSource {
+ for _, path := range productConfigMap {
+ files = append(files, path)
}
- product := flag.Args()[0]
- productConfigMap := buildProductConfigMap()
- path, found := productConfigMap[product]
- if !found {
- quit(fmt.Errorf("cannot generate configuration launcher for %s, it is not a known product",
- product))
+ }
+ for i, file := range files {
+ if _, err := os.Stat(file); os.IsNotExist(err) {
+ temp, ok := productConfigMap[file]
+ if ok {
+ files[i] = temp
+ } else {
+ quit(fmt.Errorf("%s is neither a product makefile nor a product name", file))
+ }
+ }
+ }
+ ok := true
+ for _, mkFile := range files {
+ ok = convertOne(mkFile) && ok
+ }
+
+ if *launcher != "" {
+ if len(files) != 1 {
+ quit(fmt.Errorf("a launcher can be generated only for a single product"))
}
versionDefaults, err := generateVersionDefaults()
if err != nil {
quit(err)
}
- ok = convertOne(path) && ok
versionDefaultsPath := outputFilePath(versionDefaultsMk)
err = writeGenerated(versionDefaultsPath, versionDefaults)
if err != nil {
- fmt.Fprintf(os.Stderr, "%s:%s", path, err)
+ fmt.Fprintf(os.Stderr, "%s:%s", files[0], err)
ok = false
}
- err = writeGenerated(*launcher, mk2rbc.Launcher(outputFilePath(path), versionDefaultsPath,
- mk2rbc.MakePath2ModuleName(path)))
+ err = writeGenerated(*launcher, mk2rbc.Launcher(outputFilePath(files[0]), versionDefaultsPath,
+ mk2rbc.MakePath2ModuleName(files[0])))
if err != nil {
- fmt.Fprintf(os.Stderr, "%s:%s", path, err)
+ fmt.Fprintf(os.Stderr, "%s:%s", files[0], err)
ok = false
}
- } else {
- files := flag.Args()
- if *allInSource {
- productConfigMap := buildProductConfigMap()
- for _, path := range productConfigMap {
- files = append(files, path)
- }
- }
- for _, mkFile := range files {
- ok = convertOne(mkFile) && ok
- }
}
printStats()
diff --git a/python/binary.go b/python/binary.go
index bc2768c..afcc53a 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -63,6 +63,7 @@
}
}
}
+
// TODO(b/182306917): this doesn't fully handle all nested props versioned
// by the python version, which would have been handled by the version split
// mutator. This is sufficient for very simple python_binary_host modules
@@ -80,15 +81,12 @@
// do nothing, since python_version defaults to PY3.
}
- srcs := android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs)
- data := android.BazelLabelForModuleSrc(ctx, m.properties.Data)
- deps := android.BazelLabelForModuleDeps(ctx, m.properties.Libs)
-
+ baseAttrs := m.makeArchVariantBaseAttributes(ctx)
attrs := &bazelPythonBinaryAttributes{
Main: main,
- Srcs: bazel.MakeLabelListAttribute(srcs),
- Data: bazel.MakeLabelListAttribute(data),
- Deps: bazel.MakeLabelListAttribute(deps),
+ Srcs: baseAttrs.Srcs,
+ Data: baseAttrs.Data,
+ Deps: baseAttrs.Deps,
Python_version: python_version,
}
diff --git a/python/library.go b/python/library.go
index a132216..19fa59a 100644
--- a/python/library.go
+++ b/python/library.go
@@ -88,14 +88,11 @@
// do nothing, since python_version defaults to PY2ANDPY3
}
- srcs := android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs)
- data := android.BazelLabelForModuleSrc(ctx, m.properties.Data)
- deps := android.BazelLabelForModuleDeps(ctx, m.properties.Libs)
-
+ baseAttrs := m.makeArchVariantBaseAttributes(ctx)
attrs := &bazelPythonLibraryAttributes{
- Srcs: bazel.MakeLabelListAttribute(srcs),
- Data: bazel.MakeLabelListAttribute(data),
- Deps: bazel.MakeLabelListAttribute(deps),
+ Srcs: baseAttrs.Srcs,
+ Data: baseAttrs.Data,
+ Deps: baseAttrs.Deps,
Srcs_version: python_version,
}
diff --git a/python/python.go b/python/python.go
index f900172..401d91f 100644
--- a/python/python.go
+++ b/python/python.go
@@ -22,6 +22,7 @@
"regexp"
"strings"
+ "android/soong/bazel"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -120,6 +121,18 @@
Embedded_launcher *bool `blueprint:"mutated"`
}
+type baseAttributes struct {
+ // TODO(b/200311466): Probably not translate b/c Bazel has no good equiv
+ //Pkg_path bazel.StringAttribute
+ // TODO: Related to Pkg_bath and similarLy gated
+ //Is_internal bazel.BoolAttribute
+ // Combines Srcs and Exclude_srcs
+ Srcs bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
+ // Combines Data and Java_data (invariant)
+ Data bazel.LabelListAttribute
+}
+
// Used to store files of current module after expanding dependencies
type pathMapping struct {
dest string
@@ -177,6 +190,25 @@
}
}
+func (m *Module) makeArchVariantBaseAttributes(ctx android.TopDownMutatorContext) baseAttributes {
+ var attrs baseAttributes
+ archVariantBaseProps := m.GetArchVariantProperties(ctx, &BaseProperties{})
+ for axis, configToProps := range archVariantBaseProps {
+ for config, props := range configToProps {
+ if baseProps, ok := props.(*BaseProperties); ok {
+ attrs.Srcs.SetSelectValue(axis, config,
+ android.BazelLabelForModuleSrcExcludes(ctx, baseProps.Srcs, baseProps.Exclude_srcs))
+ attrs.Deps.SetSelectValue(axis, config,
+ android.BazelLabelForModuleDeps(ctx, baseProps.Libs))
+ data := android.BazelLabelForModuleSrc(ctx, baseProps.Data)
+ data.Append(android.BazelLabelForModuleSrc(ctx, baseProps.Java_data))
+ attrs.Data.SetSelectValue(axis, config, data)
+ }
+ }
+ }
+ return attrs
+}
+
// bootstrapper interface should be implemented for runnable modules, e.g. binary and test
type bootstrapper interface {
bootstrapperProps() []interface{}
diff --git a/rust/rust.go b/rust/rust.go
index 0a7d68d..b9afc7f 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -663,7 +663,7 @@
}
func (mod *Module) installable(apexInfo android.ApexInfo) bool {
- if !mod.EverInstallable() {
+ if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
return false
}
diff --git a/scripts/package-check.sh b/scripts/package-check.sh
index d7e602f..9f4a9da 100755
--- a/scripts/package-check.sh
+++ b/scripts/package-check.sh
@@ -42,7 +42,7 @@
fi
# Transform to a slash-separated path and add a trailing slash to enforce
# package name boundary.
- prefixes+=("${package//\./\/}/")
+ prefixes+=("${package//\.//}/")
shift
done
diff --git a/sdk/Android.bp b/sdk/Android.bp
index c6544d6..f42b478 100644
--- a/sdk/Android.bp
+++ b/sdk/Android.bp
@@ -11,10 +11,12 @@
"soong-android",
"soong-apex",
"soong-cc",
+ "soong-dexpreopt",
"soong-java",
],
srcs: [
"bp.go",
+ "build_release.go",
"exports.go",
"member_trait.go",
"member_type.go",
@@ -24,6 +26,7 @@
testSrcs: [
"bootclasspath_fragment_sdk_test.go",
"bp_test.go",
+ "build_release_test.go",
"cc_sdk_test.go",
"compat_config_sdk_test.go",
"exports_test.go",
@@ -31,6 +34,7 @@
"license_sdk_test.go",
"member_trait_test.go",
"sdk_test.go",
+ "systemserverclasspath_fragment_sdk_test.go",
"testing.go",
],
pluginFor: ["soong_build"],
diff --git a/sdk/build_release.go b/sdk/build_release.go
new file mode 100644
index 0000000..a3f0899
--- /dev/null
+++ b/sdk/build_release.go
@@ -0,0 +1,324 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sdk
+
+import (
+ "fmt"
+ "reflect"
+ "strings"
+)
+
+// Supports customizing sdk snapshot output based on target build release.
+
+// buildRelease represents the version of a build system used to create a specific release.
+//
+// The name of the release, is the same as the code for the dessert release, e.g. S, T, etc.
+type buildRelease struct {
+ // The name of the release, e.g. S, T, etc.
+ name string
+
+ // The index of this structure within the buildReleases list.
+ ordinal int
+}
+
+// String returns the name of the build release.
+func (s *buildRelease) String() string {
+ return s.name
+}
+
+// buildReleaseSet represents a set of buildRelease objects.
+type buildReleaseSet struct {
+ // Set of *buildRelease represented as a map from *buildRelease to struct{}.
+ contents map[*buildRelease]struct{}
+}
+
+// addItem adds a build release to the set.
+func (s *buildReleaseSet) addItem(release *buildRelease) {
+ s.contents[release] = struct{}{}
+}
+
+// addRange adds all the build releases from start (inclusive) to end (inclusive).
+func (s *buildReleaseSet) addRange(start *buildRelease, end *buildRelease) {
+ for i := start.ordinal; i <= end.ordinal; i += 1 {
+ s.addItem(buildReleases[i])
+ }
+}
+
+// contains returns true if the set contains the specified build release.
+func (s *buildReleaseSet) contains(release *buildRelease) bool {
+ _, ok := s.contents[release]
+ return ok
+}
+
+// String returns a string representation of the set, sorted from earliest to latest release.
+func (s *buildReleaseSet) String() string {
+ list := []string{}
+ for _, release := range buildReleases {
+ if _, ok := s.contents[release]; ok {
+ list = append(list, release.name)
+ }
+ }
+ return fmt.Sprintf("[%s]", strings.Join(list, ","))
+}
+
+var (
+ // nameToBuildRelease contains a map from name to build release.
+ nameToBuildRelease = map[string]*buildRelease{}
+
+ // buildReleases lists all the available build releases.
+ buildReleases = []*buildRelease{}
+
+ // allBuildReleaseSet is the set of all build releases.
+ allBuildReleaseSet = &buildReleaseSet{contents: map[*buildRelease]struct{}{}}
+
+ // Add the build releases from oldest to newest.
+ buildReleaseS = initBuildRelease("S")
+ buildReleaseT = initBuildRelease("T")
+)
+
+// initBuildRelease creates a new build release with the specified name.
+func initBuildRelease(name string) *buildRelease {
+ ordinal := len(nameToBuildRelease)
+ release := &buildRelease{name: name, ordinal: ordinal}
+ nameToBuildRelease[name] = release
+ buildReleases = append(buildReleases, release)
+ allBuildReleaseSet.addItem(release)
+ return release
+}
+
+// latestBuildRelease returns the latest build release, i.e. the last one added.
+func latestBuildRelease() *buildRelease {
+ return buildReleases[len(buildReleases)-1]
+}
+
+// nameToRelease maps from build release name to the corresponding build release (if it exists) or
+// the error if it does not.
+func nameToRelease(name string) (*buildRelease, error) {
+ if r, ok := nameToBuildRelease[name]; ok {
+ return r, nil
+ }
+
+ return nil, fmt.Errorf("unknown release %q, expected one of %s", name, allBuildReleaseSet)
+}
+
+// parseBuildReleaseSet parses a build release set string specification into a build release set.
+//
+// The specification consists of one of the following:
+// * a single build release name, e.g. S, T, etc.
+// * a closed range (inclusive to inclusive), e.g. S-T
+// * an open range, e.g. T+.
+//
+// This returns the set if the specification was valid or an error.
+func parseBuildReleaseSet(specification string) (*buildReleaseSet, error) {
+ set := &buildReleaseSet{contents: map[*buildRelease]struct{}{}}
+
+ if strings.HasSuffix(specification, "+") {
+ rangeStart := strings.TrimSuffix(specification, "+")
+ start, err := nameToRelease(rangeStart)
+ if err != nil {
+ return nil, err
+ }
+ end := latestBuildRelease()
+ set.addRange(start, end)
+ } else if strings.Contains(specification, "-") {
+ limits := strings.SplitN(specification, "-", 2)
+ start, err := nameToRelease(limits[0])
+ if err != nil {
+ return nil, err
+ }
+
+ end, err := nameToRelease(limits[1])
+ if err != nil {
+ return nil, err
+ }
+
+ if start.ordinal > end.ordinal {
+ return nil, fmt.Errorf("invalid closed range, start release %q is later than end release %q", start.name, end.name)
+ }
+
+ set.addRange(start, end)
+ } else {
+ release, err := nameToRelease(specification)
+ if err != nil {
+ return nil, err
+ }
+ set.addItem(release)
+ }
+
+ return set, nil
+}
+
+// Given a set of properties (struct value), set the value of a field within that struct (or one of
+// its embedded structs) to its zero value.
+type fieldPrunerFunc func(structValue reflect.Value)
+
+// A property that can be cleared by a propertyPruner.
+type prunerProperty struct {
+ // The name of the field for this property. It is a "."-separated path for fields in non-anonymous
+ // sub-structs.
+ name string
+
+ // Sets the associated field to its zero value.
+ prunerFunc fieldPrunerFunc
+}
+
+// propertyPruner provides support for pruning (i.e. setting to their zero value) properties from
+// a properties structure.
+type propertyPruner struct {
+ // The properties that the pruner will clear.
+ properties []prunerProperty
+}
+
+// gatherFields recursively processes the supplied structure and a nested structures, selecting the
+// fields that require pruning and populates the propertyPruner.properties with the information
+// needed to prune those fields.
+//
+// containingStructAccessor is a func that if given an object will return a field whose value is
+// of the supplied structType. It is nil on initial entry to this method but when this method is
+// called recursively on a field that is a nested structure containingStructAccessor is set to a
+// func that provides access to the field's value.
+//
+// namePrefix is the prefix to the fields that are being visited. It is "" on initial entry to this
+// method but when this method is called recursively on a field that is a nested structure
+// namePrefix is the result of appending the field name (plus a ".") to the previous name prefix.
+// Unless the field is anonymous in which case it is passed through unchanged.
+//
+// selector is a func that will select whether the supplied field requires pruning or not. If it
+// returns true then the field will be added to those to be pruned, otherwise it will not.
+func (p *propertyPruner) gatherFields(structType reflect.Type, containingStructAccessor fieldAccessorFunc, namePrefix string, selector fieldSelectorFunc) {
+ for f := 0; f < structType.NumField(); f++ {
+ field := structType.Field(f)
+ if field.PkgPath != "" {
+ // Ignore unexported fields.
+ continue
+ }
+
+ // Save a copy of the field index for use in the function.
+ fieldIndex := f
+
+ name := namePrefix + field.Name
+
+ fieldGetter := func(container reflect.Value) reflect.Value {
+ if containingStructAccessor != nil {
+ // This is an embedded structure so first access the field for the embedded
+ // structure.
+ container = containingStructAccessor(container)
+ }
+
+ // Skip through interface and pointer values to find the structure.
+ container = getStructValue(container)
+
+ defer func() {
+ if r := recover(); r != nil {
+ panic(fmt.Errorf("%s for fieldIndex %d of field %s of container %#v", r, fieldIndex, name, container.Interface()))
+ }
+ }()
+
+ // Return the field.
+ return container.Field(fieldIndex)
+ }
+
+ zeroValue := reflect.Zero(field.Type)
+ fieldPruner := func(container reflect.Value) {
+ if containingStructAccessor != nil {
+ // This is an embedded structure so first access the field for the embedded
+ // structure.
+ container = containingStructAccessor(container)
+ }
+
+ // Skip through interface and pointer values to find the structure.
+ container = getStructValue(container)
+
+ defer func() {
+ if r := recover(); r != nil {
+ panic(fmt.Errorf("%s for fieldIndex %d of field %s of container %#v", r, fieldIndex, name, container.Interface()))
+ }
+ }()
+
+ // Set the field.
+ container.Field(fieldIndex).Set(zeroValue)
+ }
+
+ if selector(name, field) {
+ property := prunerProperty{
+ name,
+ fieldPruner,
+ }
+ p.properties = append(p.properties, property)
+ } else if field.Type.Kind() == reflect.Struct {
+ // Gather fields from the nested or embedded structure.
+ var subNamePrefix string
+ if field.Anonymous {
+ subNamePrefix = namePrefix
+ } else {
+ subNamePrefix = name + "."
+ }
+ p.gatherFields(field.Type, fieldGetter, subNamePrefix, selector)
+ }
+ }
+}
+
+// pruneProperties will prune (set to zero value) any properties in the supplied struct.
+//
+// The struct must be of the same type as was originally passed to newPropertyPruner to create this
+// propertyPruner.
+func (p *propertyPruner) pruneProperties(propertiesStruct interface{}) {
+ structValue := reflect.ValueOf(propertiesStruct)
+ for _, property := range p.properties {
+ property.prunerFunc(structValue)
+ }
+}
+
+// fieldSelectorFunc is called to select whether a specific field should be pruned or not.
+// name is the name of the field, including any prefixes from containing str
+type fieldSelectorFunc func(name string, field reflect.StructField) bool
+
+// newPropertyPruner creates a new property pruner for the structure type for the supplied
+// properties struct.
+//
+// The returned pruner can be used on any properties structure of the same type as the supplied set
+// of properties.
+func newPropertyPruner(propertiesStruct interface{}, selector fieldSelectorFunc) *propertyPruner {
+ structType := getStructValue(reflect.ValueOf(propertiesStruct)).Type()
+ pruner := &propertyPruner{}
+ pruner.gatherFields(structType, nil, "", selector)
+ return pruner
+}
+
+// newPropertyPrunerByBuildRelease creates a property pruner that will clear any properties in the
+// structure which are not supported by the specified target build release.
+//
+// A property is pruned if its field has a tag of the form:
+// `supported_build_releases:"<build-release-set>"`
+// and the resulting build release set does not contain the target build release. Properties that
+// have no such tag are assumed to be supported by all releases.
+func newPropertyPrunerByBuildRelease(propertiesStruct interface{}, targetBuildRelease *buildRelease) *propertyPruner {
+ return newPropertyPruner(propertiesStruct, func(name string, field reflect.StructField) bool {
+ if supportedBuildReleases, ok := field.Tag.Lookup("supported_build_releases"); ok {
+ set, err := parseBuildReleaseSet(supportedBuildReleases)
+ if err != nil {
+ panic(fmt.Errorf("invalid `supported_build_releases` tag on %s of %T: %s", name, propertiesStruct, err))
+ }
+
+ // If the field does not support tha target release then prune it.
+ return !set.contains(targetBuildRelease)
+
+ } else {
+ // Any untagged fields are assumed to be supported by all build releases so should never be
+ // pruned.
+ return false
+ }
+ })
+}
diff --git a/sdk/build_release_test.go b/sdk/build_release_test.go
new file mode 100644
index 0000000..dff276d
--- /dev/null
+++ b/sdk/build_release_test.go
@@ -0,0 +1,185 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sdk
+
+import (
+ "fmt"
+ "testing"
+
+ "android/soong/android"
+)
+
+// Tests for build_release.go
+
+var (
+ // Some additional test specific releases that are added after the currently supported ones and
+ // so are treated as being for future releases.
+ buildReleaseFuture1 = initBuildRelease("F1")
+ buildReleaseFuture2 = initBuildRelease("F2")
+)
+
+func TestNameToRelease(t *testing.T) {
+ t.Run("single release", func(t *testing.T) {
+ release, err := nameToRelease("S")
+ android.AssertDeepEquals(t, "errors", nil, err)
+ android.AssertDeepEquals(t, "release", buildReleaseS, release)
+ })
+ t.Run("invalid release", func(t *testing.T) {
+ release, err := nameToRelease("A")
+ android.AssertDeepEquals(t, "release", (*buildRelease)(nil), release)
+ // Uses a wildcard in the error message to allow for additional build releases to be added to
+ // the supported set without breaking this test.
+ android.FailIfNoMatchingErrors(t, `unknown release "A", expected one of \[S,T.*,F1,F2\]`, []error{err})
+ })
+}
+
+func TestParseBuildReleaseSet(t *testing.T) {
+ t.Run("single release", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("S")
+ android.AssertDeepEquals(t, "errors", nil, err)
+ android.AssertStringEquals(t, "set", "[S]", set.String())
+ })
+ t.Run("open range", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("F1+")
+ android.AssertDeepEquals(t, "errors", nil, err)
+ android.AssertStringEquals(t, "set", "[F1,F2]", set.String())
+ })
+ t.Run("closed range", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("S-F1")
+ android.AssertDeepEquals(t, "errors", nil, err)
+ android.AssertStringEquals(t, "set", "[S,T,F1]", set.String())
+ })
+ invalidAReleaseMessage := `unknown release "A", expected one of ` + allBuildReleaseSet.String()
+ t.Run("invalid release", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("A")
+ android.AssertDeepEquals(t, "set", (*buildReleaseSet)(nil), set)
+ android.AssertStringDoesContain(t, "errors", fmt.Sprint(err), invalidAReleaseMessage)
+ })
+ t.Run("invalid release in open range", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("A+")
+ android.AssertDeepEquals(t, "set", (*buildReleaseSet)(nil), set)
+ android.AssertStringDoesContain(t, "errors", fmt.Sprint(err), invalidAReleaseMessage)
+ })
+ t.Run("invalid release in closed range start", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("A-S")
+ android.AssertDeepEquals(t, "set", (*buildReleaseSet)(nil), set)
+ android.AssertStringDoesContain(t, "errors", fmt.Sprint(err), invalidAReleaseMessage)
+ })
+ t.Run("invalid release in closed range end", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("T-A")
+ android.AssertDeepEquals(t, "set", (*buildReleaseSet)(nil), set)
+ android.AssertStringDoesContain(t, "errors", fmt.Sprint(err), invalidAReleaseMessage)
+ })
+ t.Run("invalid closed range reversed", func(t *testing.T) {
+ set, err := parseBuildReleaseSet("F1-S")
+ android.AssertDeepEquals(t, "set", (*buildReleaseSet)(nil), set)
+ android.AssertStringDoesContain(t, "errors", fmt.Sprint(err), `invalid closed range, start release "F1" is later than end release "S"`)
+ })
+}
+
+func TestBuildReleaseSetContains(t *testing.T) {
+ t.Run("contains", func(t *testing.T) {
+ set, _ := parseBuildReleaseSet("F1-F2")
+ android.AssertBoolEquals(t, "set contains F1", true, set.contains(buildReleaseFuture1))
+ android.AssertBoolEquals(t, "set does not contain S", false, set.contains(buildReleaseS))
+ android.AssertBoolEquals(t, "set contains F2", true, set.contains(buildReleaseFuture2))
+ android.AssertBoolEquals(t, "set does not contain T", false, set.contains(buildReleaseT))
+ })
+}
+
+func TestPropertyPrunerInvalidTag(t *testing.T) {
+ type brokenStruct struct {
+ Broken string `supported_build_releases:"A"`
+ }
+ type containingStruct struct {
+ Nested brokenStruct
+ }
+
+ t.Run("broken struct", func(t *testing.T) {
+ android.AssertPanicMessageContains(t, "error", "invalid `supported_build_releases` tag on Broken of *sdk.brokenStruct: unknown release \"A\"", func() {
+ newPropertyPrunerByBuildRelease(&brokenStruct{}, buildReleaseS)
+ })
+ })
+
+ t.Run("nested broken struct", func(t *testing.T) {
+ android.AssertPanicMessageContains(t, "error", "invalid `supported_build_releases` tag on Nested.Broken of *sdk.containingStruct: unknown release \"A\"", func() {
+ newPropertyPrunerByBuildRelease(&containingStruct{}, buildReleaseS)
+ })
+ })
+}
+
+func TestPropertyPrunerByBuildRelease(t *testing.T) {
+ type nested struct {
+ F1_only string `supported_build_releases:"F1"`
+ }
+
+ type testBuildReleasePruner struct {
+ Default string
+ S_and_T_only string `supported_build_releases:"S-T"`
+ T_later string `supported_build_releases:"T+"`
+ Nested nested
+ }
+
+ input := testBuildReleasePruner{
+ Default: "Default",
+ S_and_T_only: "S_and_T_only",
+ T_later: "T_later",
+ Nested: nested{
+ F1_only: "F1_only",
+ },
+ }
+
+ t.Run("target S", func(t *testing.T) {
+ testStruct := input
+ pruner := newPropertyPrunerByBuildRelease(&testStruct, buildReleaseS)
+ pruner.pruneProperties(&testStruct)
+
+ expected := input
+ expected.T_later = ""
+ expected.Nested.F1_only = ""
+ android.AssertDeepEquals(t, "test struct", expected, testStruct)
+ })
+
+ t.Run("target T", func(t *testing.T) {
+ testStruct := input
+ pruner := newPropertyPrunerByBuildRelease(&testStruct, buildReleaseT)
+ pruner.pruneProperties(&testStruct)
+
+ expected := input
+ expected.Nested.F1_only = ""
+ android.AssertDeepEquals(t, "test struct", expected, testStruct)
+ })
+
+ t.Run("target F1", func(t *testing.T) {
+ testStruct := input
+ pruner := newPropertyPrunerByBuildRelease(&testStruct, buildReleaseFuture1)
+ pruner.pruneProperties(&testStruct)
+
+ expected := input
+ expected.S_and_T_only = ""
+ android.AssertDeepEquals(t, "test struct", expected, testStruct)
+ })
+
+ t.Run("target F2", func(t *testing.T) {
+ testStruct := input
+ pruner := newPropertyPrunerByBuildRelease(&testStruct, buildReleaseFuture2)
+ pruner.pruneProperties(&testStruct)
+
+ expected := input
+ expected.S_and_T_only = ""
+ expected.Nested.F1_only = ""
+ android.AssertDeepEquals(t, "test struct", expected, testStruct)
+ })
+}
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 2b53739..0d9b4a0 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -482,6 +482,71 @@
)
}
+func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForSdkTestWithJava,
+ android.FixtureAddFile("aidl", nil),
+ android.FixtureAddFile("resource.txt", nil),
+ ).RunTestWithBp(t, `
+ module_exports {
+ name: "myexports",
+ java_systemserver_libs: ["myjavalib"],
+ }
+
+ java_library {
+ name: "myjavalib",
+ srcs: ["Test.java"],
+ java_resources: ["resource.txt"],
+ // The aidl files should not be copied to the snapshot because a java_systemserver_libs member
+ // is not intended to be used for compiling Java, only for accessing the dex implementation
+ // jar.
+ aidl: {
+ export_include_dirs: ["aidl"],
+ },
+ system_modules: "none",
+ sdk_version: "none",
+ compile_dex: true,
+ permitted_packages: ["pkg.myjavalib"],
+ }
+ `)
+
+ CheckSnapshot(t, result, "myexports", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "myjavalib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"],
+ permitted_packages: ["pkg.myjavalib"],
+}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "myexports_myjavalib@current",
+ sdk_member_name: "myjavalib",
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"],
+ permitted_packages: ["pkg.myjavalib"],
+}
+
+module_exports_snapshot {
+ name: "myexports@current",
+ visibility: ["//visibility:public"],
+ java_systemserver_libs: ["myexports_myjavalib@current"],
+}
+`),
+ checkAllCopyRules(`
+.intermediates/myexports/common_os/empty -> java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar
+`),
+ )
+}
+
func TestHostSnapshotWithJavaImplLibrary(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index 85e3d87..f5f6898 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -21,6 +21,7 @@
"testing"
"android/soong/android"
+ "android/soong/java"
"github.com/google/blueprint/proptools"
)
@@ -706,4 +707,88 @@
snapshotTestPreparer(checkSnapshotWithoutSource, android.FixtureWithRootAndroidBp(bp)),
)
})
+
+ t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForSdkTestWithJava,
+ java.PrepareForTestWithJavaDefaultModules,
+ java.PrepareForTestWithJavaSdkLibraryFiles,
+ java.FixtureWithLastReleaseApis("mysdklibrary"),
+ android.FixtureWithRootAndroidBp(`
+ sdk {
+ name: "mysdk",
+ bootclasspath_fragments: ["mybootclasspathfragment"],
+ }
+
+ bootclasspath_fragment {
+ name: "mybootclasspathfragment",
+ apex_available: ["myapex"],
+ contents: ["mysdklibrary"],
+ }
+
+ java_sdk_library {
+ name: "mysdklibrary",
+ srcs: ["Test.java"],
+ compile_dex: true,
+ public: {enabled: true},
+ permitted_packages: ["mysdklibrary"],
+ }
+ `),
+ android.FixtureMergeEnv(map[string]string{
+ "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S",
+ }),
+ ).RunTest(t)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+prebuilt_bootclasspath_fragment {
+ name: "mybootclasspathfragment",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["myapex"],
+ contents: ["mysdklibrary"],
+ hidden_api: {
+ annotation_flags: "hiddenapi/annotation-flags.csv",
+ metadata: "hiddenapi/metadata.csv",
+ index: "hiddenapi/index.csv",
+ signature_patterns: "hiddenapi/signature-patterns.csv",
+ stub_flags: "hiddenapi/filtered-stub-flags.csv",
+ all_flags: "hiddenapi/filtered-flags.csv",
+ },
+}
+
+java_sdk_library_import {
+ name: "mysdklibrary",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["//apex_available:platform"],
+ shared_library: true,
+ compile_dex: true,
+ permitted_packages: ["mysdklibrary"],
+ public: {
+ jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
+ stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
+ current_api: "sdk_library/public/mysdklibrary.txt",
+ removed_api: "sdk_library/public/mysdklibrary-removed.txt",
+ sdk_version: "current",
+ },
+}
+`),
+
+ checkAllCopyRules(`
+.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
+.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
+.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
+.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
+.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
+.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
+.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
+.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
+.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
+`),
+ )
+ })
+
}
diff --git a/sdk/systemserverclasspath_fragment_sdk_test.go b/sdk/systemserverclasspath_fragment_sdk_test.go
new file mode 100644
index 0000000..16e3e7f
--- /dev/null
+++ b/sdk/systemserverclasspath_fragment_sdk_test.go
@@ -0,0 +1,171 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package sdk
+
+import (
+ "testing"
+
+ "android/soong/android"
+ "android/soong/dexpreopt"
+ "android/soong/java"
+)
+
+func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ prepareForSdkTestWithJava,
+ java.PrepareForTestWithJavaDefaultModules,
+ java.PrepareForTestWithJavaSdkLibraryFiles,
+ java.FixtureWithLastReleaseApis("mysdklibrary"),
+ dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"),
+ prepareForSdkTestWithApex,
+
+ android.FixtureWithRootAndroidBp(`
+ sdk {
+ name: "mysdk",
+ systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
+ java_sdk_libs: [
+ // This is not strictly needed as it should be automatically added to the sdk_snapshot as
+ // a java_sdk_libs module because it is used in the mysystemserverclasspathfragment's
+ // contents property. However, it is specified here to ensure that duplicates are
+ // correctly deduped.
+ "mysdklibrary",
+ ],
+ }
+
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ min_sdk_version: "2",
+ systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
+ }
+
+ systemserverclasspath_fragment {
+ name: "mysystemserverclasspathfragment",
+ apex_available: ["myapex"],
+ contents: [
+ "mylib",
+ "mysdklibrary",
+ ],
+ }
+
+ java_library {
+ name: "mylib",
+ apex_available: ["myapex"],
+ srcs: ["Test.java"],
+ system_modules: "none",
+ sdk_version: "none",
+ min_sdk_version: "2",
+ compile_dex: true,
+ permitted_packages: ["mylib"],
+ }
+
+ java_sdk_library {
+ name: "mysdklibrary",
+ apex_available: ["myapex"],
+ srcs: ["Test.java"],
+ shared_library: false,
+ public: {enabled: true},
+ min_sdk_version: "2",
+ }
+ `),
+ ).RunTest(t)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "mysdklibrary",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["myapex"],
+ shared_library: false,
+ public: {
+ jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
+ stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
+ current_api: "sdk_library/public/mysdklibrary.txt",
+ removed_api: "sdk_library/public/mysdklibrary-removed.txt",
+ sdk_version: "current",
+ },
+}
+
+java_import {
+ name: "mylib",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["myapex"],
+ jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
+ permitted_packages: ["mylib"],
+}
+
+prebuilt_systemserverclasspath_fragment {
+ name: "mysystemserverclasspathfragment",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["myapex"],
+ contents: [
+ "mylib",
+ "mysdklibrary",
+ ],
+}
+`),
+ checkVersionedAndroidBpContents(`
+// This is auto-generated. DO NOT EDIT.
+
+java_sdk_library_import {
+ name: "mysdk_mysdklibrary@current",
+ sdk_member_name: "mysdklibrary",
+ visibility: ["//visibility:public"],
+ apex_available: ["myapex"],
+ shared_library: false,
+ public: {
+ jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
+ stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
+ current_api: "sdk_library/public/mysdklibrary.txt",
+ removed_api: "sdk_library/public/mysdklibrary-removed.txt",
+ sdk_version: "current",
+ },
+}
+
+java_import {
+ name: "mysdk_mylib@current",
+ sdk_member_name: "mylib",
+ visibility: ["//visibility:public"],
+ apex_available: ["myapex"],
+ jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
+ permitted_packages: ["mylib"],
+}
+
+prebuilt_systemserverclasspath_fragment {
+ name: "mysdk_mysystemserverclasspathfragment@current",
+ sdk_member_name: "mysystemserverclasspathfragment",
+ visibility: ["//visibility:public"],
+ apex_available: ["myapex"],
+ contents: [
+ "mysdk_mylib@current",
+ "mysdk_mysdklibrary@current",
+ ],
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ visibility: ["//visibility:public"],
+ java_sdk_libs: ["mysdk_mysdklibrary@current"],
+ java_systemserver_libs: ["mysdk_mylib@current"],
+ systemserverclasspath_fragments: ["mysdk_mysystemserverclasspathfragment@current"],
+}
+`),
+ )
+}
diff --git a/sdk/testing.go b/sdk/testing.go
index 3254cf9..294f1a5 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -136,6 +136,7 @@
androidUnversionedBpContents: sdk.GetUnversionedAndroidBpContentsForTests(),
androidVersionedBpContents: sdk.GetVersionedAndroidBpContentsForTests(),
snapshotTestCustomizations: map[snapshotTest]*snapshotTestCustomization{},
+ targetBuildRelease: sdk.builderForTests.targetBuildRelease,
}
buildParams := sdk.BuildParamsForTests()
@@ -253,6 +254,13 @@
}
fs[filepath.Join(snapshotSubDir, "Android.bp")] = []byte(snapshotBuildInfo.androidBpContents)
+ // If the generated snapshot builders not for the current release then it cannot be loaded by
+ // the current release.
+ currentBuildRelease := latestBuildRelease()
+ if snapshotBuildInfo.targetBuildRelease != currentBuildRelease {
+ return
+ }
+
// The preparers from the original source fixture.
sourcePreparers := result.Preparer()
@@ -476,6 +484,9 @@
// The final output zip.
outputZip string
+ // The target build release.
+ targetBuildRelease *buildRelease
+
// The test specific customizations for each snapshot test.
snapshotTestCustomizations map[snapshotTest]*snapshotTestCustomization
}
diff --git a/sdk/update.go b/sdk/update.go
index 3246832..389e845 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -81,6 +81,19 @@
// snapshot module only. The zip file containing the generated snapshot will be
// <sdk-name>-<number>.zip.
//
+// SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE
+// This allows the target build release (i.e. the release version of the build within which
+// the snapshot will be used) of the snapshot to be specified. If unspecified then it defaults
+// to the current build release version. Otherwise, it must be the name of one of the build
+// releases defined in nameToBuildRelease, e.g. S, T, etc..
+//
+// The generated snapshot must only be used in the specified target release. If the target
+// build release is not the current build release then the generated Android.bp file not be
+// checked for compatibility.
+//
+// e.g. if setting SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S will cause the generated snapshot
+// to be compatible with S.
+//
var pctx = android.NewPackageContext("android/soong/sdk")
@@ -358,6 +371,14 @@
snapshotZipFileSuffix = "-" + version
}
+ currentBuildRelease := latestBuildRelease()
+ targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name)
+ targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv)
+ if err != nil {
+ ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err)
+ targetBuildRelease = currentBuildRelease
+ }
+
builder := &snapshotBuilder{
ctx: ctx,
sdk: s,
@@ -369,6 +390,7 @@
prebuiltModules: make(map[string]*bpModule),
allMembersByName: allMembersByName,
exportedMembersByName: exportedMembersByName,
+ targetBuildRelease: targetBuildRelease,
}
s.builderForTests = builder
@@ -449,7 +471,11 @@
generateBpContents(&bp.generatedContents, bpFile)
contents := bp.content.String()
- syntaxCheckSnapshotBpFile(ctx, contents)
+ // If the snapshot is being generated for the current build release then check the syntax to make
+ // sure that it is compatible.
+ if targetBuildRelease == currentBuildRelease {
+ syntaxCheckSnapshotBpFile(ctx, contents)
+ }
bp.build(pctx, ctx, nil)
@@ -1051,6 +1077,9 @@
// The set of exported members by name.
exportedMembersByName map[string]struct{}
+
+ // The target build release for which the snapshot is to be generated.
+ targetBuildRelease *buildRelease
}
func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) {
@@ -1426,6 +1455,16 @@
return osInfo
}
+func (osInfo *osTypeSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ if len(osInfo.archInfos) == 0 {
+ pruner.pruneProperties(osInfo.Properties)
+ } else {
+ for _, archInfo := range osInfo.archInfos {
+ archInfo.pruneUnsupportedProperties(pruner)
+ }
+ }
+}
+
// Optimize the properties by extracting common properties from arch type specific
// properties into os type specific properties.
func (osInfo *osTypeSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
@@ -1635,6 +1674,16 @@
return linkType
}
+func (archInfo *archTypeSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ if len(archInfo.imageVariantInfos) == 0 {
+ pruner.pruneProperties(archInfo.Properties)
+ } else {
+ for _, imageVariantInfo := range archInfo.imageVariantInfos {
+ imageVariantInfo.pruneUnsupportedProperties(pruner)
+ }
+ }
+}
+
// Optimize the properties by extracting common properties from link type specific
// properties into arch type specific properties.
func (archInfo *archTypeSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
@@ -1732,6 +1781,16 @@
return imageInfo
}
+func (imageInfo *imageVariantSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ if len(imageInfo.linkInfos) == 0 {
+ pruner.pruneProperties(imageInfo.Properties)
+ } else {
+ for _, linkInfo := range imageInfo.linkInfos {
+ linkInfo.pruneUnsupportedProperties(pruner)
+ }
+ }
+}
+
// Optimize the properties by extracting common properties from link type specific
// properties into arch type specific properties.
func (imageInfo *imageVariantSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
@@ -1798,6 +1857,10 @@
addSdkMemberPropertiesToSet(ctx, l.Properties, linkPropertySet)
}
+func (l *linkTypeSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ pruner.pruneProperties(l.Properties)
+}
+
func (l *linkTypeSpecificInfo) String() string {
return fmt.Sprintf("LinkType{%s}", l.linkType)
}
@@ -1837,12 +1900,12 @@
memberType := member.memberType
// Do not add the prefer property if the member snapshot module is a source module type.
+ config := ctx.sdkMemberContext.Config()
if !memberType.UsesSourceModuleTypeInSnapshot() {
// Set the prefer based on the environment variable. This is a temporary work around to allow a
// snapshot to be created that sets prefer: true.
// TODO(b/174997203): Remove once the ability to select the modules to prefer can be done
// dynamically at build time not at snapshot generation time.
- config := ctx.sdkMemberContext.Config()
prefer := config.IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER")
// Set prefer. Setting this to false is not strictly required as that is the default but it does
@@ -1884,6 +1947,11 @@
commonProperties := variantPropertiesFactory()
commonProperties.Base().Os = android.CommonOS
+ // Create a property pruner that will prune any properties unsupported by the target build
+ // release.
+ targetBuildRelease := ctx.builder.targetBuildRelease
+ unsupportedPropertyPruner := newPropertyPrunerByBuildRelease(commonProperties, targetBuildRelease)
+
// Create common value extractor that can be used to optimize the properties.
commonValueExtractor := newCommonValueExtractor(commonProperties)
@@ -1898,6 +1966,8 @@
// independent properties structs.
osSpecificPropertiesContainers = append(osSpecificPropertiesContainers, osInfo)
+ osInfo.pruneUnsupportedProperties(unsupportedPropertyPruner)
+
// Optimize the properties across all the variants for a specific os type.
osInfo.optimizeProperties(ctx, commonValueExtractor)
}
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index 3d16073..afec829 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -163,6 +163,7 @@
"AUX_OS_VARIANT_LIST",
"PRODUCT_SOONG_NAMESPACES",
"SOONG_SDK_SNAPSHOT_PREFER",
+ "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE",
"SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR",
"SOONG_SDK_SNAPSHOT_VERSION",
}