1package android
2
3import (
4	"path/filepath"
5	"testing"
6)
7
8func TestFileGroupWithPathProp(t *testing.T) {
9	// TODO(b/247782695), TODO(b/242847534) Fix mixed builds for filegroups
10	t.Skip("Re-enable once filegroups are corrected for mixed builds")
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 {
43		result := GroupFixturePreparers(
44			PrepareForTestWithFilegroup,
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}
52
53func 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}
73