blob: e808340faad773a8dce7a50691d02d006f579b1e [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"],
Liz Kammer8bd92422023-06-09 13:41:08 -040036 cmd: "$(location program.py) $(in) $(out) $(location foo/file.txt) $(location :external_files)",
37 data: ["foo/file.txt", ":external_files"],
Vinh Tranb69e1ae2022-05-20 18:54:09 -040038 output_extension: "out",
39 bazel_module: { bp2build_available: true },
40 }`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000041 expectedBazelAttrs: AttrNameToString{
Vinh Tranb69e1ae2022-05-20 18:54:09 -040042 "srcs": `[
43 "test/input.txt",
44 ":external_files__BP2BUILD__MISSING__DEP",
45 ]`,
46 "tools": `["program.py"]`,
47 "output_extension": `"out"`,
Liz Kammer8bd92422023-06-09 13:41:08 -040048 "cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files__BP2BUILD__MISSING__DEP)"`,
49 "data": `[
50 "foo/file.txt",
51 ":external_files__BP2BUILD__MISSING__DEP",
52 ]`,
Vinh Tranb69e1ae2022-05-20 18:54:09 -040053 },
54 },
55 {
56 name: "gensrcs with out_extension unset",
57 bp: `
58 gensrcs {
59 name: "foo",
60 srcs: ["input.txt"],
61 cmd: "cat $(in) > $(out)",
62 bazel_module: { bp2build_available: true },
63 }`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000064 expectedBazelAttrs: AttrNameToString{
Vinh Tranb69e1ae2022-05-20 18:54:09 -040065 "srcs": `["input.txt"]`,
66 "cmd": `"cat $(SRC) > $(OUT)"`,
67 },
68 },
69 }
70
71 for _, test := range testcases {
72 expectedBazelTargets := []string{
Sam Delmerico3177a6e2022-06-21 19:28:33 +000073 MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
Vinh Tranb69e1ae2022-05-20 18:54:09 -040074 }
75 t.Run(test.name, func(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000076 RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
77 Bp2buildTestCase{
78 ModuleTypeUnderTest: "gensrcs",
79 ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
80 Blueprint: test.bp,
81 ExpectedBazelTargets: expectedBazelTargets,
Vinh Tranb69e1ae2022-05-20 18:54:09 -040082 })
83 })
84 }
85}