2022-05-21 00:54:09 +02:00
|
|
|
// Copyright 2020 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package bp2build
|
|
|
|
|
|
|
|
import (
|
2023-10-05 17:47:07 +02:00
|
|
|
"testing"
|
|
|
|
|
2022-05-21 00:54:09 +02:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/genrule"
|
|
|
|
)
|
|
|
|
|
2023-10-05 17:47:07 +02:00
|
|
|
func registerModulesForGensrcsTests(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
|
|
|
}
|
|
|
|
|
2022-05-21 00:54:09 +02:00
|
|
|
func TestGensrcs(t *testing.T) {
|
|
|
|
testcases := []struct {
|
2023-10-05 17:47:07 +02:00
|
|
|
name string
|
|
|
|
bp string
|
|
|
|
expectedBazelAttrs AttrNameToString
|
|
|
|
stubbedBuildDefinitions []string
|
2022-05-21 00:54:09 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "gensrcs with common usage of properties",
|
|
|
|
bp: `
|
|
|
|
gensrcs {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["test/input.txt", ":external_files"],
|
|
|
|
tool_files: ["program.py"],
|
2023-06-09 19:41:08 +02:00
|
|
|
cmd: "$(location program.py) $(in) $(out) $(location foo/file.txt) $(location :external_files)",
|
|
|
|
data: ["foo/file.txt", ":external_files"],
|
2022-05-21 00:54:09 +02:00
|
|
|
output_extension: "out",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2023-10-05 17:47:07 +02:00
|
|
|
}
|
|
|
|
filegroup {
|
|
|
|
name: "external_files",
|
2022-05-21 00:54:09 +02:00
|
|
|
}`,
|
2023-10-05 17:47:07 +02:00
|
|
|
stubbedBuildDefinitions: []string{"external_files"},
|
2022-06-21 21:28:33 +02:00
|
|
|
expectedBazelAttrs: AttrNameToString{
|
2022-05-21 00:54:09 +02:00
|
|
|
"srcs": `[
|
|
|
|
"test/input.txt",
|
2023-10-05 17:47:07 +02:00
|
|
|
":external_files",
|
2022-05-21 00:54:09 +02:00
|
|
|
]`,
|
|
|
|
"tools": `["program.py"]`,
|
|
|
|
"output_extension": `"out"`,
|
2023-10-05 17:47:07 +02:00
|
|
|
"cmd": `"$(location program.py) $(SRC) $(OUT) $(location foo/file.txt) $(location :external_files)"`,
|
2023-06-09 19:41:08 +02:00
|
|
|
"data": `[
|
|
|
|
"foo/file.txt",
|
2023-10-05 17:47:07 +02:00
|
|
|
":external_files",
|
2023-06-09 19:41:08 +02:00
|
|
|
]`,
|
2022-05-21 00:54:09 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "gensrcs with out_extension unset",
|
|
|
|
bp: `
|
|
|
|
gensrcs {
|
|
|
|
name: "foo",
|
|
|
|
srcs: ["input.txt"],
|
|
|
|
cmd: "cat $(in) > $(out)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`,
|
2022-06-21 21:28:33 +02:00
|
|
|
expectedBazelAttrs: AttrNameToString{
|
2022-05-21 00:54:09 +02:00
|
|
|
"srcs": `["input.txt"]`,
|
|
|
|
"cmd": `"cat $(SRC) > $(OUT)"`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testcases {
|
|
|
|
expectedBazelTargets := []string{
|
2022-06-21 21:28:33 +02:00
|
|
|
MakeBazelTargetNoRestrictions("gensrcs", "foo", test.expectedBazelAttrs),
|
2022-05-21 00:54:09 +02:00
|
|
|
}
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2023-10-05 17:47:07 +02:00
|
|
|
RunBp2BuildTestCase(t, registerModulesForGensrcsTests,
|
2022-06-21 21:28:33 +02:00
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: "gensrcs",
|
|
|
|
ModuleTypeUnderTestFactory: genrule.GenSrcsFactory,
|
|
|
|
Blueprint: test.bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
2023-10-05 17:47:07 +02:00
|
|
|
StubbedBuildDefinitions: test.stubbedBuildDefinitions,
|
2022-05-21 00:54:09 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|