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
diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go
index 719771f..b2361ce 100644
--- a/etc/prebuilt_etc.go
+++ b/etc/prebuilt_etc.go
@@ -670,10 +670,11 @@
// 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 @@
}
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 @@
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",