• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 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
15package bp2build
16
17import (
18	"android/soong/android"
19	"android/soong/genrule"
20	"testing"
21)
22
23func TestGensrcs(t *testing.T) {
24	testcases := []struct {
25		name               string
26		bp                 string
27		expectedBazelAttrs AttrNameToString
28	}{
29		{
30			name: "gensrcs with common usage of properties",
31			bp: `
32			gensrcs {
33                name: "foo",
34                srcs: ["test/input.txt", ":external_files"],
35                tool_files: ["program.py"],
36                cmd: "$(location program.py) $(in) $(out)",
37                output_extension: "out",
38                bazel_module: { bp2build_available: true },
39			}`,
40			expectedBazelAttrs: AttrNameToString{
41				"srcs": `[
42        "test/input.txt",
43        ":external_files__BP2BUILD__MISSING__DEP",
44    ]`,
45				"tools":            `["program.py"]`,
46				"output_extension": `"out"`,
47				"cmd":              `"$(location program.py) $(SRC) $(OUT)"`,
48			},
49		},
50		{
51			name: "gensrcs with out_extension unset",
52			bp: `
53			gensrcs {
54                name: "foo",
55                srcs: ["input.txt"],
56                cmd: "cat $(in) > $(out)",
57                bazel_module: { bp2build_available: true },
58			}`,
59			expectedBazelAttrs: AttrNameToString{
60				"srcs": `["input.txt"]`,
61				"cmd":  `"cat $(SRC) > $(OUT)"`,
62			},
63		},
64	}
65
66	for _, test := range testcases {
67		expectedBazelTargets := []string{
68			MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
69		}
70		t.Run(test.name, func(t *testing.T) {
71			RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
72				Bp2buildTestCase{
73					ModuleTypeUnderTest:        "gensrcs",
74					ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
75					Blueprint:                  test.bp,
76					ExpectedBazelTargets:       expectedBazelTargets,
77				})
78		})
79	}
80}
81