bp2build: framework for generating BazelTargetModules.
This CL creates the framework necessary for generating BazelTargetModules from regular Soong Android modules. BazelTargetModules are code-generated into Bazel targets in BUILD files. See the follow-up CL for examples of creating filegroup/genrule BazelTargetModules. Test: GENERATE_BAZEL_FILES=true m nothing # creates out/soong/bp2build with no BUILD files, because there are no BazelTargetModules in the module graph. Change-Id: I33a96365bd439043b13af6db9e439592e9983188
This commit is contained in:
@@ -200,7 +200,7 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
|
||||
_, errs = ctx.PrepareBuildActions(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context)[dir]
|
||||
bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, false)[dir]
|
||||
if g, w := len(bazelTargets), 1; g != w {
|
||||
t.Fatalf("Expected %d bazel target, got %d", w, g)
|
||||
}
|
||||
@@ -210,7 +210,58 @@ func TestGenerateSoongModuleTargets(t *testing.T) {
|
||||
t.Errorf(
|
||||
"Expected generated Bazel target to be '%s', got '%s'",
|
||||
testCase.expectedBazelTarget,
|
||||
actualBazelTarget,
|
||||
actualBazelTarget.content,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateBazelTargetModules(t *testing.T) {
|
||||
testCases := []struct {
|
||||
bp string
|
||||
expectedBazelTarget string
|
||||
}{
|
||||
{
|
||||
bp: `custom {
|
||||
name: "foo",
|
||||
string_list_prop: ["a", "b"],
|
||||
string_prop: "a",
|
||||
}`,
|
||||
expectedBazelTarget: `custom(
|
||||
name = "foo",
|
||||
string_list_prop = [
|
||||
"a",
|
||||
"b",
|
||||
],
|
||||
string_prop = "a",
|
||||
)`,
|
||||
},
|
||||
}
|
||||
|
||||
dir := "."
|
||||
for _, testCase := range testCases {
|
||||
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
|
||||
ctx := android.NewTestContext(config)
|
||||
ctx.RegisterModuleType("custom", customModuleFactory)
|
||||
ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutator)
|
||||
ctx.RegisterForBazelConversion()
|
||||
|
||||
_, errs := ctx.ParseFileList(dir, []string{"Android.bp"})
|
||||
android.FailIfErrored(t, errs)
|
||||
_, errs = ctx.ResolveDependencies(config)
|
||||
android.FailIfErrored(t, errs)
|
||||
|
||||
bazelTargets := GenerateSoongModuleTargets(ctx.Context.Context, true)[dir]
|
||||
if g, w := len(bazelTargets), 1; g != w {
|
||||
t.Fatalf("Expected %d bazel target, got %d", w, g)
|
||||
}
|
||||
|
||||
actualBazelTarget := bazelTargets[0]
|
||||
if actualBazelTarget.content != testCase.expectedBazelTarget {
|
||||
t.Errorf(
|
||||
"Expected generated Bazel target to be '%s', got '%s'",
|
||||
testCase.expectedBazelTarget,
|
||||
actualBazelTarget.content,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user