blob: 14008e25d4179ae132df63994ff4e8e0a0573745 [file] [log] [blame]
Hao Chen1c8ea5b2023-10-20 23:03:45 +00001// Copyright 2024 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18 "strings"
19 "testing"
20
21 "android/soong/android"
22)
23
24func wasGenerated(t *testing.T, m *android.TestingModule, fileName string, ruleType string) {
25 t.Helper()
26 ruleName := m.Output(fileName).Rule.String()
27 if !strings.HasSuffix(ruleName, ruleType) {
28 t.Errorf("Main Cmake file wasn't generated, expected rule %v, found %v", ruleType, ruleName)
29 }
30}
31
32func TestEmptyCmakeSnapshot(t *testing.T) {
Tomasz Wasilczykea2fbd62024-05-10 07:13:21 -070033 t.Skip("Failing on sdk-sdk_mac target")
Hao Chen1c8ea5b2023-10-20 23:03:45 +000034 t.Parallel()
35 result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
36 cc_cmake_snapshot {
37 name: "foo",
38 modules: [],
39 prebuilts: ["libc++"],
40 include_sources: true,
41 }`)
42
43 snapshotModule := result.ModuleForTests("foo", "")
44
45 wasGenerated(t, &snapshotModule, "CMakeLists.txt", "rawFileCopy")
46 wasGenerated(t, &snapshotModule, "foo.zip", "")
47}
48
49func TestCmakeSnapshotWithBinary(t *testing.T) {
Tomasz Wasilczykea2fbd62024-05-10 07:13:21 -070050 t.Skip("Failing on sdk-sdk_mac target")
Hao Chen1c8ea5b2023-10-20 23:03:45 +000051 t.Parallel()
52 xtra := android.FixtureAddTextFile("some/module/Android.bp", `
53 cc_binary {
54 name: "foo_binary",
55 host_supported: true,
56 cmake_snapshot_supported: true,
57 }
58 `)
59 result := android.GroupFixturePreparers(PrepareForIntegrationTestWithCc, xtra).RunTestWithBp(t, `
60 cc_cmake_snapshot {
61 name: "foo",
62 modules: [
63 "foo_binary",
64 ],
65 include_sources: true,
66 }`)
67
68 snapshotModule := result.ModuleForTests("foo", "")
69
70 wasGenerated(t, &snapshotModule, "some/module/CMakeLists.txt", "rawFileCopy")
71}