summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2023-01-15 11:38:45 -0800
committerLinux Build Service Account <lnxbuild@localhost>2023-01-15 11:38:45 -0800
commitc1ebb8f5c2d4b29008997460e5af1728e3331392 (patch)
tree4d3909187e1bf15367c6fec81d1865097ebfbdd0
parentacc7acb7e4de8e58d3cee4a5cec933b583ddcf53 (diff)
parent2f36e2d29219744ae4ab5731bc9911f310229936 (diff)
Merge 2f36e2d29219744ae4ab5731bc9911f310229936 on remote branch
Change-Id: I1d9889d41e537a00e260ae3015575b4aaafee997
-rw-r--r--android/arch.go12
-rw-r--r--android/config.go4
-rw-r--r--android/sdk.go17
-rw-r--r--android/variable.go2
-rw-r--r--apex/apex.go52
-rw-r--r--cmd/extract_apks/main.go90
-rw-r--r--cmd/extract_apks/main_test.go364
-rw-r--r--cmd/pom2bp/pom2bp.go14
-rw-r--r--java/java.go33
-rw-r--r--java/systemserver_classpath_fragment.go3
-rw-r--r--sdk/build_release.go12
-rw-r--r--sdk/java_sdk_test.go71
-rw-r--r--sdk/systemserverclasspath_fragment_sdk_test.go65
-rw-r--r--sdk/update.go41
14 files changed, 683 insertions, 97 deletions
diff --git a/android/arch.go b/android/arch.go
index cbf77c758..3587b469f 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -655,7 +655,8 @@ func archMutator(bpctx blueprint.BottomUpMutatorContext) {
prefer32 := os == Windows
// Determine the multilib selection for this module.
- multilib, extraMultilib := decodeMultilib(base, os)
+ force_first_on_device := mctx.Config().ForceMultilibFirstOnDevice()
+ multilib, extraMultilib := decodeMultilib(base, os, force_first_on_device)
// Convert the multilib selection into a list of Targets.
targets, err := decodeMultilibTargets(multilib, osTargets, prefer32)
@@ -730,7 +731,7 @@ func addTargetProperties(m Module, target Target, multiTargets []Target, primary
// multilib from the factory's call to InitAndroidArchModule if none was set. For modules that
// called InitAndroidMultiTargetsArchModule it always returns "common" for multilib, and returns
// the actual multilib in extraMultilib.
-func decodeMultilib(base *ModuleBase, os OsType) (multilib, extraMultilib string) {
+func decodeMultilib(base *ModuleBase, os OsType, force_first_on_device bool) (multilib, extraMultilib string) {
// First check the "android.compile_multilib" or "host.compile_multilib" properties.
switch os.Class {
case Device:
@@ -749,6 +750,13 @@ func decodeMultilib(base *ModuleBase, os OsType) (multilib, extraMultilib string
multilib = base.commonProperties.Default_multilib
}
+ // If a device is configured with multiple targets, this option
+ // force all device targets that prefer32 to be compiled only as
+ // the first target.
+ if force_first_on_device && os.Class == Device && (multilib == "prefer32" || multilib == "first_prefer32") {
+ multilib = "first"
+ }
+
if base.commonProperties.UseTargetVariants {
// Darwin has the concept of "universal binaries" which is implemented in Soong by
// building both x86_64 and arm64 variants, and having select module types know how to
diff --git a/android/config.go b/android/config.go
index 8f7adaa4b..fa704faac 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1757,6 +1757,10 @@ func (c *deviceConfig) GenerateAidlNdkPlatformBackend() bool {
return c.config.productVariables.GenerateAidlNdkPlatformBackend
}
+func (c *config) ForceMultilibFirstOnDevice() bool {
+ return c.productVariables.ForceMultilibFirstOnDevice
+}
+
// The ConfiguredJarList struct provides methods for handling a list of (apex, jar) pairs.
// Such lists are used in the build system for things like bootclasspath jars or system server jars.
// The apex part is either an apex name, or a special names "platform" or "system_ext". Jar is a
diff --git a/android/sdk.go b/android/sdk.go
index 3a5624030..1ce692fb6 100644
--- a/android/sdk.go
+++ b/android/sdk.go
@@ -661,6 +661,10 @@ type SdkMemberType interface {
// an Android.bp file.
RequiresBpProperty() bool
+ // SupportedBuildReleases returns the string representation of a set of target build releases that
+ // support this member type.
+ SupportedBuildReleases() string
+
// UsableWithSdkAndSdkSnapshot returns true if the member type supports the sdk/sdk_snapshot,
// false otherwise.
UsableWithSdkAndSdkSnapshot() bool
@@ -760,6 +764,11 @@ type SdkMemberTypeBase struct {
// property to be specifiable in an Android.bp file.
BpPropertyNotRequired bool
+ // The name of the first targeted build release.
+ //
+ // If not specified then it is assumed to be available on all targeted build releases.
+ SupportedBuildReleaseSpecification string
+
SupportsSdk bool
HostOsDependent bool
@@ -780,6 +789,10 @@ func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
return !b.BpPropertyNotRequired
}
+func (b *SdkMemberTypeBase) SupportedBuildReleases() string {
+ return b.SupportedBuildReleaseSpecification
+}
+
func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
return b.SupportsSdk
}
@@ -933,6 +946,10 @@ type SdkMemberContext interface {
// RequiresTrait returns true if this member is expected to provide the specified trait.
RequiresTrait(trait SdkMemberTrait) bool
+
+ // IsTargetBuildBeforeTiramisu return true if the target build release for which this snapshot is
+ // being generated is before Tiramisu, i.e. S.
+ IsTargetBuildBeforeTiramisu() bool
}
// ExportedComponentsInfo contains information about the components that this module exports to an
diff --git a/android/variable.go b/android/variable.go
index aef3a1478..2c7eded56 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -489,6 +489,8 @@ type productVariables struct {
SepolicyFreezeTestExtraPrebuiltDirs []string `json:",omitempty"`
GenerateAidlNdkPlatformBackend bool `json:",omitempty"`
+
+ ForceMultilibFirstOnDevice bool `json:",omitempty"`
}
func boolPtr(v bool) *bool {
diff --git a/apex/apex.go b/apex/apex.go
index 2a64135eb..afb05d0ca 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2776,61 +2776,13 @@ func makeApexAvailableBaseline() map[string][]string {
// Module separator
//
m["com.android.btservices"] = []string{
- "bluetooth-protos-lite",
- "internal_include_headers",
- "libaudio-a2dp-hw-utils",
- "libaudio-hearing-aid-hw-utils",
- "libbluetooth",
- "libbluetooth-types",
- "libbluetooth-types-header",
- "libbluetooth_gd",
- "libbluetooth_headers",
- "libbluetooth_jni",
- "libbt-audio-hal-interface",
- "libbt-bta",
- "libbt-common",
- "libbt-hci",
- "libbt-platform-protos-lite",
- "libbt-protos-lite",
- "libbt-sbc-decoder",
- "libbt-sbc-encoder",
- "libbt-stack",
- "libbt-utils",
- "libbtcore",
- "libbtdevice",
- "libbte",
- "libbtif",
- "libchrome",
+ // empty
}
//
// Module separator
//
m["com.android.bluetooth"] = []string{
- "bluetooth-protos-lite",
- "internal_include_headers",
- "libaudio-a2dp-hw-utils",
- "libaudio-hearing-aid-hw-utils",
- "libbluetooth",
- "libbluetooth-types",
- "libbluetooth-types-header",
- "libbluetooth_gd",
- "libbluetooth_headers",
- "libbluetooth_jni",
- "libbt-audio-hal-interface",
- "libbt-bta",
- "libbt-common",
- "libbt-hci",
- "libbt-platform-protos-lite",
- "libbt-protos-lite",
- "libbt-sbc-decoder",
- "libbt-sbc-encoder",
- "libbt-stack",
- "libbt-utils",
- "libbtcore",
- "libbtdevice",
- "libbte",
- "libbtif",
- "libchrome",
+ // empty
}
//
// Module separator
diff --git a/cmd/extract_apks/main.go b/cmd/extract_apks/main.go
index 1cf64de8b..e39f8d765 100644
--- a/cmd/extract_apks/main.go
+++ b/cmd/extract_apks/main.go
@@ -29,6 +29,7 @@ import (
"google.golang.org/protobuf/proto"
+ "android/soong/cmd/extract_apks/bundle_proto"
android_bundle_proto "android/soong/cmd/extract_apks/bundle_proto"
"android/soong/third_party/zip"
)
@@ -197,6 +198,49 @@ type multiAbiTargetingMatcher struct {
*android_bundle_proto.MultiAbiTargeting
}
+type multiAbiValue []*bundle_proto.Abi
+
+func (m multiAbiValue) compare(other multiAbiValue) int {
+ min := func(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+ }
+
+ sortAbis := func(abiSlice multiAbiValue) func(i, j int) bool {
+ return func(i, j int) bool {
+ // sort priorities greatest to least
+ return multiAbiPriorities[abiSlice[i].Alias] > multiAbiPriorities[abiSlice[j].Alias]
+ }
+ }
+
+ m = append(multiAbiValue{}, m...)
+ sort.Slice(m, sortAbis(m))
+ other = append(multiAbiValue{}, other...)
+ sort.Slice(other, sortAbis(other))
+
+ for i := 0; i < min(len(m), len(other)); i++ {
+ if multiAbiPriorities[m[i].Alias] > multiAbiPriorities[other[i].Alias] {
+ return 1
+ }
+ if multiAbiPriorities[m[i].Alias] < multiAbiPriorities[other[i].Alias] {
+ return -1
+ }
+ }
+
+ if len(m) == len(other) {
+ return 0
+ }
+ if len(m) > len(other) {
+ return 1
+ }
+ return -1
+}
+
+// this logic should match the logic in bundletool at
+// https://github.com/google/bundletool/blob/ae0fc0162fd80d92ef8f4ef4527c066f0106942f/src/main/java/com/android/tools/build/bundletool/device/MultiAbiMatcher.java#L43
+// (note link is the commit at time of writing; but logic should always match the latest)
func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool {
if t.MultiAbiTargeting == nil {
return true
@@ -204,31 +248,45 @@ func (t multiAbiTargetingMatcher) matches(config TargetConfig) bool {
if _, ok := config.abis[android_bundle_proto.Abi_UNSPECIFIED_CPU_ARCHITECTURE]; ok {
return true
}
- // Find the one with the highest priority.
- highestPriority := 0
- for _, v := range t.GetValue() {
- for _, a := range v.GetAbi() {
- if _, ok := config.abis[a.Alias]; ok {
- if highestPriority < multiAbiPriorities[a.Alias] {
- highestPriority = multiAbiPriorities[a.Alias]
- }
+
+ multiAbiIsValid := func(m multiAbiValue) bool {
+ for _, abi := range m {
+ if _, ok := config.abis[abi.Alias]; !ok {
+ return false
}
}
+ return true
+ }
+
+ // ensure that the current value is valid for our config
+ valueSetContainsViableAbi := false
+ multiAbiSet := t.GetValue()
+ for _, multiAbi := range multiAbiSet {
+ if multiAbiIsValid(multiAbi.GetAbi()) {
+ valueSetContainsViableAbi = true
+ }
}
- if highestPriority == 0 {
+
+ if !valueSetContainsViableAbi {
return false
}
+
// See if there are any matching alternatives with a higher priority.
- for _, v := range t.GetAlternatives() {
- for _, a := range v.GetAbi() {
- if _, ok := config.abis[a.Alias]; ok {
- if highestPriority < multiAbiPriorities[a.Alias] {
- // There's a better one. Skip this one.
- return false
- }
+ for _, altMultiAbi := range t.GetAlternatives() {
+ if !multiAbiIsValid(altMultiAbi.GetAbi()) {
+ continue
+ }
+
+ for _, multiAbi := range multiAbiSet {
+ valueAbis := multiAbiValue(multiAbi.GetAbi())
+ altAbis := multiAbiValue(altMultiAbi.GetAbi())
+ if valueAbis.compare(altAbis) < 0 {
+ // An alternative has a higher priority, don't use this one
+ return false
}
}
}
+
return true
}
diff --git a/cmd/extract_apks/main_test.go b/cmd/extract_apks/main_test.go
index f5e40466a..c1d712df4 100644
--- a/cmd/extract_apks/main_test.go
+++ b/cmd/extract_apks/main_test.go
@@ -420,6 +420,370 @@ bundletool {
}
}
+func TestSelectApks_ApexSet_Variants(t *testing.T) {
+ testCases := []testDesc{
+ {
+ protoText: `
+variant {
+ targeting {
+ sdk_version_targeting {value {min {value: 29}}}
+ multi_abi_targeting {
+ value {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: X86}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ apk_set {
+ module_metadata {
+ name: "base"
+ delivery_type: INSTALL_TIME
+ }
+ apk_description {
+ targeting {
+ multi_abi_targeting {
+ value {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: X86}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ path: "standalones/standalone-armeabi_v7a.apex"
+ }
+ }
+ variant_number: 0
+}
+variant {
+ targeting {
+ sdk_version_targeting {value {min {value: 29}}}
+ multi_abi_targeting {
+ value {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: X86}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ apk_set {
+ module_metadata {
+ name: "base"
+ delivery_type: INSTALL_TIME
+ }
+ apk_description {
+ targeting {
+ multi_abi_targeting {
+ value {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: X86}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ path: "standalones/standalone-arm64_v8a.apex"
+ }
+ }
+ variant_number: 1
+}
+variant {
+ targeting {
+ sdk_version_targeting {value {min {value: 29}}}
+ multi_abi_targeting {
+ value {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: X86}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ apk_set {
+ module_metadata {
+ name: "base"
+ delivery_type: INSTALL_TIME
+ }
+ apk_description {
+ targeting {
+ multi_abi_targeting {
+ value {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: X86}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ path: "standalones/standalone-armeabi_v7a.arm64_v8a.apex"
+ }
+ }
+ variant_number: 2
+}
+variant {
+ targeting {
+ sdk_version_targeting {value {min {value: 29}}}
+ multi_abi_targeting {
+ value {abi {alias: X86}}
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ apk_set {
+ module_metadata {
+ name: "base"
+ delivery_type: INSTALL_TIME
+ }
+ apk_description {
+ targeting {
+ multi_abi_targeting {
+ value {abi {alias: X86}}
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ }
+ }
+ path: "standalones/standalone-x86.apex"
+ }
+ }
+ variant_number: 3
+}
+variant {
+ targeting {
+ sdk_version_targeting {value {min {value: 29}}}
+ multi_abi_targeting {
+ value {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: X86}}
+ }
+ }
+ apk_set {
+ module_metadata {
+ name: "base"
+ delivery_type: INSTALL_TIME
+ }
+ apk_description {
+ targeting {
+ multi_abi_targeting {
+ value {
+ abi {alias: X86}
+ abi {alias: X86_64}
+ }
+ alternatives {abi {alias: ARMEABI_V7A}}
+ alternatives {
+ abi {alias: ARMEABI_V7A}
+ abi {alias: ARM64_V8A}
+ }
+ alternatives {abi {alias: ARM64_V8A}}
+ alternatives {abi {alias: X86}}
+ }
+ }
+ path: "standalones/standalone-x86.x86_64.apex"
+ }
+ }
+ variant_number: 4
+}
+`,
+ configs: []testConfigDesc{
+ {
+ name: "multi-variant multi-target ARM",
+ targetConfig: TargetConfig{
+ sdkVersion: 33,
+ screenDpi: map[bp.ScreenDensity_DensityAlias]bool{
+ bp.ScreenDensity_DENSITY_UNSPECIFIED: true,
+ },
+ abis: map[bp.Abi_AbiAlias]int{
+ bp.Abi_ARM64_V8A: 0,
+ bp.Abi_ARMEABI_V7A: 1,
+ },
+ },
+ expected: SelectionResult{
+ "base",
+ []string{
+ "standalones/standalone-armeabi_v7a.arm64_v8a.apex",
+ },
+ },
+ },
+ {
+ name: "multi-variant single-target arm",
+ targetConfig: TargetConfig{
+ sdkVersion: 33,
+ screenDpi: map[bp.ScreenDensity_DensityAlias]bool{
+ bp.ScreenDensity_DENSITY_UNSPECIFIED: true,
+ },
+ abis: map[bp.Abi_AbiAlias]int{
+ bp.Abi_ARMEABI_V7A: 0,
+ },
+ },
+ expected: SelectionResult{
+ "base",
+ []string{
+ "standalones/standalone-armeabi_v7a.apex",
+ },
+ },
+ },
+ {
+ name: "multi-variant single-target arm64",
+ targetConfig: TargetConfig{
+ sdkVersion: 33,
+ screenDpi: map[bp.ScreenDensity_DensityAlias]bool{
+ bp.ScreenDensity_DENSITY_UNSPECIFIED: true,
+ },
+ abis: map[bp.Abi_AbiAlias]int{
+ bp.Abi_ARM64_V8A: 0,
+ },
+ },
+ expected: SelectionResult{
+ "base",
+ []string{
+ "standalones/standalone-arm64_v8a.apex",
+ },
+ },
+ },
+ {
+ name: "multi-variant multi-target x86",
+ targetConfig: TargetConfig{
+ sdkVersion: 33,
+ screenDpi: map[bp.ScreenDensity_DensityAlias]bool{
+ bp.ScreenDensity_DENSITY_UNSPECIFIED: true,
+ },
+ abis: map[bp.Abi_AbiAlias]int{
+ bp.Abi_X86: 0,
+ bp.Abi_X86_64: 1,
+ },
+ },
+ expected: SelectionResult{
+ "base",
+ []string{
+ "standalones/standalone-x86.x86_64.apex",
+ },
+ },
+ },
+ {
+ name: "multi-variant single-target x86",
+ targetConfig: TargetConfig{
+ sdkVersion: 33,
+ screenDpi: map[bp.ScreenDensity_DensityAlias]bool{
+ bp.ScreenDensity_DENSITY_UNSPECIFIED: true,
+ },
+ abis: map[bp.Abi_AbiAlias]int{
+ bp.Abi_X86: 0,
+ },
+ },
+ expected: SelectionResult{
+ "base",
+ []string{
+ "standalones/standalone-x86.apex",
+ },
+ },
+ },
+ {
+ name: "multi-variant single-target x86_64",
+ targetConfig: TargetConfig{
+ sdkVersion: 33,
+ screenDpi: map[bp.ScreenDensity_DensityAlias]bool{
+ bp.ScreenDensity_DENSITY_UNSPECIFIED: true,
+ },
+ abis: map[bp.Abi_AbiAlias]int{
+ bp.Abi_X86_64: 0,
+ },
+ },
+ expected: SelectionResult{},
+ },
+ {
+ name: "multi-variant multi-target cross-target",
+ targetConfig: TargetConfig{
+ sdkVersion: 33,
+ screenDpi: map[bp.ScreenDensity_DensityAlias]bool{
+ bp.ScreenDensity_DENSITY_UNSPECIFIED: true,
+ },
+ abis: map[bp.Abi_AbiAlias]int{
+ bp.Abi_ARM64_V8A: 0,
+ bp.Abi_X86_64: 1,
+ },
+ },
+ expected: SelectionResult{
+ "base",
+ []string{
+ "standalones/standalone-arm64_v8a.apex",
+ },
+ },
+ },
+ },
+ },
+ }
+ for _, testCase := range testCases {
+ var toc bp.BuildApksResult
+ if err := prototext.Unmarshal([]byte(testCase.protoText), &toc); err != nil {
+ t.Fatal(err)
+ }
+ for _, config := range testCase.configs {
+ t.Run(config.name, func(t *testing.T) {
+ actual := selectApks(&toc, config.targetConfig)
+ if !reflect.DeepEqual(config.expected, actual) {
+ t.Errorf("expected %v, got %v", config.expected, actual)
+ }
+ })
+ }
+ }
+}
+
type testZip2ZipWriter struct {
entries map[string]string
}
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go
index f8844fc94..e0638b8ed 100644
--- a/cmd/pom2bp/pom2bp.go
+++ b/cmd/pom2bp/pom2bp.go
@@ -150,6 +150,7 @@ var sdkVersion string
var defaultMinSdkVersion string
var useVersion string
var staticDeps bool
+var writeCmd bool
var jetifier bool
func InList(s string, list []string) bool {
@@ -810,6 +811,9 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib
-use-version <version>
If the maven directory contains multiple versions of artifacts and their pom files,
-use-version can be used to only write Android.bp files for a specific version of those artifacts.
+ -write-cmd
+ Whether to write the command line arguments used to generate the build file as a comment at
+ the top of the build file itself.
-jetifier
Sets jetifier: true for all modules.
<dir>
@@ -836,6 +840,7 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib
flag.StringVar(&defaultMinSdkVersion, "default-min-sdk-version", "24", "Default min_sdk_version to use, if one is not available from AndroidManifest.xml. Default: 24")
flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version")
flag.BoolVar(&staticDeps, "static-deps", false, "Statically include direct dependencies")
+ flag.BoolVar(&writeCmd, "write-cmd", true, "Write command line arguments as a comment")
flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules")
flag.StringVar(&regen, "regen", "", "Rewrite specified file")
flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file")
@@ -962,8 +967,13 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib
if pom2build {
commentString = "#"
}
- fmt.Fprintln(buf, commentString, "Automatically generated with:")
- fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " "))
+
+ fmt.Fprintln(buf, commentString, "This is a generated file. Do not modify directly.")
+
+ if writeCmd {
+ fmt.Fprintln(buf, commentString, "Automatically generated with:")
+ fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " "))
+ }
depsTemplate := bpDepsTemplate
template := bpTemplate
diff --git a/java/java.go b/java/java.go
index c8fb93cca..1e99aa32f 100644
--- a/java/java.go
+++ b/java/java.go
@@ -118,6 +118,16 @@ var (
copyEverythingToSnapshot,
}
+ snapshotRequiresImplementationJar = func(ctx android.SdkMemberContext) bool {
+ // In the S build the build will break if updatable-media does not provide a full implementation
+ // jar. That issue was fixed in Tiramisu by b/229932396.
+ if ctx.IsTargetBuildBeforeTiramisu() && ctx.Name() == "updatable-media" {
+ return true
+ }
+
+ return false
+ }
+
// Supports adding java boot libraries to module_exports and sdk.
//
// The build has some implicit dependencies (via the boot jars configuration) on a number of
@@ -135,13 +145,21 @@ var (
SupportsSdk: true,
},
func(ctx android.SdkMemberContext, j *Library) android.Path {
+ if snapshotRequiresImplementationJar(ctx) {
+ return exportImplementationClassesJar(ctx, j)
+ }
+
// Java boot libs are only provided in the SDK to provide access to their dex implementation
// jar for use by dexpreopting and boot jars package check. 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 {
+ func(ctx android.SdkMemberContext, osPrefix, name string) string {
+ if snapshotRequiresImplementationJar(ctx) {
+ return sdkSnapshotFilePathForJar(ctx, osPrefix, name)
+ }
+
// 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.
@@ -164,6 +182,9 @@ var (
android.SdkMemberTypeBase{
PropertyName: "java_systemserver_libs",
SupportsSdk: true,
+
+ // This was only added in Tiramisu.
+ SupportedBuildReleaseSpecification: "Tiramisu+",
},
func(ctx android.SdkMemberContext, j *Library) android.Path {
// Java systemserver libs are only provided in the SDK to provide access to their dex
@@ -172,7 +193,7 @@ var (
// file. Any attempt to use that file as a jar will cause a build error.
return ctx.SnapshotBuilder().EmptyFile()
},
- func(osPrefix, name string) string {
+ func(_ android.SdkMemberContext, 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.
@@ -646,7 +667,7 @@ const (
)
// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
-func sdkSnapshotFilePathForJar(osPrefix, name string) string {
+func sdkSnapshotFilePathForJar(_ android.SdkMemberContext, osPrefix, name string) string {
return sdkSnapshotFilePathForMember(osPrefix, name, jarFileSuffix)
}
@@ -663,7 +684,7 @@ type librarySdkMemberType struct {
// Function to compute the snapshot relative path to which the named library's
// jar should be copied.
- snapshotPathGetter func(osPrefix, name string) string
+ snapshotPathGetter func(ctx android.SdkMemberContext, osPrefix, name string) string
// True if only the jar should be copied to the snapshot, false if the jar plus any additional
// files like aidl files should also be copied.
@@ -721,7 +742,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte
exportedJar := p.JarToExport
if exportedJar != nil {
// Delegate the creation of the snapshot relative path to the member type.
- snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(p.OsPrefix(), ctx.Name())
+ snapshotRelativeJavaLibPath := memberType.snapshotPathGetter(ctx, p.OsPrefix(), ctx.Name())
// Copy the exported jar to the snapshot.
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
@@ -1187,7 +1208,7 @@ func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext,
exportedJar := p.JarToExport
if exportedJar != nil {
- snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
+ snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(ctx, p.OsPrefix(), ctx.Name())
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go
index fa61ea68c..79d2ee9f7 100644
--- a/java/systemserver_classpath_fragment.go
+++ b/java/systemserver_classpath_fragment.go
@@ -28,6 +28,9 @@ func init() {
SdkMemberTypeBase: android.SdkMemberTypeBase{
PropertyName: "systemserverclasspath_fragments",
SupportsSdk: true,
+
+ // This was only added in Tiramisu.
+ SupportedBuildReleaseSpecification: "Tiramisu+",
},
})
}
diff --git a/sdk/build_release.go b/sdk/build_release.go
index 4c2277e85..0494a28ee 100644
--- a/sdk/build_release.go
+++ b/sdk/build_release.go
@@ -24,18 +24,22 @@ import (
// 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.
+// The name of the release, is the same as the code for the dessert release, e.g. S, Tiramisu, etc.
type buildRelease struct {
- // The name of the release, e.g. S, T, etc.
+ // The name of the release, e.g. S, Tiramisu, etc.
name string
// The index of this structure within the buildReleases list.
ordinal int
}
+func (br *buildRelease) EarlierThan(other *buildRelease) bool {
+ return br.ordinal < other.ordinal
+}
+
// String returns the name of the build release.
-func (s *buildRelease) String() string {
- return s.name
+func (br *buildRelease) String() string {
+ return br.name
}
// buildReleaseSet represents a set of buildRelease objects.
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index a99fa1ff0..2cadd60f4 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -15,6 +15,7 @@
package sdk
import (
+ "fmt"
"testing"
"android/soong/android"
@@ -339,8 +340,8 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) {
android.FixtureAddFile("aidl", nil),
android.FixtureAddFile("resource.txt", nil),
).RunTestWithBp(t, `
- module_exports {
- name: "myexports",
+ sdk {
+ name: "mysdk",
java_boot_libs: ["myjavalib"],
}
@@ -360,7 +361,7 @@ func TestSnapshotWithJavaBootLibrary(t *testing.T) {
}
`)
- CheckSnapshot(t, result, "myexports", "",
+ CheckSnapshot(t, result, "mysdk", "",
checkUnversionedAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -377,7 +378,7 @@ java_import {
// This is auto-generated. DO NOT EDIT.
java_import {
- name: "myexports_myjavalib@current",
+ name: "mysdk_myjavalib@current",
sdk_member_name: "myjavalib",
visibility: ["//visibility:public"],
apex_available: ["//apex_available:platform"],
@@ -385,19 +386,73 @@ java_import {
permitted_packages: ["pkg.myjavalib"],
}
-module_exports_snapshot {
- name: "myexports@current",
+sdk_snapshot {
+ name: "mysdk@current",
visibility: ["//visibility:public"],
- java_boot_libs: ["myexports_myjavalib@current"],
+ java_boot_libs: ["mysdk_myjavalib@current"],
}
`),
checkAllCopyRules(`
-.intermediates/myexports/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar
+.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar
`),
)
}
+func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) {
+ runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) {
+ result := android.GroupFixturePreparers(
+ prepareForSdkTestWithJava,
+ android.FixtureMergeEnv(map[string]string{
+ "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease,
+ }),
+ ).RunTestWithBp(t, `
+ sdk {
+ name: "mysdk",
+ java_boot_libs: ["updatable-media"],
+ }
+
+ java_library {
+ name: "updatable-media",
+ srcs: ["Test.java"],
+ system_modules: "none",
+ sdk_version: "none",
+ compile_dex: true,
+ permitted_packages: ["pkg.media"],
+ apex_available: ["com.android.media"],
+ }
+ `)
+
+ CheckSnapshot(t, result, "mysdk", "",
+ checkUnversionedAndroidBpContents(fmt.Sprintf(`
+// This is auto-generated. DO NOT EDIT.
+
+java_import {
+ name: "updatable-media",
+ prefer: false,
+ visibility: ["//visibility:public"],
+ apex_available: ["com.android.media"],
+ jars: ["%s"],
+ permitted_packages: ["pkg.media"],
+}
+`, expectedJarPath)),
+ checkAllCopyRules(expectedCopyRule),
+ )
+ }
+
+ t.Run("updatable-media in S", func(t *testing.T) {
+ runTest(t, "S", "java/updatable-media.jar", `
+.intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar
+`)
+ })
+
+ t.Run("updatable-media in T", func(t *testing.T) {
+ runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", `
+.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar
+`)
+ })
+}
+
func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) {
result := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
diff --git a/sdk/systemserverclasspath_fragment_sdk_test.go b/sdk/systemserverclasspath_fragment_sdk_test.go
index 16e3e7fa9..819083d23 100644
--- a/sdk/systemserverclasspath_fragment_sdk_test.go
+++ b/sdk/systemserverclasspath_fragment_sdk_test.go
@@ -22,13 +22,16 @@ import (
"android/soong/java"
)
-func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
+func testSnapshotWithSystemServerClasspathFragment(t *testing.T, targetBuildRelease string, expectedUnversionedSdkSnapshot string, expectedVersionedSdkSnapshot string) {
result := android.GroupFixturePreparers(
prepareForSdkTestWithJava,
java.PrepareForTestWithJavaDefaultModules,
java.PrepareForTestWithJavaSdkLibraryFiles,
java.FixtureWithLastReleaseApis("mysdklibrary"),
dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"),
+ android.FixtureModifyEnv(func(env map[string]string) {
+ env["SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE"] = targetBuildRelease
+ }),
prepareForSdkTestWithApex,
android.FixtureWithRootAndroidBp(`
@@ -83,7 +86,58 @@ func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
).RunTest(t)
CheckSnapshot(t, result, "mysdk", "",
- checkUnversionedAndroidBpContents(`
+ checkUnversionedAndroidBpContents(expectedUnversionedSdkSnapshot),
+ checkVersionedAndroidBpContents(expectedVersionedSdkSnapshot),
+ )
+}
+
+func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
+ t.Run("target-s", func(t *testing.T) {
+ testSnapshotWithSystemServerClasspathFragment(t, "S", `
+// 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",
+ },
+}
+`, `
+// 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",
+ },
+}
+
+sdk_snapshot {
+ name: "mysdk@current",
+ visibility: ["//visibility:public"],
+ java_sdk_libs: ["mysdk_mysdklibrary@current"],
+}
+`)
+ })
+
+ t.Run("target-t", func(t *testing.T) {
+ testSnapshotWithSystemServerClasspathFragment(t, "Tiramisu", `
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
@@ -120,8 +174,7 @@ prebuilt_systemserverclasspath_fragment {
"mysdklibrary",
],
}
-`),
- checkVersionedAndroidBpContents(`
+`, `
// This is auto-generated. DO NOT EDIT.
java_sdk_library_import {
@@ -166,6 +219,6 @@ sdk_snapshot {
java_systemserver_libs: ["mysdk_mylib@current"],
systemserverclasspath_fragments: ["mysdk_mysystemserverclasspathfragment@current"],
}
-`),
- )
+`)
+ })
}
diff --git a/sdk/update.go b/sdk/update.go
index 5db604b7c..017887461 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -242,7 +242,7 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) {
// Finally, the member type slices are concatenated together to form a single slice. The order in
// which they are concatenated is the order in which the member types were registered in the
// android.SdkMemberTypesRegistry.
-func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, memberVariantDeps []sdkMemberVariantDep) []*sdkMember {
+func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, targetBuildRelease *buildRelease, memberVariantDeps []sdkMemberVariantDep) []*sdkMember {
byType := make(map[android.SdkMemberType][]*sdkMember)
byName := make(map[string]*sdkMember)
@@ -265,13 +265,39 @@ func (s *sdk) groupMemberVariantsByMemberThenType(ctx android.ModuleContext, mem
var members []*sdkMember
for _, memberListProperty := range s.memberTypeListProperties() {
- membersOfType := byType[memberListProperty.memberType]
+ memberType := memberListProperty.memberType
+
+ if !isMemberTypeSupportedByTargetBuildRelease(memberType, targetBuildRelease) {
+ continue
+ }
+
+ membersOfType := byType[memberType]
members = append(members, membersOfType...)
}
return members
}
+// isMemberTypeSupportedByTargetBuildRelease returns true if the member type is supported by the
+// target build release.
+func isMemberTypeSupportedByTargetBuildRelease(memberType android.SdkMemberType, targetBuildRelease *buildRelease) bool {
+ supportedByTargetBuildRelease := true
+ supportedBuildReleases := memberType.SupportedBuildReleases()
+ if supportedBuildReleases == "" {
+ supportedBuildReleases = "S+"
+ }
+
+ set, err := parseBuildReleaseSet(supportedBuildReleases)
+ if err != nil {
+ panic(fmt.Errorf("member type %s has invalid supported build releases %q: %s",
+ memberType.SdkPropertyName(), supportedBuildReleases, err))
+ }
+ if !set.contains(targetBuildRelease) {
+ supportedByTargetBuildRelease = false
+ }
+ return supportedByTargetBuildRelease
+}
+
func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware {
for _, v := range variants {
if v == newVariant {
@@ -416,7 +442,7 @@ be unnecessary as every module in the sdk already has its own licenses property.
// Group the variants for each member module together and then group the members of each member
// type together.
- members := s.groupMemberVariantsByMemberThenType(ctx, memberVariantDeps)
+ members := s.groupMemberVariantsByMemberThenType(ctx, targetBuildRelease, memberVariantDeps)
// Create the prebuilt modules for each of the member modules.
traits := s.gatherTraits()
@@ -795,6 +821,9 @@ func (s *sdk) addSnapshotPropertiesToPropertySet(builder *snapshotBuilder, prope
if memberListProperty.getter == nil {
continue
}
+ if !isMemberTypeSupportedByTargetBuildRelease(memberListProperty.memberType, builder.targetBuildRelease) {
+ continue
+ }
names := memberListProperty.getter(dynamicMemberTypeListProperties)
if len(names) > 0 {
propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false))
@@ -1902,6 +1931,12 @@ func (m *memberContext) RequiresTrait(trait android.SdkMemberTrait) bool {
return m.requiredTraits.Contains(trait)
}
+func (m *memberContext) IsTargetBuildBeforeTiramisu() bool {
+ return m.builder.targetBuildRelease.EarlierThan(buildReleaseT)
+}
+
+var _ android.SdkMemberContext = (*memberContext)(nil)
+
func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) {
memberType := member.memberType