| 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" | 
| Colin Cross | e16ce36 | 2020-11-12 08:29:30 -0800 | [diff] [blame] | 21 |  | 
 | 22 | 	"android/soong/android" | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 23 | ) | 
 | 24 |  | 
 | 25 | func 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 Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 36 | 		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 Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 38 |  | 
| Paul Duffin | e8366da | 2021-03-24 10:40:38 +0000 | [diff] [blame] | 39 | 		expected := "-I" + filepath.Dir(aidl.Output.String()) | 
 | 40 | 		actual := android.StringsRelativeToTop(ctx.Config(), libfoo.flags.Local.CommonFlags) | 
 | 41 | 		if !inList(expected, actual) { | 
 | 42 | 			t.Errorf("missing aidl includes in global flags, expected %q, actual %q", expected, actual) | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 43 | 		} | 
 | 44 | 	}) | 
 | 45 |  | 
 | 46 | 	t.Run("filegroup", func(t *testing.T) { | 
 | 47 | 		ctx := testCc(t, ` | 
 | 48 | 		filegroup { | 
 | 49 | 			name: "fg", | 
| Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 50 | 			srcs: ["sub/c.aidl"], | 
 | 51 | 			path: "sub", | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 52 | 		} | 
 | 53 |  | 
 | 54 | 		cc_library_shared { | 
 | 55 | 			name: "libfoo", | 
 | 56 | 			srcs: [ | 
 | 57 | 				"foo.c", | 
 | 58 | 				":fg", | 
 | 59 | 			], | 
 | 60 | 		}`) | 
 | 61 |  | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 62 | 		aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("aidl") | 
| Colin Cross | e16ce36 | 2020-11-12 08:29:30 -0800 | [diff] [blame] | 63 | 		aidlManifest := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Output("aidl.sbox.textproto") | 
| Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 64 | 		libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Module().(*Module) | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 65 |  | 
| Paul Duffin | e8366da | 2021-03-24 10:40:38 +0000 | [diff] [blame] | 66 | 		if !inList("-I"+filepath.Dir(aidl.Output.String()), android.StringsRelativeToTop(ctx.Config(), libfoo.flags.Local.CommonFlags)) { | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 67 | 			t.Errorf("missing aidl includes in global flags") | 
 | 68 | 		} | 
| Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 69 |  | 
| Colin Cross | f61d03d | 2023-11-02 16:56:39 -0700 | [diff] [blame] | 70 | 		aidlCommand := android.RuleBuilderSboxProtoForTests(t, ctx, aidlManifest).Commands[0].GetCommand() | 
| Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 71 | 		if !strings.Contains(aidlCommand, "-Isub") { | 
 | 72 | 			t.Errorf("aidl command for c.aidl should contain \"-Isub\", but was %q", aidlCommand) | 
 | 73 | 		} | 
 | 74 |  | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 75 | 	}) | 
 | 76 |  | 
| Trevor Radcliffe | 3092a8e | 2022-08-24 15:25:25 +0000 | [diff] [blame] | 77 | 	t.Run("sysprop", func(t *testing.T) { | 
 | 78 | 		ctx := testCc(t, ` | 
 | 79 | 		cc_library { | 
 | 80 | 			name: "libsysprop", | 
 | 81 | 			srcs: [ | 
 | 82 | 				"path/to/foo.sysprop", | 
 | 83 | 			], | 
 | 84 | 		}`) | 
 | 85 |  | 
 | 86 | 		outDir := "out/soong/.intermediates/libsysprop/android_arm64_armv8-a_static/gen" | 
 | 87 | 		syspropBuildParams := ctx.ModuleForTests("libsysprop", "android_arm64_armv8-a_static").Rule("sysprop") | 
 | 88 |  | 
 | 89 | 		android.AssertStringEquals(t, "header output directory does not match", outDir+"/sysprop/include/path/to", syspropBuildParams.Args["headerOutDir"]) | 
 | 90 | 		android.AssertStringEquals(t, "public output directory does not match", outDir+"/sysprop/public/include/path/to", syspropBuildParams.Args["publicOutDir"]) | 
 | 91 | 		android.AssertStringEquals(t, "src output directory does not match", outDir+"/sysprop/path/to", syspropBuildParams.Args["srcOutDir"]) | 
 | 92 | 		android.AssertStringEquals(t, "output include name does not match", "path/to/foo.sysprop.h", syspropBuildParams.Args["includeName"]) | 
 | 93 | 		android.AssertStringEquals(t, "Input file does not match", "path/to/foo.sysprop", syspropBuildParams.Input.String()) | 
 | 94 | 		android.AssertStringEquals(t, "Output file does not match", outDir+"/sysprop/path/to/foo.sysprop.cpp", syspropBuildParams.Output.String()) | 
 | 95 | 		android.AssertStringListContains(t, "Implicit outputs does not contain header file", syspropBuildParams.ImplicitOutputs.Strings(), outDir+"/sysprop/include/path/to/foo.sysprop.h") | 
 | 96 | 		android.AssertStringListContains(t, "Implicit outputs does not contain public header file", syspropBuildParams.ImplicitOutputs.Strings(), outDir+"/sysprop/public/include/path/to/foo.sysprop.h") | 
 | 97 | 		android.AssertIntEquals(t, "Implicit outputs contains the incorrect number of elements", 2, len(syspropBuildParams.ImplicitOutputs.Strings())) | 
 | 98 | 	}) | 
| Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 99 | } |