Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 1 | package android |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestFileGroupWithPathProp(t *testing.T) { |
Liz Kammer | 748209c | 2022-10-24 10:43:27 -0400 | [diff] [blame] | 9 | // TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups |
| 10 | t.Skip("Re-enable once filegroups are corrected for mixed builds") |
Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 11 | outBaseDir := "outputbase" |
| 12 | pathPrefix := outBaseDir + "/execroot/__main__" |
| 13 | expectedOutputfile := filepath.Join(pathPrefix, "a/b/c/d/test.aidl") |
| 14 | |
| 15 | testCases := []struct { |
| 16 | bp string |
| 17 | rel string |
| 18 | }{ |
| 19 | { |
| 20 | bp: ` |
| 21 | filegroup { |
| 22 | name: "baz", |
| 23 | srcs: ["a/b/c/d/test.aidl"], |
| 24 | path: "a/b", |
| 25 | bazel_module: { label: "//:baz" }, |
| 26 | } |
| 27 | `, |
| 28 | rel: "c/d/test.aidl", |
| 29 | }, |
| 30 | { |
| 31 | bp: ` |
| 32 | filegroup { |
| 33 | name: "baz", |
| 34 | srcs: ["a/b/c/d/test.aidl"], |
| 35 | bazel_module: { label: "//:baz" }, |
| 36 | } |
| 37 | `, |
| 38 | rel: "a/b/c/d/test.aidl", |
| 39 | }, |
| 40 | } |
| 41 | |
| 42 | for _, testCase := range testCases { |
Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 43 | result := GroupFixturePreparers( |
| 44 | PrepareForTestWithFilegroup, |
Vinh Tran | 16fe8e1 | 2022-08-16 16:45:44 -0400 | [diff] [blame] | 45 | ).RunTestWithBp(t, testCase.bp) |
| 46 | |
| 47 | fg := result.Module("baz", "").(*fileGroup) |
| 48 | AssertStringEquals(t, "src relativeRoot", testCase.rel, fg.srcs[0].Rel()) |
| 49 | AssertStringEquals(t, "src full path", expectedOutputfile, fg.srcs[0].String()) |
| 50 | } |
| 51 | } |
Anton Hansson | 7d6dd8b | 2023-03-06 11:26:17 +0000 | [diff] [blame] | 52 | |
| 53 | func TestFilegroupDefaults(t *testing.T) { |
| 54 | bp := FixtureAddTextFile("p/Android.bp", ` |
| 55 | filegroup_defaults { |
| 56 | name: "defaults", |
| 57 | visibility: ["//x"], |
| 58 | } |
| 59 | filegroup { |
| 60 | name: "foo", |
| 61 | defaults: ["defaults"], |
| 62 | visibility: ["//y"], |
| 63 | } |
| 64 | `) |
| 65 | result := GroupFixturePreparers( |
| 66 | PrepareForTestWithFilegroup, |
| 67 | PrepareForTestWithDefaults, |
| 68 | PrepareForTestWithVisibility, |
| 69 | bp).RunTest(t) |
| 70 | rules := effectiveVisibilityRules(result.Config, qualifiedModuleName{pkg: "p", name: "foo"}) |
| 71 | AssertDeepEquals(t, "visibility", []string{"//x", "//y"}, rules.Strings()) |
| 72 | } |