blob: cda187f1dc4507259d46d6cd21adfa860bdafe81 [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) {
33 t.Parallel()
34 result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
35 cc_cmake_snapshot {
36 name: "foo",
37 modules: [],
38 prebuilts: ["libc++"],
39 include_sources: true,
40 }`)
41
42 snapshotModule := result.ModuleForTests("foo", "")
43
44 wasGenerated(t, &snapshotModule, "CMakeLists.txt", "rawFileCopy")
45 wasGenerated(t, &snapshotModule, "foo.zip", "")
46}
47
48func TestCmakeSnapshotWithBinary(t *testing.T) {
49 t.Parallel()
50 xtra := android.FixtureAddTextFile("some/module/Android.bp", `
51 cc_binary {
52 name: "foo_binary",
53 host_supported: true,
54 cmake_snapshot_supported: true,
55 }
56 `)
57 result := android.GroupFixturePreparers(PrepareForIntegrationTestWithCc, xtra).RunTestWithBp(t, `
58 cc_cmake_snapshot {
59 name: "foo",
60 modules: [
61 "foo_binary",
62 ],
63 include_sources: true,
64 }`)
65
66 snapshotModule := result.ModuleForTests("foo", "")
67
68 wasGenerated(t, &snapshotModule, "some/module/CMakeLists.txt", "rawFileCopy")
69}