blob: 41ef95c2706c0a4b9983500319e5482093f0d9c0 [file] [log] [blame]
Colin Crossf18e1102017-11-16 14:33:08 -08001// Copyright 2017 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 (
Dan Willemsen1945a4b2019-06-04 17:10:41 -070018 "path/filepath"
Jiyong Park29074592019-07-07 16:27:47 +090019 "strings"
Colin Crossf18e1102017-11-16 14:33:08 -080020 "testing"
Colin Crosse16ce362020-11-12 08:29:30 -080021
22 "android/soong/android"
Colin Crossf18e1102017-11-16 14:33:08 -080023)
24
25func TestGen(t *testing.T) {
26 t.Run("simple", func(t *testing.T) {
27 ctx := testCc(t, `
28 cc_library_shared {
29 name: "libfoo",
30 srcs: [
31 "foo.c",
32 "b.aidl",
33 ],
34 }`)
35
Colin Cross7113d202019-11-20 16:39:12 -080036 aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("aidl")
37 libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module)
Colin Crossf18e1102017-11-16 14:33:08 -080038
Colin Cross4af21ed2019-11-04 09:37:55 -080039 if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) {
Colin Crossf18e1102017-11-16 14:33:08 -080040 t.Errorf("missing aidl includes in global flags")
41 }
42 })
43
44 t.Run("filegroup", func(t *testing.T) {
45 ctx := testCc(t, `
46 filegroup {
47 name: "fg",
Jiyong Park29074592019-07-07 16:27:47 +090048 srcs: ["sub/c.aidl"],
49 path: "sub",
Colin Crossf18e1102017-11-16 14:33:08 -080050 }
51
52 cc_library_shared {
53 name: "libfoo",
54 srcs: [
55 "foo.c",
56 ":fg",
57 ],
58 }`)
59
Colin Cross7113d202019-11-20 16:39:12 -080060 aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("aidl")
Colin Crosse16ce362020-11-12 08:29:30 -080061 aidlManifest := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("aidl.sbox.textproto")
Colin Cross7113d202019-11-20 16:39:12 -080062 libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module)
Colin Crossf18e1102017-11-16 14:33:08 -080063
Colin Cross4af21ed2019-11-04 09:37:55 -080064 if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) {
Colin Crossf18e1102017-11-16 14:33:08 -080065 t.Errorf("missing aidl includes in global flags")
66 }
Jiyong Park29074592019-07-07 16:27:47 +090067
Colin Crosse16ce362020-11-12 08:29:30 -080068 aidlCommand := android.RuleBuilderSboxProtoForTests(t, aidlManifest).Commands[0].GetCommand()
Jiyong Park29074592019-07-07 16:27:47 +090069 if !strings.Contains(aidlCommand, "-Isub") {
70 t.Errorf("aidl command for c.aidl should contain \"-Isub\", but was %q", aidlCommand)
71 }
72
Colin Crossf18e1102017-11-16 14:33:08 -080073 })
74
75}