From e44358fa8f9ad114e70942708958538101fc20a6 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 26 Nov 2019 18:04:12 +0000 Subject: [PATCH] Add support for host sdk Adds HostSupported() method to ModuleBase for use by sdk. Adds host_supported/device_supported to all prebuilt modules and the sdk snapshot (where necessary). Adds TestHostSnapshot to verify the behavior is correct. Bug: 143678475 Test: m nothing Change-Id: I8b4d097e46d5804f62cb8f651a83069299a3e639 --- android/module.go | 7 ++ sdk/sdk_test.go | 192 ++++++++++++++++++++++++++++++++++++++++++++++ sdk/update.go | 13 ++++ 3 files changed, 212 insertions(+) diff --git a/android/module.go b/android/module.go index 2ae296197..b4f8f1ae0 100644 --- a/android/module.go +++ b/android/module.go @@ -778,6 +778,13 @@ func (m *ModuleBase) DeviceSupported() bool { *m.hostAndDeviceProperties.Device_supported) } +func (m *ModuleBase) HostSupported() bool { + return m.commonProperties.HostOrDeviceSupported == HostSupported || + m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && + (m.hostAndDeviceProperties.Host_supported != nil && + *m.hostAndDeviceProperties.Host_supported) +} + func (m *ModuleBase) Platform() bool { return !m.DeviceSpecific() && !m.SocSpecific() && !m.ProductSpecific() && !m.SystemExtSpecific() } diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 8def1d850..6b92d2761 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -596,6 +596,198 @@ sdk_snapshot { } } +func TestHostSnapshot(t *testing.T) { + ctx, config := testSdk(t, ` + sdk { + name: "mysdk", + device_supported: false, + host_supported: true, + java_libs: ["myjavalib"], + native_shared_libs: ["mynativelib"], + stubs_sources: ["myjavaapistubs"], + } + + java_library { + name: "myjavalib", + device_supported: false, + host_supported: true, + srcs: ["Test.java"], + aidl: { + export_include_dirs: ["aidl"], + }, + system_modules: "none", + sdk_version: "none", + compile_dex: true, + } + + cc_library_shared { + name: "mynativelib", + device_supported: false, + host_supported: true, + srcs: [ + "Test.cpp", + "aidl/foo/bar/Test.aidl", + ], + export_include_dirs: ["include"], + aidl: { + export_aidl_headers: true, + }, + system_shared_libs: [], + stl: "none", + } + + droidstubs { + name: "myjavaapistubs", + device_supported: false, + host_supported: true, + srcs: ["foo/bar/Foo.java"], + system_modules: "none", + sdk_version: "none", + } + `) + + sdk := ctx.ModuleForTests("mysdk", "linux_glibc_common").Module().(*sdk) + + checkSnapshotAndroidBpContents(t, sdk, `// This is auto-generated. DO NOT EDIT. + +java_import { + name: "mysdk_myjavalib@current", + sdk_member_name: "myjavalib", + device_supported: false, + host_supported: true, + jars: ["java/myjavalib.jar"], +} + +java_import { + name: "myjavalib", + prefer: false, + device_supported: false, + host_supported: true, + jars: ["java/myjavalib.jar"], +} + +prebuilt_stubs_sources { + name: "mysdk_myjavaapistubs@current", + sdk_member_name: "myjavaapistubs", + device_supported: false, + host_supported: true, + srcs: ["java/myjavaapistubs_stubs_sources"], +} + +prebuilt_stubs_sources { + name: "myjavaapistubs", + prefer: false, + device_supported: false, + host_supported: true, + srcs: ["java/myjavaapistubs_stubs_sources"], +} + +cc_prebuilt_library_shared { + name: "mysdk_mynativelib@current", + sdk_member_name: "mynativelib", + device_supported: false, + host_supported: true, + arch: { + x86_64: { + srcs: ["x86_64/lib/mynativelib.so"], + export_include_dirs: [ + "x86_64/include/include", + "x86_64/include_gen/mynativelib", + ], + }, + x86: { + srcs: ["x86/lib/mynativelib.so"], + export_include_dirs: [ + "x86/include/include", + "x86/include_gen/mynativelib", + ], + }, + }, + stl: "none", + system_shared_libs: [], +} + +cc_prebuilt_library_shared { + name: "mynativelib", + prefer: false, + device_supported: false, + host_supported: true, + arch: { + x86_64: { + srcs: ["x86_64/lib/mynativelib.so"], + export_include_dirs: [ + "x86_64/include/include", + "x86_64/include_gen/mynativelib", + ], + }, + x86: { + srcs: ["x86/lib/mynativelib.so"], + export_include_dirs: [ + "x86/include/include", + "x86/include_gen/mynativelib", + ], + }, + }, + stl: "none", + system_shared_libs: [], +} + +sdk_snapshot { + name: "mysdk@current", + device_supported: false, + host_supported: true, + java_libs: ["mysdk_myjavalib@current"], + stubs_sources: ["mysdk_myjavaapistubs@current"], + native_shared_libs: ["mysdk_mynativelib@current"], +} + +`) + + var copySrcs []string + var copyDests []string + buildParams := sdk.BuildParamsForTests() + var zipBp android.BuildParams + for _, bp := range buildParams { + ruleString := bp.Rule.String() + if ruleString == "android/soong/android.Cp" { + copySrcs = append(copySrcs, bp.Input.String()) + copyDests = append(copyDests, bp.Output.Rel()) // rooted at the snapshot root + } else if ruleString == ":m.mysdk_linux_glibc_common.snapshot" { + zipBp = bp + } + } + + buildDir := config.BuildDir() + ensureListContains(t, copySrcs, "aidl/foo/bar/Test.aidl") + ensureListContains(t, copySrcs, "include/Test.h") + ensureListContains(t, copySrcs, filepath.Join(buildDir, ".intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h")) + ensureListContains(t, copySrcs, filepath.Join(buildDir, ".intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h")) + ensureListContains(t, copySrcs, filepath.Join(buildDir, ".intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h")) + ensureListContains(t, copySrcs, filepath.Join(buildDir, ".intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar")) + ensureListContains(t, copySrcs, filepath.Join(buildDir, ".intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so")) + + ensureListContains(t, copyDests, "aidl/aidl/foo/bar/Test.aidl") + ensureListContains(t, copyDests, "x86_64/include/include/Test.h") + ensureListContains(t, copyDests, "x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h") + ensureListContains(t, copyDests, "x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h") + ensureListContains(t, copyDests, "x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h") + ensureListContains(t, copyDests, "java/myjavalib.jar") + ensureListContains(t, copyDests, "x86_64/lib/mynativelib.so") + + // Ensure that the droidstubs .srcjar as repackaged into a temporary zip file + // and then merged together with the intermediate snapshot zip. + snapshotCreationInputs := zipBp.Implicits.Strings() + ensureListContains(t, snapshotCreationInputs, + filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/tmp/java/myjavaapistubs_stubs_sources.zip")) + ensureListContains(t, snapshotCreationInputs, + filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/mysdk-current.unmerged.zip")) + actual := zipBp.Output.String() + expected := filepath.Join(buildDir, ".intermediates/mysdk/linux_glibc_common/mysdk-current.zip") + if actual != expected { + t.Errorf("Expected snapshot output to be %q but was %q", expected, actual) + } +} + func checkSnapshotAndroidBpContents(t *testing.T, s *sdk, expectedContents string) { t.Helper() androidBpContents := strings.NewReplacer("\\n", "\n").Replace(s.GetAndroidBpContentsForTests()) diff --git a/sdk/update.go b/sdk/update.go index 3bd63369d..8159d3b4d 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -250,6 +250,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { builder := &snapshotBuilder{ ctx: ctx, + sdk: s, version: "current", snapshotDir: snapshotDir.OutputPath, filesToZip: []android.Path{bp.path}, @@ -293,6 +294,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath { snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version snapshotModule := bpFile.newModule("sdk_snapshot") snapshotModule.AddProperty("name", snapshotName) + addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule) if len(s.properties.Java_libs) > 0 { snapshotModule.AddProperty("java_libs", builder.versionedSdkMemberNames(s.properties.Java_libs)) } @@ -505,6 +507,7 @@ func (info *nativeLibInfo) generatePrebuiltLibrary(ctx android.ModuleContext, bu type snapshotBuilder struct { ctx android.ModuleContext + sdk *sdk version string snapshotDir android.OutputPath bpFile *bpFile @@ -551,12 +554,22 @@ func (s *snapshotBuilder) AddPrebuiltModule(name string, moduleType string) andr m := s.bpFile.newModule(moduleType) m.AddProperty("name", name) + addHostDeviceSupportedProperties(&s.sdk.ModuleBase, m) s.prebuiltModules[name] = m s.prebuiltOrder = append(s.prebuiltOrder, m) return m } +func addHostDeviceSupportedProperties(module *android.ModuleBase, bpModule *bpModule) { + if !module.DeviceSupported() { + bpModule.AddProperty("device_supported", false) + } + if module.HostSupported() { + bpModule.AddProperty("host_supported", true) + } +} + // Get a versioned name appropriate for the SDK snapshot version being taken. func (s *snapshotBuilder) versionedSdkMemberName(unversionedName string) string { return versionedSdkMemberName(s.ctx, unversionedName, s.version)