Bp2Build common properties auto-handling

Introduce `commonAttributes` & `fillCommonBp2BuildModuleAttrs used in
CreateBazelTargetModule

Adapt `bp2BuildInfo` to use `commonAttrs` instead of `Name`.
And thus also all downstream users of `CreateBazelTargetModule`.

As initial user, the Soong `required` property will be
translated to Bazel's `data`.

Bug: 198146582, 196091467
Test: build_converstion_test.go:TestCommonBp2BuildModuleAttrs
Test: go test
Test: mixed_{libc,droid}.sh
Change-Id: Ib500e40f7e2cb48c459f1ebe3188962fc41ec124
This commit is contained in:
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
2021-08-31 20:30:36 +00:00
parent 9c03ef7790
commit 447f6c99c9
18 changed files with 229 additions and 51 deletions

View File

@@ -15,10 +15,12 @@
package bp2build
import (
"android/soong/android"
"fmt"
"strings"
"testing"
"android/soong/android"
"android/soong/python"
)
func TestGenerateSoongModuleTargets(t *testing.T) {
@@ -1215,3 +1217,133 @@ func TestGlobExcludeSrcs(t *testing.T) {
}
}
}
func TestCommonBp2BuildModuleAttrs(t *testing.T) {
testCases := []bp2buildTestCase{
{
description: "Required into data test",
moduleTypeUnderTest: "filegroup",
moduleTypeUnderTestFactory: android.FileGroupFactory,
moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
blueprint: `filegroup {
name: "reqd",
}
filegroup {
name: "fg_foo",
required: ["reqd"],
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{`filegroup(
name = "fg_foo",
data = [":reqd"],
)`,
`filegroup(
name = "reqd",
)`,
},
},
{
description: "Required via arch into data test",
moduleTypeUnderTest: "python_library",
moduleTypeUnderTestFactory: python.PythonLibraryFactory,
moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build,
blueprint: `python_library {
name: "reqdx86",
bazel_module: { bp2build_available: false, },
}
python_library {
name: "reqdarm",
bazel_module: { bp2build_available: false, },
}
python_library {
name: "fg_foo",
arch: {
arm: {
required: ["reqdarm"],
},
x86: {
required: ["reqdx86"],
},
},
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{`py_library(
name = "fg_foo",
data = select({
"//build/bazel/platforms/arch:arm": [":reqdarm"],
"//build/bazel/platforms/arch:x86": [":reqdx86"],
"//conditions:default": [],
}),
srcs_version = "PY3",
)`,
},
},
{
description: "Required appended to data test",
moduleTypeUnderTest: "python_library",
moduleTypeUnderTestFactory: python.PythonLibraryFactory,
moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build,
blueprint: `python_library {
name: "reqd",
srcs: ["src.py"],
}
python_library {
name: "fg_foo",
data: ["data.bin"],
required: ["reqd"],
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
`py_library(
name = "fg_foo",
data = [
"data.bin",
":reqd",
],
srcs_version = "PY3",
)`,
`py_library(
name = "reqd",
srcs = ["src.py"],
srcs_version = "PY3",
)`,
},
filesystem: map[string]string{
"data.bin": "",
"src.py": "",
},
},
{
description: "All props-to-attrs at once together test",
moduleTypeUnderTest: "filegroup",
moduleTypeUnderTestFactory: android.FileGroupFactory,
moduleTypeUnderTestBp2BuildMutator: android.FilegroupBp2Build,
blueprint: `filegroup {
name: "reqd"
}
filegroup {
name: "fg_foo",
required: ["reqd"],
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: []string{
`filegroup(
name = "fg_foo",
data = [":reqd"],
)`,
`filegroup(
name = "reqd",
)`,
},
filesystem: map[string]string{},
},
}
for _, test := range testCases {
runBp2BuildTestCaseSimple(t, test)
}
}