blob: da3b4e8ad8b3a1f04d28ae53ba7a9e3fec2d6cb6 [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"
21)
22
23func TestGen(t *testing.T) {
24 t.Run("simple", func(t *testing.T) {
25 ctx := testCc(t, `
26 cc_library_shared {
27 name: "libfoo",
28 srcs: [
29 "foo.c",
30 "b.aidl",
31 ],
32 }`)
33
34 aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
35 libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
36
Dan Willemsen1945a4b2019-06-04 17:10:41 -070037 if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.GlobalFlags) {
Colin Crossf18e1102017-11-16 14:33:08 -080038 t.Errorf("missing aidl includes in global flags")
39 }
40 })
41
42 t.Run("filegroup", func(t *testing.T) {
43 ctx := testCc(t, `
44 filegroup {
45 name: "fg",
Jiyong Park29074592019-07-07 16:27:47 +090046 srcs: ["sub/c.aidl"],
47 path: "sub",
Colin Crossf18e1102017-11-16 14:33:08 -080048 }
49
50 cc_library_shared {
51 name: "libfoo",
52 srcs: [
53 "foo.c",
54 ":fg",
55 ],
56 }`)
57
58 aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
59 libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
60
Dan Willemsen1945a4b2019-06-04 17:10:41 -070061 if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.GlobalFlags) {
Colin Crossf18e1102017-11-16 14:33:08 -080062 t.Errorf("missing aidl includes in global flags")
63 }
Jiyong Park29074592019-07-07 16:27:47 +090064
65 aidlCommand := aidl.RuleParams.Command
66 if !strings.Contains(aidlCommand, "-Isub") {
67 t.Errorf("aidl command for c.aidl should contain \"-Isub\", but was %q", aidlCommand)
68 }
69
Colin Crossf18e1102017-11-16 14:33:08 -080070 })
71
72}