diff --git a/bp2build/prebuilt_etc_conversion_test.go b/bp2build/prebuilt_etc_conversion_test.go index a00197276..2e4b22119 100644 --- a/bp2build/prebuilt_etc_conversion_test.go +++ b/bp2build/prebuilt_etc_conversion_test.go @@ -49,7 +49,7 @@ prebuilt_etc { "filename": `"tz_version"`, "installable": `False`, "src": `"version/tz_version"`, - "sub_dir": `"tz"`, + "dir": `"etc/tz"`, })}}) } @@ -83,7 +83,7 @@ prebuilt_etc { "//build/bazel/platforms/arch:arm64": "arm64", "//conditions:default": "version/tz_version", })`, - "sub_dir": `"tz"`, + "dir": `"etc/tz"`, })}}) } @@ -125,6 +125,59 @@ prebuilt_etc { "//build/bazel/platforms/os_arch:linux_bionic_arm64": "darwin_or_arm64", "//conditions:default": "version/tz_version", })`, - "sub_dir": `"tz"`, + "dir": `"etc/tz"`, + })}}) +} + +func runPrebuiltUsrShareTestCase(t *testing.T, tc bp2buildTestCase) { + t.Helper() + (&tc).moduleTypeUnderTest = "prebuilt_usr_share" + (&tc).moduleTypeUnderTestFactory = etc.PrebuiltUserShareFactory + runBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) +} + +func registerPrebuiltUsrShareModuleTypes(ctx android.RegistrationContext) { +} + +func TestPrebuiltUsrShareSimple(t *testing.T) { + runPrebuiltUsrShareTestCase(t, bp2buildTestCase{ + description: "prebuilt_usr_share - simple example", + filesystem: map[string]string{}, + blueprint: ` +prebuilt_usr_share { + name: "apex_tz_version", + src: "version/tz_version", + filename: "tz_version", + sub_dir: "tz", + installable: false, +} +`, + expectedBazelTargets: []string{ + makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ + "filename": `"tz_version"`, + "installable": `False`, + "src": `"version/tz_version"`, + "dir": `"usr/share/tz"`, + })}}) +} + +func TestPrebuiltEtcNoSubdir(t *testing.T) { + runPrebuiltEtcTestCase(t, bp2buildTestCase{ + description: "prebuilt_etc - no subdir", + filesystem: map[string]string{}, + blueprint: ` +prebuilt_etc { + name: "apex_tz_version", + src: "version/tz_version", + filename: "tz_version", + installable: false, +} +`, + expectedBazelTargets: []string{ + makeBazelTarget("prebuilt_file", "apex_tz_version", attrNameToString{ + "filename": `"tz_version"`, + "installable": `False`, + "src": `"version/tz_version"`, + "dir": `"etc"`, })}}) } diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index aa4b889bb..719771f4c 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -474,6 +474,7 @@ func PrebuiltUserShareFactory() android.Module { // This module is device-only android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) android.InitDefaultableModule(module) + android.InitBazelModule(module) return module } @@ -668,25 +669,17 @@ func generatePrebuiltSnapshot(s snapshot.SnapshotSingleton, ctx android.Singleto // For Bazel / bp2build -type bazelPrebuiltEtcAttributes struct { +type bazelPrebuiltFileAttributes struct { Src bazel.LabelAttribute Filename string - Sub_dir string + Dir string Installable bazel.BoolAttribute } // ConvertWithBp2build performs bp2build conversion of PrebuiltEtc -func (p *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) { - // All prebuilt_* modules are PrebuiltEtc, but at this time, we only convert prebuilt_etc modules. - if p.installDirBase != "etc" { - return - } - - prebuiltEtcBp2BuildInternal(ctx, p) -} - -func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *PrebuiltEtc) { - var srcLabelAttribute bazel.LabelAttribute +// All prebuilt_* modules are PrebuiltEtc, which we treat uniformily as *PrebuiltFile* +func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.TopDownMutatorContext) { + var src bazel.LabelAttribute for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltEtcProperties{}) { for config, p := range configToProps { props, ok := p.(*prebuiltEtcProperties) @@ -695,7 +688,7 @@ func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *Preb } if props.Src != nil { label := android.BazelLabelForModuleSrcSingle(ctx, *props.Src) - srcLabelAttribute.SetSelectValue(axis, config, label) + src.SetSelectValue(axis, config, label) } } } @@ -705,21 +698,25 @@ func prebuiltEtcBp2BuildInternal(ctx android.TopDownMutatorContext, module *Preb filename = *module.properties.Filename } - var subDir string - if module.subdirProperties.Sub_dir != nil { - subDir = *module.subdirProperties.Sub_dir + var dir = module.installDirBase + // prebuilt_file supports only `etc` or `usr/share` + if !(dir == "etc" || dir == "usr/share") { + return + } + if subDir := module.subdirProperties.Sub_dir; subDir != nil { + dir = dir + "/" + *subDir } - var installableBoolAttribute bazel.BoolAttribute - if module.properties.Installable != nil { - installableBoolAttribute.Value = module.properties.Installable + var installable bazel.BoolAttribute + if install := module.properties.Installable; install != nil { + installable.Value = install } - attrs := &bazelPrebuiltEtcAttributes{ - Src: srcLabelAttribute, + attrs := &bazelPrebuiltFileAttributes{ + Src: src, Filename: filename, - Sub_dir: subDir, - Installable: installableBoolAttribute, + Dir: dir, + Installable: installable, } props := bazel.BazelTargetModuleProperties{