blob: 893da57740d241be86b9858b869a968faadd4923 [file] [log] [blame]
Vinh Tran16fe8e12022-08-16 16:45:44 -04001package android
2
3import (
4 "path/filepath"
5 "testing"
6)
7
8func TestFileGroupWithPathProp(t *testing.T) {
Liz Kammer748209c2022-10-24 10:43:27 -04009 // TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups
10 t.Skip("Re-enable once filegroups are corrected for mixed builds")
Vinh Tran16fe8e12022-08-16 16:45:44 -040011 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 {
43 outBaseDir := "outputbase"
44 result := GroupFixturePreparers(
45 PrepareForTestWithFilegroup,
46 FixtureModifyConfig(func(config Config) {
47 config.BazelContext = MockBazelContext{
48 OutputBaseDir: outBaseDir,
49 LabelToOutputFiles: map[string][]string{
50 "//:baz": []string{"a/b/c/d/test.aidl"},
51 },
52 }
53 }),
54 ).RunTestWithBp(t, testCase.bp)
55
56 fg := result.Module("baz", "").(*fileGroup)
57 AssertStringEquals(t, "src relativeRoot", testCase.rel, fg.srcs[0].Rel())
58 AssertStringEquals(t, "src full path", expectedOutputfile, fg.srcs[0].String())
59 }
60}
Anton Hansson7d6dd8b2023-03-06 11:26:17 +000061
62func TestFilegroupDefaults(t *testing.T) {
63 bp := FixtureAddTextFile("p/Android.bp", `
64 filegroup_defaults {
65 name: "defaults",
66 visibility: ["//x"],
67 }
68 filegroup {
69 name: "foo",
70 defaults: ["defaults"],
71 visibility: ["//y"],
72 }
73 `)
74 result := GroupFixturePreparers(
75 PrepareForTestWithFilegroup,
76 PrepareForTestWithDefaults,
77 PrepareForTestWithVisibility,
78 bp).RunTest(t)
79 rules := effectiveVisibilityRules(result.Config, qualifiedModuleName{pkg: "p", name: "foo"})
80 AssertDeepEquals(t, "visibility", []string{"//x", "//y"}, rules.Strings())
81}