Add CommonOS variant for sdk
Adds a CommonOS variant for sdk that depends on the os specific
variants and is used to generate a single sdk for multiple OsTypes,
e.g. host linux and android.
At the minute the member types only support a single OsType but the
basic mechanism for managing the CommonOS variant and collating the
variants across all of them is there.
The only visible effect of this change is that the location of the
generated snapshot is changed, it is no longer os specific and instead
is in the same location irrespective of which os it is built for.
A lot of tests needed to be changed to specify "common_os" as the
variant type instead of the specific os type. As that is the same across
all tests it is hard coded in CheckSnapshot method.
Bug: 153306490
Test: m nothing
Bug: 150451422
Merged-In: If36be39b06d6910453649f7c288c2d34f688b2f4
Change-Id: If36be39b06d6910453649f7c288c2d34f688b2f4
diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go
index ecb1da0..45b548c 100644
--- a/sdk/cc_sdk_test.go
+++ b/sdk/cc_sdk_test.go
@@ -17,6 +17,7 @@
import (
"testing"
+ "android/soong/android"
"android/soong/cc"
)
@@ -54,7 +55,7 @@
arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
var inputs []string
- buildParams := result.Module("mysdk", "android_common").BuildParamsForTests()
+ buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
for _, bp := range buildParams {
if bp.Input != nil {
inputs = append(inputs, bp.Input.String())
@@ -250,7 +251,7 @@
}
`)
- result.CheckSnapshot("mysdk", "android_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
@@ -287,7 +288,7 @@
}
`)
- result.CheckSnapshot("mysdk", "android_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -356,7 +357,7 @@
}
`)
- result.CheckSnapshot("mymodule_exports", "android_common", "",
+ result.CheckSnapshot("mymodule_exports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -422,7 +423,7 @@
}
`)
- result.CheckSnapshot("mysdk", "android_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -510,7 +511,7 @@
}
`)
- result.CheckSnapshot("mysdk", "linux_glibc_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -597,7 +598,7 @@
}
`)
- result.CheckSnapshot("myexports", "android_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -685,7 +686,7 @@
}
`)
- result.CheckSnapshot("myexports", "linux_glibc_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -784,7 +785,7 @@
}
`)
- result.CheckSnapshot("myexports", "linux_glibc_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -856,7 +857,7 @@
}
`)
- result.CheckSnapshot("mysdk", "android_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -909,7 +910,7 @@
}
`)
- result.CheckSnapshot("mysdk", "linux_glibc_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
diff --git a/sdk/exports_test.go b/sdk/exports_test.go
index b905d71..20e2521 100644
--- a/sdk/exports_test.go
+++ b/sdk/exports_test.go
@@ -42,7 +42,7 @@
"package/Android.bp": []byte(packageBp),
})
- result.CheckSnapshot("myexports", "android_common", "package",
+ result.CheckSnapshot("myexports", "package",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
diff --git a/sdk/java_sdk_test.go b/sdk/java_sdk_test.go
index 0737e5e..9046eec 100644
--- a/sdk/java_sdk_test.go
+++ b/sdk/java_sdk_test.go
@@ -141,7 +141,7 @@
}
`)
- result.CheckSnapshot("mysdk", "android_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -196,7 +196,7 @@
}
`)
- result.CheckSnapshot("mysdk", "linux_glibc_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -250,7 +250,7 @@
}
`)
- result.CheckSnapshot("myexports", "android_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -305,7 +305,7 @@
}
`)
- result.CheckSnapshot("myexports", "linux_glibc_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -356,7 +356,7 @@
}
`)
- result.CheckSnapshot("myexports", "android_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -409,7 +409,7 @@
}
`)
- result.CheckSnapshot("myexports", "linux_glibc_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -503,7 +503,7 @@
}
`)
- result.CheckSnapshot("myexports", "android_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -526,7 +526,7 @@
`),
checkAllCopyRules(""),
- checkMergeZip(".intermediates/myexports/android_common/tmp/java/myjavaapistubs_stubs_sources.zip"),
+ checkMergeZip(".intermediates/myexports/common_os/tmp/java/myjavaapistubs_stubs_sources.zip"),
)
}
@@ -552,7 +552,7 @@
}
`)
- result.CheckSnapshot("myexports", "linux_glibc_common", "",
+ result.CheckSnapshot("myexports", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -580,7 +580,7 @@
}
`),
checkAllCopyRules(""),
- checkMergeZip(".intermediates/myexports/linux_glibc_common/tmp/java/myjavaapistubs_stubs_sources.zip"),
+ checkMergeZip(".intermediates/myexports/common_os/tmp/java/myjavaapistubs_stubs_sources.zip"),
)
}
@@ -612,7 +612,7 @@
}
`)
- result.CheckSnapshot("mysdk", "android_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
@@ -702,7 +702,7 @@
}
`)
- result.CheckSnapshot("mysdk", "linux_glibc_common", "",
+ result.CheckSnapshot("mysdk", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
diff --git a/sdk/sdk.go b/sdk/sdk.go
index c194ac1..14e44bf 100644
--- a/sdk/sdk.go
+++ b/sdk/sdk.go
@@ -53,6 +53,13 @@
// The set of exported members.
exportedMembers map[string]struct{}
+ // Information about the OsType specific member variants associated with this variant.
+ //
+ // Set by OsType specific variants when their GenerateAndroidBuildActions is invoked
+ // and used by the CommonOS variant when its GenerateAndroidBuildActions is invoked, which
+ // is guaranteed to occur afterwards.
+ memberRefs []sdkMemberRef
+
properties sdkProperties
snapshotFile android.OptionalPath
@@ -201,7 +208,7 @@
// properties for the member type specific list properties.
s.dynamicMemberTypeListProperties = s.dynamicSdkMemberTypes.createMemberListProperties()
s.AddProperties(&s.properties, s.dynamicMemberTypeListProperties)
- android.InitAndroidMultiTargetsArchModule(s, android.HostAndDeviceSupported, android.MultilibCommon)
+ android.InitCommonOSAndroidMultiTargetsArchModule(s, android.HostAndDeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(s)
android.AddLoadHook(s, func(ctx android.LoadHookContext) {
type props struct {
@@ -252,10 +259,29 @@
}
func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- if !s.snapshot() {
+ if s.snapshot() {
// We don't need to create a snapshot out of sdk_snapshot.
// That doesn't make sense. We need a snapshot to create sdk_snapshot.
- s.snapshotFile = android.OptionalPathForPath(s.buildSnapshot(ctx))
+ return
+ }
+
+ // This method is guaranteed to be called on OsType specific variants before it is called
+ // on their corresponding CommonOS variant.
+ if !s.IsCommonOSVariant() {
+ // Collect the OsType specific members are add them to the OsType specific variant.
+ s.memberRefs = s.collectMembers(ctx)
+ } else {
+ // Get the OsType specific variants on which the CommonOS depends.
+ osSpecificVariants := android.GetOsSpecificVariantsOfCommonOSVariant(ctx)
+ var sdkVariants []*sdk
+ for _, m := range osSpecificVariants {
+ if sdkVariant, ok := m.(*sdk); ok {
+ sdkVariants = append(sdkVariants, sdkVariant)
+ }
+ }
+
+ // Generate the snapshot from the member info.
+ s.snapshotFile = android.OptionalPathForPath(s.buildSnapshot(ctx, sdkVariants))
}
}
@@ -320,7 +346,8 @@
// Step 1: create dependencies from an SDK module to its members.
func memberMutator(mctx android.BottomUpMutatorContext) {
if s, ok := mctx.Module().(*sdk); ok {
- if s.Enabled() {
+ // Add dependencies from enabled and non CommonOS variants to the sdk member variants.
+ if s.Enabled() && !s.IsCommonOSVariant() {
for _, memberListProperty := range s.memberListProperties() {
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
if len(names) > 0 {
diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go
index 53c2971..b13b90c 100644
--- a/sdk/sdk_test.go
+++ b/sdk/sdk_test.go
@@ -146,7 +146,7 @@
"package/Android.bp": []byte(packageBp),
})
- result.CheckSnapshot("mysdk", "android_common", "package",
+ result.CheckSnapshot("mysdk", "package",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
diff --git a/sdk/testing.go b/sdk/testing.go
index 7352c74..be882d4 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -246,9 +246,12 @@
// Takes a list of functions which check different facets of the snapshot build rules.
// Allows each test to customize what is checked without duplicating lots of code
// or proliferating check methods of different flavors.
-func (r *testSdkResult) CheckSnapshot(name string, variant string, dir string, checkers ...snapshotBuildInfoChecker) {
+func (r *testSdkResult) CheckSnapshot(name string, dir string, checkers ...snapshotBuildInfoChecker) {
r.t.Helper()
+ // The sdk CommonOS variant is always responsible for generating the snapshot.
+ variant := android.CommonOS.Name
+
sdk := r.Module(name, variant).(*sdk)
snapshotBuildInfo := r.getSdkSnapshotBuildInfo(sdk)
diff --git a/sdk/update.go b/sdk/update.go
index d211e80..087b8bc 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -104,18 +104,9 @@
// Collect all the members.
//
-// The members are first grouped by type and then grouped by name. The order of
-// the types is the order they are referenced in android.SdkMemberTypesRegistry.
-// The names are in the order in which the dependencies were added.
-//
-// Returns the members as well as the multilib setting to use.
-func (s *sdk) collectMembers(ctx android.ModuleContext) ([]*sdkMember, string) {
- byType := make(map[android.SdkMemberType][]*sdkMember)
- byName := make(map[string]*sdkMember)
-
- lib32 := false // True if any of the members have 32 bit version.
- lib64 := false // True if any of the members have 64 bit version.
-
+// Returns a list containing type (extracted from the dependency tag) and the variant.
+func (s *sdk) collectMembers(ctx android.ModuleContext) []sdkMemberRef {
+ var memberRefs []sdkMemberRef
ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
tag := ctx.OtherModuleDependencyTag(child)
if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok {
@@ -126,24 +117,7 @@
ctx.ModuleErrorf("module %q is not valid in property %s", ctx.OtherModuleName(child), memberType.SdkPropertyName())
}
- name := ctx.OtherModuleName(child)
- member := byName[name]
- if member == nil {
- member = &sdkMember{memberType: memberType, name: name}
- byName[name] = member
- byType[memberType] = append(byType[memberType], member)
- }
-
- multilib := child.Target().Arch.ArchType.Multilib
- if multilib == "lib32" {
- lib32 = true
- } else if multilib == "lib64" {
- lib64 = true
- }
-
- // Only append new variants to the list. This is needed because a member can be both
- // exported by the sdk and also be a transitive sdk member.
- member.variants = appendUniqueVariants(member.variants, child.(android.SdkAware))
+ memberRefs = append(memberRefs, sdkMemberRef{memberType, child.(android.SdkAware)})
// If the member type supports transitive sdk members then recurse down into
// its dependencies, otherwise exit traversal.
@@ -153,6 +127,47 @@
return false
})
+ return memberRefs
+}
+
+// Organize the members.
+//
+// The members are first grouped by type and then grouped by name. The order of
+// the types is the order they are referenced in android.SdkMemberTypesRegistry.
+// The names are in the order in which the dependencies were added.
+//
+// Returns the members as well as the multilib setting to use.
+func (s *sdk) organizeMembers(ctx android.ModuleContext, memberRefs []sdkMemberRef) ([]*sdkMember, string) {
+ byType := make(map[android.SdkMemberType][]*sdkMember)
+ byName := make(map[string]*sdkMember)
+
+ lib32 := false // True if any of the members have 32 bit version.
+ lib64 := false // True if any of the members have 64 bit version.
+
+ for _, memberRef := range memberRefs {
+ memberType := memberRef.memberType
+ variant := memberRef.variant
+
+ name := ctx.OtherModuleName(variant)
+ member := byName[name]
+ if member == nil {
+ member = &sdkMember{memberType: memberType, name: name}
+ byName[name] = member
+ byType[memberType] = append(byType[memberType], member)
+ }
+
+ multilib := variant.Target().Arch.ArchType.Multilib
+ if multilib == "lib32" {
+ lib32 = true
+ } else if multilib == "lib64" {
+ lib64 = true
+ }
+
+ // Only append new variants to the list. This is needed because a member can be both
+ // exported by the sdk and also be a transitive sdk member.
+ member.variants = appendUniqueVariants(member.variants, variant)
+ }
+
var members []*sdkMember
for _, memberListProperty := range s.memberListProperties() {
membersOfType := byType[memberListProperty.memberType]
@@ -207,7 +222,13 @@
// buildSnapshot is the main function in this source file. It creates rules to copy
// the contents (header files, stub libraries, etc) into the zip file.
-func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
+func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) android.OutputPath {
+
+ var memberRefs []sdkMemberRef
+ for _, sdkVariant := range sdkVariants {
+ memberRefs = append(memberRefs, sdkVariant.memberRefs...)
+ }
+
snapshotDir := android.PathForModuleOut(ctx, "snapshot")
bp := newGeneratedFile(ctx, "snapshot", "Android.bp")
@@ -228,7 +249,7 @@
}
s.builderForTests = builder
- members, multilib := s.collectMembers(ctx)
+ members, multilib := s.organizeMembers(ctx, memberRefs)
for _, member := range members {
member.memberType.BuildSnapshot(ctx, builder, member)
}
@@ -592,6 +613,11 @@
return references
}
+type sdkMemberRef struct {
+ memberType android.SdkMemberType
+ variant android.SdkAware
+}
+
var _ android.SdkMember = (*sdkMember)(nil)
type sdkMember struct {