Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Dan Willemsen | 1945a4b | 2019-06-04 17:10:41 -0700 | [diff] [blame] | 18 | "path/filepath" |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 19 | "strings" |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 20 | "testing" |
| 21 | ) |
| 22 | |
| 23 | func 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 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 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) |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 36 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 37 | if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) { |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 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", |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 46 | srcs: ["sub/c.aidl"], |
| 47 | path: "sub", |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | cc_library_shared { |
| 51 | name: "libfoo", |
| 52 | srcs: [ |
| 53 | "foo.c", |
| 54 | ":fg", |
| 55 | ], |
| 56 | }`) |
| 57 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 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) |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 60 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 61 | if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) { |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 62 | t.Errorf("missing aidl includes in global flags") |
| 63 | } |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 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 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 70 | }) |
| 71 | |
| 72 | } |