blob: fa0c6f209bf8104c56ca62c6a6d2df4c63e9cdad [file] [log] [blame]
Colin Crossef354482018-10-23 11:27:50 -07001// Copyright 2018 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 "reflect"
19 "testing"
20
21 "android/soong/android"
22)
23
Colin Cross98be1bb2019-12-13 20:41:13 -080024func testGenruleContext(config android.Config) *android.TestContext {
Colin Crossae8600b2020-10-29 17:09:13 -070025 ctx := android.NewTestArchContext(config)
Colin Cross4b49b762019-11-22 15:25:03 -080026 ctx.RegisterModuleType("cc_genrule", genRuleFactory)
Colin Crossae8600b2020-10-29 17:09:13 -070027 ctx.Register()
Colin Crossef354482018-10-23 11:27:50 -070028
29 return ctx
30}
31
32func TestArchGenruleCmd(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -080033 fs := map[string][]byte{
34 "tool": nil,
35 "foo": nil,
36 "bar": nil,
37 }
Colin Crossef354482018-10-23 11:27:50 -070038 bp := `
39 cc_genrule {
40 name: "gen",
41 tool_files: ["tool"],
42 cmd: "$(location tool) $(in) $(out)",
43 arch: {
44 arm: {
45 srcs: ["foo"],
46 out: ["out_arm"],
47 },
48 arm64: {
49 srcs: ["bar"],
50 out: ["out_arm64"],
51 },
52 },
53 }
54 `
Colin Cross98be1bb2019-12-13 20:41:13 -080055 config := android.TestArchConfig(buildDir, nil, bp, fs)
Colin Crossef354482018-10-23 11:27:50 -070056
Colin Cross98be1bb2019-12-13 20:41:13 -080057 ctx := testGenruleContext(config)
Colin Crossef354482018-10-23 11:27:50 -070058
59 _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
60 if errs == nil {
61 _, errs = ctx.PrepareBuildActions(config)
62 }
63 if errs != nil {
64 t.Fatal(errs)
65 }
66
Colin Cross7113d202019-11-20 16:39:12 -080067 gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out_arm")
Colin Crossef354482018-10-23 11:27:50 -070068 expected := []string{"foo"}
Colin Cross3d680512020-11-13 16:23:53 -080069 if !reflect.DeepEqual(expected, gen.Implicits.Strings()[:len(expected)]) {
70 t.Errorf(`want arm inputs %v, got %v`, expected, gen.Implicits.Strings())
Colin Crossef354482018-10-23 11:27:50 -070071 }
72
Colin Cross7113d202019-11-20 16:39:12 -080073 gen = ctx.ModuleForTests("gen", "android_arm64_armv8-a").Output("out_arm64")
Colin Crossef354482018-10-23 11:27:50 -070074 expected = []string{"bar"}
Colin Cross3d680512020-11-13 16:23:53 -080075 if !reflect.DeepEqual(expected, gen.Implicits.Strings()[:len(expected)]) {
76 t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Implicits.Strings())
Colin Crossef354482018-10-23 11:27:50 -070077 }
78}
Colin Cross81ca6cd2020-08-06 17:46:48 -070079
80func TestLibraryGenruleCmd(t *testing.T) {
81 bp := `
82 cc_library {
83 name: "libboth",
84 }
85
86 cc_library_shared {
87 name: "libshared",
88 }
89
90 cc_library_static {
91 name: "libstatic",
92 }
93
94 cc_genrule {
95 name: "gen",
96 tool_files: ["tool"],
97 srcs: [
98 ":libboth",
99 ":libshared",
100 ":libstatic",
101 ],
102 cmd: "$(location tool) $(in) $(out)",
103 out: ["out"],
104 }
105 `
106 ctx := testCc(t, bp)
107
108 gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out")
109 expected := []string{"libboth.so", "libshared.so", "libstatic.a"}
110 var got []string
Colin Cross3d680512020-11-13 16:23:53 -0800111 for _, input := range gen.Implicits {
Colin Cross81ca6cd2020-08-06 17:46:48 -0700112 got = append(got, input.Base())
113 }
Colin Cross3d680512020-11-13 16:23:53 -0800114 if !reflect.DeepEqual(expected, got[:len(expected)]) {
Colin Cross81ca6cd2020-08-06 17:46:48 -0700115 t.Errorf(`want inputs %v, got %v`, expected, got)
116 }
117}