Disable cc_cmake_snapshot outside of Linux
Test: cd build/soong/cc && go test
Bug: 339782737
Change-Id: Ide6693123c741a39d37164a1a39841be1bd84862
diff --git a/cc/cmake_snapshot.go b/cc/cmake_snapshot.go
index 3ac7db1..0635a29 100644
--- a/cc/cmake_snapshot.go
+++ b/cc/cmake_snapshot.go
@@ -494,13 +494,30 @@
return nil
}
+func cmakeSnapshotLoadHook(ctx android.LoadHookContext) {
+ props := struct {
+ Target struct {
+ Darwin struct {
+ Enabled *bool
+ }
+ Windows struct {
+ Enabled *bool
+ }
+ }
+ }{}
+ props.Target.Darwin.Enabled = proptools.BoolPtr(false)
+ props.Target.Windows.Enabled = proptools.BoolPtr(false)
+ ctx.AppendProperties(&props)
+}
+
// cmake_snapshot allows defining source packages for release outside of Android build tree.
// As a result of cmake_snapshot module build, a zip file is generated with CMake build definitions
// for selected source modules, their dependencies and optionally also the source code itself.
func CmakeSnapshotFactory() android.Module {
module := &CmakeSnapshot{}
module.AddProperties(&module.Properties)
- android.InitAndroidModule(module)
+ android.AddLoadHook(module, cmakeSnapshotLoadHook)
+ android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
return module
}
diff --git a/cc/cmake_snapshot_test.go b/cc/cmake_snapshot_test.go
index 14008e2..8fca6c1 100644
--- a/cc/cmake_snapshot_test.go
+++ b/cc/cmake_snapshot_test.go
@@ -15,6 +15,7 @@
package cc
import (
+ "runtime"
"strings"
"testing"
@@ -23,14 +24,16 @@
func wasGenerated(t *testing.T, m *android.TestingModule, fileName string, ruleType string) {
t.Helper()
- ruleName := m.Output(fileName).Rule.String()
+ ruleName := "<nil>"
+ if rule := m.MaybeOutput(fileName).Rule; rule != nil {
+ ruleName = rule.String()
+ }
if !strings.HasSuffix(ruleName, ruleType) {
- t.Errorf("Main Cmake file wasn't generated, expected rule %v, found %v", ruleType, ruleName)
+ t.Errorf("Main Cmake file wasn't generated properly, expected rule %v, found %v", ruleType, ruleName)
}
}
func TestEmptyCmakeSnapshot(t *testing.T) {
- t.Skip("Failing on sdk-sdk_mac target")
t.Parallel()
result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
cc_cmake_snapshot {
@@ -40,14 +43,17 @@
include_sources: true,
}`)
- snapshotModule := result.ModuleForTests("foo", "")
+ if runtime.GOOS != "linux" {
+ t.Skip("CMake snapshots are only supported on Linux")
+ }
+
+ snapshotModule := result.ModuleForTests("foo", "linux_glibc_x86_64")
wasGenerated(t, &snapshotModule, "CMakeLists.txt", "rawFileCopy")
wasGenerated(t, &snapshotModule, "foo.zip", "")
}
func TestCmakeSnapshotWithBinary(t *testing.T) {
- t.Skip("Failing on sdk-sdk_mac target")
t.Parallel()
xtra := android.FixtureAddTextFile("some/module/Android.bp", `
cc_binary {
@@ -65,7 +71,45 @@
include_sources: true,
}`)
- snapshotModule := result.ModuleForTests("foo", "")
+ if runtime.GOOS != "linux" {
+ t.Skip("CMake snapshots are only supported on Linux")
+ }
+
+ snapshotModule := result.ModuleForTests("foo", "linux_glibc_x86_64")
wasGenerated(t, &snapshotModule, "some/module/CMakeLists.txt", "rawFileCopy")
}
+
+func TestCmakeSnapshotAsTestData(t *testing.T) {
+ t.Parallel()
+ result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
+ cc_test {
+ name: "foo_test",
+ gtest: false,
+ srcs: [
+ "foo_test.c",
+ ],
+ data: [
+ ":foo",
+ ],
+ target: {
+ android: {enabled: false},
+ },
+ }
+
+ cc_cmake_snapshot {
+ name: "foo",
+ modules: [],
+ prebuilts: ["libc++"],
+ include_sources: true,
+ }`)
+
+ if runtime.GOOS != "linux" {
+ t.Skip("CMake snapshots are only supported on Linux")
+ }
+
+ snapshotModule := result.ModuleForTests("foo", "linux_glibc_x86_64")
+
+ wasGenerated(t, &snapshotModule, "CMakeLists.txt", "rawFileCopy")
+ wasGenerated(t, &snapshotModule, "foo.zip", "")
+}