Handle filename variations for prebuilt_etc in bp2build
Bp2build now handles these cases: -filename is specified as a property -if filename is not specified and filename_from_src = true, filename is set as the src -filename defaults to the module name otherwise Bug: 228353188 Test: bp2build/prebuilt_etc_conversion_test.go Change-Id: Ia4c9b2c89f100e4ed9363dc3ba20ea501b776216
This commit is contained in:
parent
6faa161557
commit
993872a5d7
2 changed files with 107 additions and 7 deletions
|
@ -181,3 +181,87 @@ prebuilt_etc {
|
|||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFilenameAsProperty(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - filename is specified as a property ",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
src: "fooSrc",
|
||||
filename: "fooFileName",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename": `"fooFileName"`,
|
||||
"src": `"fooSrc"`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFileNameFromSrc(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - filename_from_src is true ",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
filename_from_src: true,
|
||||
src: "fooSrc",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename": `"fooSrc"`,
|
||||
"src": `"fooSrc"`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFileNameFromSrcMultipleSrcs(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - filename_from_src is true but there are multiple srcs",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
filename_from_src: true,
|
||||
arch: {
|
||||
arm: {
|
||||
src: "barSrc",
|
||||
},
|
||||
arm64: {
|
||||
src: "bazSrc",
|
||||
},
|
||||
}
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename_from_src": `True`,
|
||||
"dir": `"etc"`,
|
||||
"src": `select({
|
||||
"//build/bazel/platforms/arch:arm": "barSrc",
|
||||
"//build/bazel/platforms/arch:arm64": "bazSrc",
|
||||
"//conditions:default": None,
|
||||
})`,
|
||||
})}})
|
||||
}
|
||||
|
||||
func TestFilenameFromModuleName(t *testing.T) {
|
||||
runPrebuiltEtcTestCase(t, Bp2buildTestCase{
|
||||
Description: "prebuilt_etc - neither filename nor filename_from_src are specified ",
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
prebuilt_etc {
|
||||
name: "foo",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("prebuilt_file", "foo", AttrNameToString{
|
||||
"filename": `"foo"`,
|
||||
"dir": `"etc"`,
|
||||
})}})
|
||||
}
|
||||
|
|
|
@ -670,10 +670,11 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto
|
|||
// For Bazel / bp2build
|
||||
|
||||
type bazelPrebuiltFileAttributes struct {
|
||||
Src bazel.LabelAttribute
|
||||
Filename string
|
||||
Dir string
|
||||
Installable bazel.BoolAttribute
|
||||
Src bazel.LabelAttribute
|
||||
Filename bazel.LabelAttribute
|
||||
Dir string
|
||||
Installable bazel.BoolAttribute
|
||||
Filename_from_src bazel.BoolAttribute
|
||||
}
|
||||
|
||||
// ConvertWithBp2build performs bp2build conversion of PrebuiltEtc
|
||||
|
@ -694,8 +695,18 @@ func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext
|
|||
}
|
||||
|
||||
var filename string
|
||||
if module.properties.Filename != nil {
|
||||
filename = *module.properties.Filename
|
||||
var filenameFromSrc bool
|
||||
moduleProps := module.properties
|
||||
|
||||
if moduleProps.Filename != nil && *moduleProps.Filename != "" {
|
||||
filename = *moduleProps.Filename
|
||||
} else if moduleProps.Filename_from_src != nil && *moduleProps.Filename_from_src {
|
||||
if moduleProps.Src != nil {
|
||||
filename = *moduleProps.Src
|
||||
}
|
||||
filenameFromSrc = true
|
||||
} else {
|
||||
filename = ctx.ModuleName()
|
||||
}
|
||||
|
||||
var dir = module.installDirBase
|
||||
|
@ -714,11 +725,16 @@ func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext
|
|||
|
||||
attrs := &bazelPrebuiltFileAttributes{
|
||||
Src: src,
|
||||
Filename: filename,
|
||||
Dir: dir,
|
||||
Installable: installable,
|
||||
}
|
||||
|
||||
if filename != "" {
|
||||
attrs.Filename = bazel.LabelAttribute{Value: &bazel.Label{Label: filename}}
|
||||
} else if filenameFromSrc {
|
||||
attrs.Filename_from_src = bazel.BoolAttribute{Value: moduleProps.Filename_from_src}
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "prebuilt_file",
|
||||
Bzl_load_location: "//build/bazel/rules:prebuilt_file.bzl",
|
||||
|
|
Loading…
Reference in a new issue