1// 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 ( 18 "path/filepath" 19 "strings" 20 "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_shared").Rule("aidl") 35 libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module) 36 37 if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) { 38 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", 46 srcs: ["sub/c.aidl"], 47 path: "sub", 48 } 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_shared").Rule("aidl") 59 libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module) 60 61 if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) { 62 t.Errorf("missing aidl includes in global flags") 63 } 64 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 70 }) 71 72} 73