diff --git a/android/sdk.go b/android/sdk.go index 28f5cd585..9ea7ff49c 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -327,6 +327,12 @@ type SdkMemberType interface { // SdkAware and be added with an SdkMemberTypeDependencyTag tag. HasTransitiveSdkMembers() bool + // Return true if prebuilt host artifacts may be specific to the host OS. Only + // applicable to modules where HostSupported() is true. If this is true, + // snapshots will list each host OS variant explicitly and disable all other + // host OS'es. + IsHostOsDependent() bool + // Add dependencies from the SDK module to all the module variants the member // type contributes to the SDK. `names` is the list of module names given in // the member type property (as returned by SdkPropertyName()) in the SDK @@ -389,6 +395,7 @@ type SdkMemberTypeBase struct { PropertyName string SupportsSdk bool TransitiveSdkMembers bool + HostOsDependent bool } func (b *SdkMemberTypeBase) SdkPropertyName() string { @@ -403,6 +410,10 @@ func (b *SdkMemberTypeBase) HasTransitiveSdkMembers() bool { return b.TransitiveSdkMembers } +func (b *SdkMemberTypeBase) IsHostOsDependent() bool { + return b.HostOsDependent +} + // Encapsulates the information about registered SdkMemberTypes. type SdkMemberTypesRegistry struct { // The list of types sorted by property name. diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go index 51d8b4e97..337de55b3 100644 --- a/cc/binary_sdk_member.go +++ b/cc/binary_sdk_member.go @@ -29,7 +29,8 @@ func init() { var ccBinarySdkMemberType = &binarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_binaries", + PropertyName: "native_binaries", + HostOsDependent: true, }, } diff --git a/cc/library_headers.go b/cc/library_headers.go index b7ab3907c..8b3dbeb8b 100644 --- a/cc/library_headers.go +++ b/cc/library_headers.go @@ -25,8 +25,9 @@ func init() { var headersLibrarySdkMemberType = &librarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_header_libs", - SupportsSdk: true, + PropertyName: "native_header_libs", + SupportsSdk: true, + HostOsDependent: true, }, prebuiltModuleType: "cc_prebuilt_library_headers", noOutputFiles: true, diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index 4b9eb302c..cff00b668 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -27,8 +27,9 @@ import ( var sharedLibrarySdkMemberType = &librarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_shared_libs", - SupportsSdk: true, + PropertyName: "native_shared_libs", + SupportsSdk: true, + HostOsDependent: true, }, prebuiltModuleType: "cc_prebuilt_library_shared", linkTypes: []string{"shared"}, @@ -36,8 +37,9 @@ var sharedLibrarySdkMemberType = &librarySdkMemberType{ var staticLibrarySdkMemberType = &librarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_static_libs", - SupportsSdk: true, + PropertyName: "native_static_libs", + SupportsSdk: true, + HostOsDependent: true, }, prebuiltModuleType: "cc_prebuilt_library_static", linkTypes: []string{"static"}, @@ -45,8 +47,9 @@ var staticLibrarySdkMemberType = &librarySdkMemberType{ var staticAndSharedLibrarySdkMemberType = &librarySdkMemberType{ SdkMemberTypeBase: android.SdkMemberTypeBase{ - PropertyName: "native_libs", - SupportsSdk: true, + PropertyName: "native_libs", + SupportsSdk: true, + HostOsDependent: true, }, prebuiltModuleType: "cc_prebuilt_library", linkTypes: []string{"static", "shared"}, diff --git a/sdk/cc_sdk_test.go b/sdk/cc_sdk_test.go index 17afdb804..9501d88d7 100644 --- a/sdk/cc_sdk_test.go +++ b/sdk/cc_sdk_test.go @@ -39,6 +39,20 @@ func testSdkWithCc(t *testing.T, bp string) *testSdkResult { // Contains tests for SDK members provided by the cc package. +func TestSingleDeviceOsAssumption(t *testing.T) { + // Mock a module with DeviceSupported() == true. + s := &sdk{} + android.InitAndroidArchModule(s, android.DeviceSupported, android.MultilibCommon) + + osTypes := s.getPossibleOsTypes() + if len(osTypes) != 1 { + // The snapshot generation assumes there is a single device OS. If more are + // added it might need to disable them by default, like it does for host + // OS'es. + t.Errorf("expected a single device OS, got %v", osTypes) + } +} + func TestSdkIsCompileMultilibBoth(t *testing.T) { result := testSdkWithCc(t, ` sdk { @@ -99,9 +113,15 @@ cc_prebuilt_library_shared { stl: "none", compile_multilib: "64", target: { + host: { + enabled: false, + }, android_arm64: { srcs: ["android/arm64/lib/sdkmember.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/sdkmember.so"], }, @@ -115,9 +135,15 @@ cc_prebuilt_library_shared { stl: "none", compile_multilib: "64", target: { + host: { + enabled: false, + }, android_arm64: { srcs: ["android/arm64/lib/sdkmember.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/sdkmember.so"], }, @@ -129,6 +155,14 @@ sdk_snapshot { host_supported: true, native_shared_libs: ["mysdk_sdkmember@current"], compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `), checkAllCopyRules(` @@ -573,7 +607,11 @@ cc_prebuilt_binary { installable: false, stl: "none", target: { + host: { + enabled: false, + }, linux_glibc: { + enabled: true, compile_multilib: "both", }, linux_glibc_x86_64: { @@ -583,6 +621,7 @@ cc_prebuilt_binary { srcs: ["linux_glibc/x86/bin/mynativebinary"], }, windows: { + enabled: true, compile_multilib: "64", }, windows_x86_64: { @@ -598,7 +637,11 @@ cc_prebuilt_binary { host_supported: true, stl: "none", target: { + host: { + enabled: false, + }, linux_glibc: { + enabled: true, compile_multilib: "both", }, linux_glibc_x86_64: { @@ -608,6 +651,7 @@ cc_prebuilt_binary { srcs: ["linux_glibc/x86/bin/mynativebinary"], }, windows: { + enabled: true, compile_multilib: "64", }, windows_x86_64: { @@ -622,7 +666,14 @@ module_exports_snapshot { host_supported: true, native_binaries: ["myexports_mynativebinary@current"], target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, windows: { + enabled: true, compile_multilib: "64", }, }, @@ -636,6 +687,162 @@ module_exports_snapshot { ) } +func TestSnapshotWithSingleHostOsType(t *testing.T) { + ctx, config := testSdkContext(` + cc_defaults { + name: "mydefaults", + device_supported: false, + host_supported: true, + compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_bionic: { + enabled: true, + }, + }, + } + + module_exports { + name: "myexports", + defaults: ["mydefaults"], + native_shared_libs: ["mynativelib"], + native_binaries: ["mynativebinary"], + compile_multilib: "64", // The built-in default in sdk.go overrides mydefaults. + } + + cc_library { + name: "mynativelib", + defaults: ["mydefaults"], + srcs: [ + "Test.cpp", + ], + stl: "none", + } + + cc_binary { + name: "mynativebinary", + defaults: ["mydefaults"], + srcs: [ + "Test.cpp", + ], + stl: "none", + } + `, ccTestFs, []android.OsType{android.LinuxBionic}) + + result := runTests(t, ctx, config) + + result.CheckSnapshot("myexports", "", + checkAndroidBpContents(` +// This is auto-generated. DO NOT EDIT. + +cc_prebuilt_binary { + name: "myexports_mynativebinary@current", + sdk_member_name: "mynativebinary", + device_supported: false, + host_supported: true, + installable: false, + stl: "none", + compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_bionic: { + enabled: true, + }, + linux_bionic_x86_64: { + srcs: ["x86_64/bin/mynativebinary"], + }, + }, +} + +cc_prebuilt_binary { + name: "mynativebinary", + prefer: false, + device_supported: false, + host_supported: true, + stl: "none", + compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_bionic: { + enabled: true, + }, + linux_bionic_x86_64: { + srcs: ["x86_64/bin/mynativebinary"], + }, + }, +} + +cc_prebuilt_library_shared { + name: "myexports_mynativelib@current", + sdk_member_name: "mynativelib", + device_supported: false, + host_supported: true, + installable: false, + stl: "none", + compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_bionic: { + enabled: true, + }, + linux_bionic_x86_64: { + srcs: ["x86_64/lib/mynativelib.so"], + }, + }, +} + +cc_prebuilt_library_shared { + name: "mynativelib", + prefer: false, + device_supported: false, + host_supported: true, + stl: "none", + compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_bionic: { + enabled: true, + }, + linux_bionic_x86_64: { + srcs: ["x86_64/lib/mynativelib.so"], + }, + }, +} + +module_exports_snapshot { + name: "myexports@current", + device_supported: false, + host_supported: true, + native_binaries: ["myexports_mynativebinary@current"], + native_shared_libs: ["myexports_mynativelib@current"], + compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_bionic: { + enabled: true, + }, + }, +} +`), + checkAllCopyRules(` +.intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary +.intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so +`), + ) +} + // Test that we support the necessary flags for the linker binary, which is // special in several ways. func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) { @@ -674,11 +881,17 @@ cc_prebuilt_binary { compile_multilib: "both", static_executable: true, nocrt: true, - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/bin/linker"], }, - x86: { + linux_glibc_x86: { srcs: ["x86/bin/linker"], }, }, @@ -693,11 +906,17 @@ cc_prebuilt_binary { compile_multilib: "both", static_executable: true, nocrt: true, - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/bin/linker"], }, - x86: { + linux_glibc_x86: { srcs: ["x86/bin/linker"], }, }, @@ -708,6 +927,14 @@ module_exports_snapshot { device_supported: false, host_supported: true, native_binaries: ["mymodule_exports_linker@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `), checkAllCopyRules(` @@ -1034,12 +1261,18 @@ cc_prebuilt_library_shared { stl: "none", compile_multilib: "both", export_include_dirs: ["include/include"], - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/lib/mynativelib.so"], export_include_dirs: ["x86_64/include_gen/mynativelib"], }, - x86: { + linux_glibc_x86: { srcs: ["x86/lib/mynativelib.so"], export_include_dirs: ["x86/include_gen/mynativelib"], }, @@ -1055,12 +1288,18 @@ cc_prebuilt_library_shared { stl: "none", compile_multilib: "both", export_include_dirs: ["include/include"], - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/lib/mynativelib.so"], export_include_dirs: ["x86_64/include_gen/mynativelib"], }, - x86: { + linux_glibc_x86: { srcs: ["x86/lib/mynativelib.so"], export_include_dirs: ["x86/include_gen/mynativelib"], }, @@ -1072,6 +1311,14 @@ sdk_snapshot { device_supported: false, host_supported: true, native_shared_libs: ["mysdk_mynativelib@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `), checkAllCopyRules(` @@ -1130,7 +1377,11 @@ cc_prebuilt_library_shared { installable: false, stl: "none", target: { + host: { + enabled: false, + }, linux_glibc: { + enabled: true, compile_multilib: "both", }, linux_glibc_x86_64: { @@ -1140,6 +1391,7 @@ cc_prebuilt_library_shared { srcs: ["linux_glibc/x86/lib/mynativelib.so"], }, windows: { + enabled: true, compile_multilib: "64", }, windows_x86_64: { @@ -1155,7 +1407,11 @@ cc_prebuilt_library_shared { host_supported: true, stl: "none", target: { + host: { + enabled: false, + }, linux_glibc: { + enabled: true, compile_multilib: "both", }, linux_glibc_x86_64: { @@ -1165,6 +1421,7 @@ cc_prebuilt_library_shared { srcs: ["linux_glibc/x86/lib/mynativelib.so"], }, windows: { + enabled: true, compile_multilib: "64", }, windows_x86_64: { @@ -1179,7 +1436,14 @@ sdk_snapshot { host_supported: true, native_shared_libs: ["mysdk_mynativelib@current"], target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, windows: { + enabled: true, compile_multilib: "64", }, }, @@ -1312,12 +1576,18 @@ cc_prebuilt_library_static { stl: "none", compile_multilib: "both", export_include_dirs: ["include/include"], - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/lib/mynativelib.a"], export_include_dirs: ["x86_64/include_gen/mynativelib"], }, - x86: { + linux_glibc_x86: { srcs: ["x86/lib/mynativelib.a"], export_include_dirs: ["x86/include_gen/mynativelib"], }, @@ -1332,12 +1602,18 @@ cc_prebuilt_library_static { stl: "none", compile_multilib: "both", export_include_dirs: ["include/include"], - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/lib/mynativelib.a"], export_include_dirs: ["x86_64/include_gen/mynativelib"], }, - x86: { + linux_glibc_x86: { srcs: ["x86/lib/mynativelib.a"], export_include_dirs: ["x86/include_gen/mynativelib"], }, @@ -1349,6 +1625,14 @@ module_exports_snapshot { device_supported: false, host_supported: true, native_static_libs: ["myexports_mynativelib@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `), checkAllCopyRules(` @@ -1496,8 +1780,14 @@ cc_prebuilt_library_static { stl: "none", compile_multilib: "64", export_include_dirs: ["include/include"], - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/lib/mynativelib.a"], export_include_dirs: ["x86_64/include_gen/mynativelib"], }, @@ -1512,8 +1802,14 @@ cc_prebuilt_library_static { stl: "none", compile_multilib: "64", export_include_dirs: ["include/include"], - arch: { - x86_64: { + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + linux_glibc_x86_64: { srcs: ["x86_64/lib/mynativelib.a"], export_include_dirs: ["x86_64/include_gen/mynativelib"], }, @@ -1526,6 +1822,14 @@ module_exports_snapshot { host_supported: true, native_static_libs: ["myexports_mynativelib@current"], compile_multilib: "64", + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, }`), checkAllCopyRules(` include/Test.h -> include/include/Test.h @@ -1612,6 +1916,14 @@ cc_prebuilt_library_headers { stl: "none", compile_multilib: "both", export_include_dirs: ["include/include"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } cc_prebuilt_library_headers { @@ -1622,6 +1934,14 @@ cc_prebuilt_library_headers { stl: "none", compile_multilib: "both", export_include_dirs: ["include/include"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } sdk_snapshot { @@ -1629,6 +1949,14 @@ sdk_snapshot { device_supported: false, host_supported: true, native_header_libs: ["mysdk_mynativeheaders@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `), checkAllCopyRules(` @@ -1673,10 +2001,14 @@ cc_prebuilt_library_headers { compile_multilib: "both", export_system_include_dirs: ["common_os/include/include"], target: { + host: { + enabled: false, + }, android: { export_include_dirs: ["android/include/include-android"], }, linux_glibc: { + enabled: true, export_include_dirs: ["linux_glibc/include/include-host"], }, }, @@ -1690,10 +2022,14 @@ cc_prebuilt_library_headers { compile_multilib: "both", export_system_include_dirs: ["common_os/include/include"], target: { + host: { + enabled: false, + }, android: { export_include_dirs: ["android/include/include-android"], }, linux_glibc: { + enabled: true, export_include_dirs: ["linux_glibc/include/include-host"], }, }, @@ -1703,6 +2039,14 @@ sdk_snapshot { name: "mysdk@current", host_supported: true, native_header_libs: ["mysdk_mynativeheaders@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `), checkAllCopyRules(` @@ -1870,6 +2214,9 @@ cc_prebuilt_library_shared { installable: false, compile_multilib: "both", target: { + host: { + enabled: false, + }, android: { system_shared_libs: [], }, @@ -1879,6 +2226,9 @@ cc_prebuilt_library_shared { android_arm: { srcs: ["android/arm/lib/sslvariants.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/sslvariants.so"], }, @@ -1894,6 +2244,9 @@ cc_prebuilt_library_shared { host_supported: true, compile_multilib: "both", target: { + host: { + enabled: false, + }, android: { system_shared_libs: [], }, @@ -1903,6 +2256,9 @@ cc_prebuilt_library_shared { android_arm: { srcs: ["android/arm/lib/sslvariants.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/sslvariants.so"], }, @@ -1916,6 +2272,14 @@ sdk_snapshot { name: "mysdk@current", host_supported: true, native_shared_libs: ["mysdk_sslvariants@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `)) } @@ -2025,12 +2389,18 @@ cc_prebuilt_library_shared { versions: ["3"], }, target: { + host: { + enabled: false, + }, android_arm64: { srcs: ["android/arm64/lib/stubslib.so"], }, android_arm: { srcs: ["android/arm/lib/stubslib.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/stubslib.so"], }, @@ -2049,12 +2419,18 @@ cc_prebuilt_library_shared { versions: ["3"], }, target: { + host: { + enabled: false, + }, android_arm64: { srcs: ["android/arm64/lib/stubslib.so"], }, android_arm: { srcs: ["android/arm/lib/stubslib.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/stubslib.so"], }, @@ -2068,6 +2444,14 @@ sdk_snapshot { name: "mysdk@current", host_supported: true, native_shared_libs: ["mysdk_stubslib@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `)) } @@ -2099,12 +2483,18 @@ cc_prebuilt_library_shared { unique_host_soname: true, compile_multilib: "both", target: { + host: { + enabled: false, + }, android_arm64: { srcs: ["android/arm64/lib/mylib.so"], }, android_arm: { srcs: ["android/arm/lib/mylib.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/mylib-host.so"], }, @@ -2121,12 +2511,18 @@ cc_prebuilt_library_shared { unique_host_soname: true, compile_multilib: "both", target: { + host: { + enabled: false, + }, android_arm64: { srcs: ["android/arm64/lib/mylib.so"], }, android_arm: { srcs: ["android/arm/lib/mylib.so"], }, + linux_glibc: { + enabled: true, + }, linux_glibc_x86_64: { srcs: ["linux_glibc/x86_64/lib/mylib-host.so"], }, @@ -2140,6 +2536,14 @@ sdk_snapshot { name: "mysdk@current", host_supported: true, native_shared_libs: ["mysdk_mylib@current"], + target: { + host: { + enabled: false, + }, + linux_glibc: { + enabled: true, + }, + }, } `), checkAllCopyRules(` diff --git a/sdk/update.go b/sdk/update.go index 25d50d217..936696a01 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -262,7 +262,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro memberCtx := &memberContext{ctx, builder, memberType, member.name} prebuiltModule := memberType.AddPrebuiltModule(memberCtx, member) - s.createMemberSnapshot(memberCtx, member, prebuiltModule) + s.createMemberSnapshot(memberCtx, member, prebuiltModule.(*bpModule)) } // Create a transformer that will transform an unversioned module into a versioned module. @@ -345,12 +345,37 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro snapshotModule.AddProperty("compile_multilib", commonVariantProperties.Compile_multilib) } - // Iterate over the os types in a fixed order. targetPropertySet := snapshotModule.AddPropertySet("target") + + // If host is supported and any member is host OS dependent then disable host + // by default, so that we can enable each host OS variant explicitly. This + // avoids problems with implicitly enabled OS variants when the snapshot is + // used, which might be different from this run (e.g. different build OS). + hasHostOsDependentMember := false + if s.HostSupported() { + for _, memberRef := range memberRefs { + if memberRef.memberType.IsHostOsDependent() { + hasHostOsDependentMember = true + break + } + } + if hasHostOsDependentMember { + hostPropertySet := targetPropertySet.AddPropertySet("host") + hostPropertySet.AddProperty("enabled", false) + } + } + + // Iterate over the os types in a fixed order. for _, osType := range s.getPossibleOsTypes() { if sdkVariant, ok := osTypeToMemberProperties[osType]; ok { osPropertySet := targetPropertySet.AddPropertySet(sdkVariant.Target().Os.Name) + // Enable the variant explicitly when we've disabled it by default on host. + if hasHostOsDependentMember && + (osType.Class == android.Host || osType.Class == android.HostCross) { + osPropertySet.AddProperty("enabled", true) + } + variantProps := variantToProperties[sdkVariant] if variantProps.Compile_multilib != "" && variantProps.Compile_multilib != "both" { osPropertySet.AddProperty("compile_multilib", variantProps.Compile_multilib) @@ -993,9 +1018,12 @@ func (osInfo *osTypeSpecificInfo) addToPropertySet(ctx *memberContext, bpModule var osPropertySet android.BpPropertySet var archPropertySet android.BpPropertySet var archOsPrefix string - if osInfo.Properties.Base().Os_count == 1 { - // There is only one os type present in the variants so don't bother - // with adding target specific properties. + if osInfo.Properties.Base().Os_count == 1 && + (osInfo.osType.Class == android.Device || !ctx.memberType.IsHostOsDependent()) { + // There is only one OS type present in the variants and it shouldn't have a + // variant-specific target. The latter is the case if it's either for device + // where there is only one OS (android), or for host and the member type + // isn't host OS dependent. // Create a structure that looks like: // module_type { @@ -1032,6 +1060,12 @@ func (osInfo *osTypeSpecificInfo) addToPropertySet(ctx *memberContext, bpModule osPropertySet = targetPropertySet.AddPropertySet(osType.Name) archPropertySet = targetPropertySet + // Enable the variant explicitly when we've disabled it by default on host. + if ctx.memberType.IsHostOsDependent() && + (osType.Class == android.Host || osType.Class == android.HostCross) { + osPropertySet.AddProperty("enabled", true) + } + // Arch specific properties need to be added to an os and arch specific // section prefixed with _. archOsPrefix = osType.Name + "_" @@ -1202,7 +1236,7 @@ func (m *memberContext) Name() string { return m.name } -func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule android.BpModule) { +func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) { memberType := member.memberType @@ -1256,6 +1290,18 @@ func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModu // added. targetPropertySet := bpModule.AddPropertySet("target") + // If the member is host OS dependent and has host_supported then disable by + // default and enable each host OS variant explicitly. This avoids problems + // with implicitly enabled OS variants when the snapshot is used, which might + // be different from this run (e.g. different build OS). + if ctx.memberType.IsHostOsDependent() { + hostSupported := bpModule.getValue("host_supported") == true // Missing means false. + if hostSupported { + hostPropertySet := targetPropertySet.AddPropertySet("host") + hostPropertySet.AddProperty("enabled", false) + } + } + // Iterate over the os types in a fixed order. for _, osType := range s.getPossibleOsTypes() { osInfo := osTypeToInfo[osType]