2021-09-08 16:36:41 +02:00
|
|
|
// Copyright 2021 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 (
|
2022-10-17 21:29:15 +02:00
|
|
|
"fmt"
|
2023-07-18 17:39:30 +02:00
|
|
|
"path/filepath"
|
2022-10-17 21:29:15 +02:00
|
|
|
"testing"
|
|
|
|
|
2021-09-08 16:36:41 +02:00
|
|
|
"android/soong/android"
|
2022-01-11 22:55:46 +01:00
|
|
|
"android/soong/cc"
|
2021-09-08 16:36:41 +02:00
|
|
|
"android/soong/genrule"
|
2022-01-11 22:55:46 +01:00
|
|
|
"android/soong/java"
|
2021-09-08 16:36:41 +02:00
|
|
|
)
|
|
|
|
|
2021-11-08 18:56:31 +01:00
|
|
|
func registerGenruleModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("genrule_defaults", func() android.Module { return genrule.DefaultsFactory() })
|
2023-08-18 00:35:04 +02:00
|
|
|
ctx.RegisterModuleType("cc_binary", func() android.Module { return cc.BinaryFactory() })
|
|
|
|
ctx.RegisterModuleType("soong_namespace", func() android.Module { return android.NamespaceFactory() })
|
2021-11-08 18:56:31 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:28:33 +02:00
|
|
|
func runGenruleTestCase(t *testing.T, tc Bp2buildTestCase) {
|
2021-11-08 18:56:31 +01:00
|
|
|
t.Helper()
|
2022-06-21 21:28:33 +02:00
|
|
|
(&tc).ModuleTypeUnderTest = "genrule"
|
|
|
|
(&tc).ModuleTypeUnderTestFactory = genrule.GenRuleFactory
|
|
|
|
RunBp2BuildTestCase(t, registerGenruleModuleTypes, tc)
|
2021-11-08 18:56:31 +01:00
|
|
|
}
|
|
|
|
|
2022-01-11 22:55:46 +01:00
|
|
|
func otherGenruleBp(genruleTarget string) map[string]string {
|
|
|
|
return map[string]string{
|
|
|
|
"other/Android.bp": fmt.Sprintf(`%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo.tool",
|
|
|
|
out: ["foo_tool.out"],
|
|
|
|
srcs: ["foo_tool.in"],
|
|
|
|
cmd: "cp $(in) $(out)",
|
|
|
|
}
|
2022-01-11 22:55:46 +01:00
|
|
|
%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "other.tool",
|
|
|
|
out: ["other_tool.out"],
|
|
|
|
srcs: ["other_tool.in"],
|
|
|
|
cmd: "cp $(in) $(out)",
|
2022-01-11 22:55:46 +01:00
|
|
|
}`, genruleTarget, genruleTarget),
|
2023-06-03 01:03:06 +02:00
|
|
|
"other/file.txt": "",
|
2021-09-08 16:36:41 +02:00
|
|
|
}
|
2022-01-11 22:55:46 +01:00
|
|
|
}
|
2021-09-08 16:36:41 +02:00
|
|
|
|
2022-01-11 22:55:46 +01:00
|
|
|
func TestGenruleCliVariableReplacement(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
|
|
|
genDir string
|
2022-05-13 23:20:20 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
2022-01-11 22:55:46 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
2022-09-21 23:01:49 +02:00
|
|
|
genDir: "$(RULEDIR)",
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
|
|
|
genDir: "$(RULEDIR)",
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
|
|
|
genDir: "$(RULEDIR)",
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
2021-09-08 16:36:41 +02:00
|
|
|
{
|
2022-01-11 22:55:46 +01:00
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
|
|
|
genDir: "$(RULEDIR)",
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.HostSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo.tool",
|
|
|
|
out: ["foo_tool.out"],
|
|
|
|
srcs: ["foo_tool.in"],
|
|
|
|
cmd: "cp $(in) $(out)",
|
|
|
|
}
|
|
|
|
|
2022-01-11 22:55:46 +01:00
|
|
|
%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out"],
|
|
|
|
srcs: ["foo.in"],
|
|
|
|
tools: [":foo.tool"],
|
|
|
|
cmd: "$(location :foo.tool) --genDir=$(genDir) arg $(in) $(out)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-01-11 22:55:46 +01:00
|
|
|
}`
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
moduleAttrs := AttrNameToString{
|
2022-01-31 15:37:29 +01:00
|
|
|
"cmd": fmt.Sprintf(`"$(location :foo.tool) --genDir=%s arg $(SRCS) $(OUTS)"`, tc.genDir),
|
|
|
|
"outs": `["foo.out"]`,
|
|
|
|
"srcs": `["foo.in"]`,
|
|
|
|
"tools": `[":foo.tool"]`,
|
|
|
|
}
|
|
|
|
|
2022-01-11 22:55:46 +01:00
|
|
|
expectedBazelTargets := []string{
|
2022-05-13 23:20:20 +02:00
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
2022-01-11 22:55:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType),
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"foo.tool", "other.tool"},
|
2022-01-11 22:55:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenruleLocationsLabel(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
2022-05-13 23:20:20 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
2022-01-11 22:55:46 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-11 22:55:46 +01:00
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.HostSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo.tools",
|
|
|
|
out: ["foo_tool.out", "foo_tool2.out"],
|
|
|
|
srcs: ["foo_tool.in"],
|
|
|
|
cmd: "cp $(in) $(out)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
|
2022-01-11 22:55:46 +01:00
|
|
|
%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out"],
|
|
|
|
srcs: ["foo.in"],
|
|
|
|
tools: [":foo.tools"],
|
|
|
|
cmd: "$(locations :foo.tools) -s $(out) $(in)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-01-11 22:55:46 +01:00
|
|
|
}`
|
|
|
|
|
2022-01-31 15:37:29 +01:00
|
|
|
for _, tc := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
fooAttrs := AttrNameToString{
|
2022-01-31 15:37:29 +01:00
|
|
|
"cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`,
|
|
|
|
"outs": `["foo.out"]`,
|
|
|
|
"srcs": `["foo.in"]`,
|
|
|
|
"tools": `[":foo.tools"]`,
|
|
|
|
}
|
2022-06-21 21:28:33 +02:00
|
|
|
fooToolsAttrs := AttrNameToString{
|
2022-01-31 15:37:29 +01:00
|
|
|
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
|
|
|
"outs": `[
|
2021-09-08 16:36:41 +02:00
|
|
|
"foo_tool.out",
|
|
|
|
"foo_tool2.out",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
2022-01-31 15:37:29 +01:00
|
|
|
"srcs": `["foo_tool.in"]`,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
2022-05-13 23:20:20 +02:00
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", fooAttrs, tc.hod),
|
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo.tools", fooToolsAttrs, tc.hod),
|
2022-01-11 22:55:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType, tc.moduleType),
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
2022-01-11 22:55:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenruleLocationsAbsoluteLabel(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
2022-05-13 23:20:20 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
2022-01-11 22:55:46 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-11 22:55:46 +01:00
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.HostSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out"],
|
|
|
|
srcs: ["foo.in"],
|
|
|
|
tool_files: [":foo.tool"],
|
|
|
|
cmd: "$(locations :foo.tool) -s $(out) $(in)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-01-11 22:55:46 +01:00
|
|
|
}`
|
|
|
|
|
2022-01-31 15:37:29 +01:00
|
|
|
for _, tc := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
moduleAttrs := AttrNameToString{
|
2022-01-11 22:55:46 +01:00
|
|
|
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
|
|
|
|
"outs": `["foo.out"]`,
|
|
|
|
"srcs": `["foo.in"]`,
|
|
|
|
"tools": `["//other:foo.tool"]`,
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
2022-05-13 23:20:20 +02:00
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
2022-01-11 22:55:46 +01:00
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
Filesystem: otherGenruleBp(tc.moduleType),
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//other:foo.tool"},
|
2022-01-11 22:55:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
2022-05-13 23:20:20 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
2022-01-11 22:55:46 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-11 22:55:46 +01:00
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.HostSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out"],
|
2023-06-03 01:03:06 +02:00
|
|
|
srcs: [":other.tool", "other/file.txt",],
|
2021-09-08 16:36:41 +02:00
|
|
|
tool_files: [":foo.tool"],
|
2023-06-03 01:03:06 +02:00
|
|
|
cmd: "$(locations :foo.tool) $(location other/file.txt) -s $(out) $(location :other.tool)",
|
2021-09-08 16:36:41 +02:00
|
|
|
bazel_module: { bp2build_available: true },
|
2022-01-11 22:55:46 +01:00
|
|
|
}`
|
|
|
|
|
2022-01-31 15:37:29 +01:00
|
|
|
for _, tc := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
moduleAttrs := AttrNameToString{
|
2023-06-03 01:03:06 +02:00
|
|
|
"cmd": `"$(locations //other:foo.tool) $(location //other:file.txt) -s $(OUTS) $(location //other:other.tool)"`,
|
|
|
|
"outs": `["foo.out"]`,
|
|
|
|
"srcs": `[
|
|
|
|
"//other:other.tool",
|
|
|
|
"//other:file.txt",
|
|
|
|
]`,
|
2022-01-11 22:55:46 +01:00
|
|
|
"tools": `["//other:foo.tool"]`,
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
2022-05-13 23:20:20 +02:00
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
2022-01-11 22:55:46 +01:00
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
Filesystem: otherGenruleBp(tc.moduleType),
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
|
2022-01-11 22:55:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
2022-05-13 23:20:20 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
2022-01-11 22:55:46 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-11 22:55:46 +01:00
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.HostSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out"],
|
|
|
|
srcs: ["foo.in"],
|
|
|
|
tool_files: [":foo.tool", ":other.tool"],
|
|
|
|
cmd: "$(location) -s $(out) $(in)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-01-11 22:55:46 +01:00
|
|
|
}`
|
|
|
|
|
2022-01-31 15:37:29 +01:00
|
|
|
for _, tc := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
moduleAttrs := AttrNameToString{
|
2022-01-11 22:55:46 +01:00
|
|
|
"cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`,
|
|
|
|
"outs": `["foo.out"]`,
|
|
|
|
"srcs": `["foo.in"]`,
|
|
|
|
"tools": `[
|
2021-09-08 16:36:41 +02:00
|
|
|
"//other:foo.tool",
|
|
|
|
"//other:other.tool",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
2022-05-13 23:20:20 +02:00
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
2022-01-11 22:55:46 +01:00
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
Filesystem: otherGenruleBp(tc.moduleType),
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
|
2022-01-11 22:55:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
2022-05-13 23:20:20 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
2022-01-11 22:55:46 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-11 22:55:46 +01:00
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.HostSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out"],
|
|
|
|
srcs: ["foo.in"],
|
2022-01-11 22:55:46 +01:00
|
|
|
tool_files: [":foo.tool", ":other.tool"],
|
2021-09-08 16:36:41 +02:00
|
|
|
cmd: "$(locations) -s $(out) $(in)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-01-11 22:55:46 +01:00
|
|
|
}`
|
|
|
|
|
2022-01-31 15:37:29 +01:00
|
|
|
for _, tc := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
moduleAttrs := AttrNameToString{
|
2022-01-11 22:55:46 +01:00
|
|
|
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
|
|
|
|
"outs": `["foo.out"]`,
|
|
|
|
"srcs": `["foo.in"]`,
|
|
|
|
"tools": `[
|
2021-09-08 16:36:41 +02:00
|
|
|
"//other:foo.tool",
|
|
|
|
"//other:other.tool",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
2022-05-13 23:20:20 +02:00
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
2022-01-11 22:55:46 +01:00
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
Filesystem: otherGenruleBp(tc.moduleType),
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//other:foo.tool", "//other:other.tool"},
|
2022-01-11 22:55:46 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenruleWithoutToolsOrToolFiles(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
2022-05-13 23:20:20 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
2022-01-11 22:55:46 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.DeviceSupported,
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-11 22:55:46 +01:00
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
2022-05-13 23:20:20 +02:00
|
|
|
hod: android.HostSupported,
|
2022-01-11 22:55:46 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `%s {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out"],
|
|
|
|
srcs: ["foo.in"],
|
|
|
|
cmd: "cp $(in) $(out)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
2022-01-11 22:55:46 +01:00
|
|
|
}`
|
|
|
|
|
2022-01-31 15:37:29 +01:00
|
|
|
for _, tc := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
moduleAttrs := AttrNameToString{
|
2022-01-11 22:55:46 +01:00
|
|
|
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
|
|
|
"outs": `["foo.out"]`,
|
|
|
|
"srcs": `["foo.in"]`,
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
2022-05-13 23:20:20 +02:00
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
2022-01-31 15:37:29 +01:00
|
|
|
}
|
2021-09-08 16:36:41 +02:00
|
|
|
|
2022-01-11 22:55:46 +01:00
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
2022-01-11 22:55:46 +01:00
|
|
|
})
|
2021-11-08 18:56:31 +01:00
|
|
|
})
|
2021-09-08 16:36:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 22:55:46 +01:00
|
|
|
func TestGenruleBp2BuildInlinesDefaults(t *testing.T) {
|
2022-06-21 21:28:33 +02:00
|
|
|
testCases := []Bp2buildTestCase{
|
2021-09-08 16:36:41 +02:00
|
|
|
{
|
2022-06-21 21:28:33 +02:00
|
|
|
Description: "genrule applies properties from a genrule_defaults dependency if not specified",
|
|
|
|
Blueprint: `genrule_defaults {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "gen_defaults",
|
|
|
|
cmd: "do-something $(in) $(out)",
|
|
|
|
}
|
|
|
|
genrule {
|
|
|
|
name: "gen",
|
|
|
|
out: ["out"],
|
|
|
|
srcs: ["in1"],
|
|
|
|
defaults: ["gen_defaults"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"cmd": `"do-something $(SRCS) $(OUTS)"`,
|
|
|
|
"outs": `["out"]`,
|
|
|
|
"srcs": `["in1"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-06-21 21:28:33 +02:00
|
|
|
Description: "genrule does merges properties from a genrule_defaults dependency, latest-first",
|
|
|
|
Blueprint: `genrule_defaults {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "gen_defaults",
|
|
|
|
out: ["out-from-defaults"],
|
|
|
|
srcs: ["in-from-defaults"],
|
|
|
|
cmd: "cmd-from-defaults",
|
|
|
|
}
|
|
|
|
genrule {
|
|
|
|
name: "gen",
|
|
|
|
out: ["out"],
|
|
|
|
srcs: ["in1"],
|
|
|
|
defaults: ["gen_defaults"],
|
|
|
|
cmd: "do-something $(in) $(out)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"cmd": `"do-something $(SRCS) $(OUTS)"`,
|
|
|
|
"outs": `[
|
2021-09-08 16:36:41 +02:00
|
|
|
"out-from-defaults",
|
|
|
|
"out",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs": `[
|
2021-09-08 16:36:41 +02:00
|
|
|
"in-from-defaults",
|
|
|
|
"in1",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-06-21 21:28:33 +02:00
|
|
|
Description: "genrule applies properties from list of genrule_defaults",
|
|
|
|
Blueprint: `genrule_defaults {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "gen_defaults1",
|
|
|
|
cmd: "cp $(in) $(out)",
|
|
|
|
}
|
|
|
|
|
|
|
|
genrule_defaults {
|
|
|
|
name: "gen_defaults2",
|
|
|
|
srcs: ["in1"],
|
|
|
|
}
|
|
|
|
|
|
|
|
genrule {
|
|
|
|
name: "gen",
|
|
|
|
out: ["out"],
|
|
|
|
defaults: ["gen_defaults1", "gen_defaults2"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
|
|
|
"outs": `["out"]`,
|
|
|
|
"srcs": `["in1"]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
{
|
2022-06-21 21:28:33 +02:00
|
|
|
Description: "genrule applies properties from genrule_defaults transitively",
|
|
|
|
Blueprint: `genrule_defaults {
|
2021-09-08 16:36:41 +02:00
|
|
|
name: "gen_defaults1",
|
|
|
|
defaults: ["gen_defaults2"],
|
|
|
|
cmd: "cmd1 $(in) $(out)", // overrides gen_defaults2's cmd property value.
|
|
|
|
}
|
|
|
|
|
|
|
|
genrule_defaults {
|
|
|
|
name: "gen_defaults2",
|
|
|
|
defaults: ["gen_defaults3"],
|
|
|
|
cmd: "cmd2 $(in) $(out)",
|
|
|
|
out: ["out-from-2"],
|
|
|
|
srcs: ["in1"],
|
|
|
|
}
|
|
|
|
|
|
|
|
genrule_defaults {
|
|
|
|
name: "gen_defaults3",
|
|
|
|
out: ["out-from-3"],
|
|
|
|
srcs: ["srcs-from-3"],
|
|
|
|
}
|
|
|
|
|
|
|
|
genrule {
|
|
|
|
name: "gen",
|
|
|
|
out: ["out"],
|
|
|
|
defaults: ["gen_defaults1"],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`,
|
2022-06-21 21:28:33 +02:00
|
|
|
ExpectedBazelTargets: []string{
|
|
|
|
MakeBazelTargetNoRestrictions("genrule", "gen", AttrNameToString{
|
2021-11-08 18:56:31 +01:00
|
|
|
"cmd": `"cmd1 $(SRCS) $(OUTS)"`,
|
|
|
|
"outs": `[
|
2021-09-08 16:36:41 +02:00
|
|
|
"out-from-3",
|
|
|
|
"out-from-2",
|
|
|
|
"out",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
"srcs": `[
|
2021-09-08 16:36:41 +02:00
|
|
|
"srcs-from-3",
|
|
|
|
"in1",
|
2021-11-08 18:56:31 +01:00
|
|
|
]`,
|
|
|
|
}),
|
|
|
|
},
|
2021-09-08 16:36:41 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
2022-06-21 21:28:33 +02:00
|
|
|
t.Run(testCase.Description, func(t *testing.T) {
|
2021-11-08 18:56:31 +01:00
|
|
|
runGenruleTestCase(t, testCase)
|
|
|
|
})
|
2021-09-08 16:36:41 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-17 21:29:15 +02:00
|
|
|
|
|
|
|
func TestCcGenruleArchAndExcludeSrcs(t *testing.T) {
|
|
|
|
name := "cc_genrule with arch"
|
|
|
|
bp := `
|
|
|
|
cc_genrule {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"foo1.in",
|
|
|
|
"foo2.in",
|
|
|
|
],
|
|
|
|
exclude_srcs: ["foo2.in"],
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: [
|
|
|
|
"foo1_arch.in",
|
|
|
|
"foo2_arch.in",
|
|
|
|
],
|
|
|
|
exclude_srcs: ["foo2_arch.in"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
cmd: "cat $(in) > $(out)",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`
|
|
|
|
|
|
|
|
expectedBazelAttrs := AttrNameToString{
|
|
|
|
"srcs": `["foo1.in"] + select({
|
|
|
|
"//build/bazel/platforms/arch:arm": ["foo1_arch.in"],
|
|
|
|
"//conditions:default": [],
|
|
|
|
})`,
|
|
|
|
"cmd": `"cat $(SRCS) > $(OUTS)"`,
|
|
|
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions("genrule", "foo", expectedBazelAttrs),
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: "cc_genrule",
|
|
|
|
ModuleTypeUnderTestFactory: cc.GenRuleFactory,
|
|
|
|
Blueprint: bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-07-18 17:39:30 +02:00
|
|
|
|
|
|
|
func TestGenruleWithExportIncludeDirs(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
|
|
|
hod android.HostOrDeviceSupported
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
|
|
|
hod: android.DeviceSupported,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
|
|
|
hod: android.DeviceSupported,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
|
|
|
hod: android.HostSupported,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
dir := "baz"
|
|
|
|
|
|
|
|
bp := `%s {
|
|
|
|
name: "foo",
|
|
|
|
out: ["foo.out.h"],
|
|
|
|
srcs: ["foo.in"],
|
|
|
|
cmd: "cp $(in) $(out)",
|
|
|
|
export_include_dirs: ["foo", "bar", "."],
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}`
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
moduleAttrs := AttrNameToString{
|
|
|
|
"cmd": `"cp $(SRCS) $(OUTS)"`,
|
|
|
|
"outs": `["foo.out.h"]`,
|
|
|
|
"srcs": `["foo.in"]`,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
|
|
|
makeBazelTargetHostOrDevice("cc_library_headers", "foo__header_library", AttrNameToString{
|
|
|
|
"hdrs": `[":foo"]`,
|
|
|
|
"export_includes": `[
|
|
|
|
"foo",
|
|
|
|
"baz/foo",
|
|
|
|
"bar",
|
|
|
|
"baz/bar",
|
|
|
|
".",
|
|
|
|
"baz",
|
|
|
|
]`,
|
|
|
|
},
|
|
|
|
tc.hod),
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
|
|
|
|
Bp2buildTestCase{
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
Filesystem: map[string]string{
|
|
|
|
filepath.Join(dir, "Android.bp"): fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
},
|
|
|
|
Dir: dir,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-08-14 20:37:54 +02:00
|
|
|
|
2023-08-15 20:59:24 +02:00
|
|
|
func TestGenruleWithSoongConfigVariableConfiguredCmd(t *testing.T) {
|
2023-08-14 20:37:54 +02:00
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
|
|
|
hod android.HostOrDeviceSupported
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
|
|
|
hod: android.DeviceSupported,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
|
|
|
hod: android.DeviceSupported,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
|
|
|
hod: android.HostSupported,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `
|
|
|
|
soong_config_module_type {
|
|
|
|
name: "my_genrule",
|
|
|
|
module_type: "%s",
|
|
|
|
config_namespace: "my_namespace",
|
|
|
|
bool_variables: ["my_variable"],
|
|
|
|
properties: ["cmd"],
|
|
|
|
}
|
|
|
|
|
|
|
|
my_genrule {
|
|
|
|
name: "foo",
|
|
|
|
out: ["foo.txt"],
|
|
|
|
cmd: "echo 'no variable' > $(out)",
|
|
|
|
soong_config_variables: {
|
|
|
|
my_variable: {
|
|
|
|
cmd: "echo 'with variable' > $(out)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
moduleAttrs := AttrNameToString{
|
|
|
|
"cmd": `select({
|
|
|
|
"//build/bazel/product_config/config_settings:my_namespace__my_variable": "echo 'with variable' > $(OUTS)",
|
|
|
|
"//conditions:default": "echo 'no variable' > $(OUTS)",
|
|
|
|
})`,
|
|
|
|
"outs": `["foo.txt"]`,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
|
|
|
|
Bp2buildTestCase{
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-08-15 20:59:24 +02:00
|
|
|
|
|
|
|
func TestGenruleWithProductVariableConfiguredCmd(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
moduleType string
|
|
|
|
factory android.ModuleFactory
|
|
|
|
hod android.HostOrDeviceSupported
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
moduleType: "genrule",
|
|
|
|
factory: genrule.GenRuleFactory,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "cc_genrule",
|
|
|
|
factory: cc.GenRuleFactory,
|
|
|
|
hod: android.DeviceSupported,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule",
|
|
|
|
factory: java.GenRuleFactory,
|
|
|
|
hod: android.DeviceSupported,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
moduleType: "java_genrule_host",
|
|
|
|
factory: java.GenRuleFactoryHost,
|
|
|
|
hod: android.HostSupported,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bp := `
|
|
|
|
|
|
|
|
%s {
|
|
|
|
name: "foo",
|
|
|
|
out: ["foo.txt"],
|
|
|
|
cmd: "echo 'no variable' > $(out)",
|
|
|
|
product_variables: {
|
|
|
|
debuggable: {
|
|
|
|
cmd: "echo 'with variable' > $(out)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
moduleAttrs := AttrNameToString{
|
|
|
|
"cmd": `select({
|
|
|
|
"//build/bazel/product_config/config_settings:debuggable": "echo 'with variable' > $(OUTS)",
|
|
|
|
"//conditions:default": "echo 'no variable' > $(OUTS)",
|
|
|
|
})`,
|
|
|
|
"outs": `["foo.txt"]`,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run(tc.moduleType, func(t *testing.T) {
|
|
|
|
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
|
|
|
|
Bp2buildTestCase{
|
|
|
|
Blueprint: fmt.Sprintf(bp, tc.moduleType),
|
|
|
|
ModuleTypeUnderTest: tc.moduleType,
|
|
|
|
ModuleTypeUnderTestFactory: tc.factory,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-08-18 00:35:04 +02:00
|
|
|
|
|
|
|
func TestGenruleWithModulesInNamespaces(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
genrule {
|
|
|
|
name: "mygenrule",
|
|
|
|
cmd: "echo $(location //mynamespace:mymodule) > $(out)",
|
|
|
|
srcs: ["//mynamespace:mymodule"],
|
|
|
|
out: ["myout"],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
fs := map[string]string{
|
|
|
|
"mynamespace/Android.bp": `soong_namespace {}`,
|
|
|
|
"mynamespace/dir/Android.bp": `cc_binary {name: "mymodule"}`,
|
|
|
|
}
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions("genrule", "mygenrule", AttrNameToString{
|
|
|
|
// The fully qualified soong label is <namespace>:<module_name>
|
|
|
|
// - here the prefix is mynamespace
|
|
|
|
// The fully qualifed bazel label is <package>:<module_name>
|
|
|
|
// - here the prefix is mynamespace/dir, since there is a BUILD file at each level of this FS path
|
|
|
|
"cmd": `"echo $(location //mynamespace/dir:mymodule) > $(OUTS)"`,
|
|
|
|
"outs": `["myout"]`,
|
|
|
|
"srcs": `["//mynamespace/dir:mymodule"]`,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("genrule that uses module from a different namespace", func(t *testing.T) {
|
|
|
|
runGenruleTestCase(t, Bp2buildTestCase{
|
|
|
|
Blueprint: bp,
|
|
|
|
Filesystem: fs,
|
|
|
|
ModuleTypeUnderTest: "genrule",
|
|
|
|
ModuleTypeUnderTestFactory: genrule.GenRuleFactory,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
2023-09-19 03:12:48 +02:00
|
|
|
StubbedBuildDefinitions: []string{"//mynamespace/dir:mymodule"},
|
2023-08-18 00:35:04 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|