blob: 4845973d8842592a8a29efd93cfb6d91c75d5291 [file] [log] [blame]
Vinh Tranb69e1ae2022-05-20 18:54:09 -04001// 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
Sam Delmerico3177a6e2022-06-21 19:28:33 +000027 expectedBazelAttrs AttrNameToString
Vinh Tranb69e1ae2022-05-20 18:54:09 -040028 }{
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 }`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000040 expectedBazelAttrs: AttrNameToString{
Vinh Tranb69e1ae2022-05-20 18:54:09 -040041 "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 }`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000059 expectedBazelAttrs: AttrNameToString{
Vinh Tranb69e1ae2022-05-20 18:54:09 -040060 "srcs": `["input.txt"]`,
61 "cmd": `"cat $(SRC) > $(OUT)"`,
62 },
63 },
64 }
65
66 for _, test := range testcases {
67 expectedBazelTargets := []string{
Sam Delmerico3177a6e2022-06-21 19:28:33 +000068 MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
Vinh Tranb69e1ae2022-05-20 18:54:09 -040069 }
70 t.Run(test.name, func(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000071 RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
72 Bp2buildTestCase{
73 ModuleTypeUnderTest: "gensrcs",
74 ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
75 Blueprint: test.bp,
76 ExpectedBazelTargets: expectedBazelTargets,
Vinh Tranb69e1ae2022-05-20 18:54:09 -040077 })
78 })
79 }
80}