diff --git a/bp2build/prebuilt_etc_conversion_test.go b/bp2build/prebuilt_etc_conversion_test.go index e2373038a..030dbcca3 100644 --- a/bp2build/prebuilt_etc_conversion_test.go +++ b/bp2build/prebuilt_etc_conversion_test.go @@ -26,10 +26,17 @@ func runPrebuiltEtcTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() (&tc).ModuleTypeUnderTest = "prebuilt_etc" (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltEtcFactory - RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) + RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc) } -func registerPrebuiltEtcModuleTypes(ctx android.RegistrationContext) { +func runPrebuiltRootHostTestCase(t *testing.T, tc Bp2buildTestCase) { + t.Helper() + (&tc).ModuleTypeUnderTest = "prebuilt_root_host" + (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltRootHostFactory + RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc) +} + +func registerPrebuiltModuleTypes(ctx android.RegistrationContext) { } func TestPrebuiltEtcSimple(t *testing.T) { @@ -160,7 +167,7 @@ func runPrebuiltUsrShareTestCase(t *testing.T, tc Bp2buildTestCase) { t.Helper() (&tc).ModuleTypeUnderTest = "prebuilt_usr_share" (&tc).ModuleTypeUnderTestFactory = etc.PrebuiltUserShareFactory - RunBp2BuildTestCase(t, registerPrebuiltEtcModuleTypes, tc) + RunBp2BuildTestCase(t, registerPrebuiltModuleTypes, tc) } func registerPrebuiltUsrShareModuleTypes(ctx android.RegistrationContext) { @@ -360,3 +367,30 @@ prebuilt_etc { ExpectedBazelTargets: []string{}, }) } + +func TestPrebuiltRootHostWithWildCardInSrc(t *testing.T) { + runPrebuiltRootHostTestCase(t, Bp2buildTestCase{ + Description: "prebuilt_root_host - src string has wild card", + Filesystem: map[string]string{ + "prh.dat": "", + }, + Blueprint: ` +prebuilt_root_host { + name: "prh_test", + src: "*.dat", + filename_from_src: true, + relative_install_path: "test/install/path", + bazel_module: { bp2build_available: true }, +} +`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("prebuilt_file", "prh_test", AttrNameToString{ + "filename": `"prh.dat"`, + "src": `"prh.dat"`, + "dir": `"./test/install/path"`, + "target_compatible_with": `select({ + "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], + "//conditions:default": [], + })`, + })}}) +} diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 94235319a..ca2844244 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -508,6 +508,7 @@ func PrebuiltRootHostFactory() android.Module { // This module is host-only android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) android.InitDefaultableModule(module) + android.InitBazelModule(module) return module } @@ -759,7 +760,7 @@ func (module *PrebuiltEtc) Bp2buildHelper(ctx android.Bp2buildMutatorContext) (* filename = *moduleProps.Filename } else if moduleProps.Filename_from_src != nil && *moduleProps.Filename_from_src { if moduleProps.Src != nil { - filename = *moduleProps.Src + filename = android.BazelLabelForModuleSrcSingle(ctx, *moduleProps.Src).Label } filenameFromSrc = true } else { @@ -767,8 +768,8 @@ func (module *PrebuiltEtc) Bp2buildHelper(ctx android.Bp2buildMutatorContext) (* } var dir = module.installDirBase - if subDir := module.subdirProperties.Sub_dir; subDir != nil { - dir = dir + "/" + *subDir + if module.SubDir() != "" { + dir = dir + "/" + module.SubDir() } var installable bazel.BoolAttribute @@ -796,8 +797,9 @@ func (module *PrebuiltEtc) Bp2buildHelper(ctx android.Bp2buildMutatorContext) (* // which we treat as *PrebuiltFile* func (module *PrebuiltEtc) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { var dir = module.installDirBase - // prebuilt_file supports only `etc` or `usr/share` - if !(dir == "etc" || dir == "usr/share") { + // prebuilt_file only supports "etc" or "usr/share" or "." as module installDirBase + if !(dir == "etc" || dir == "usr/share" || dir == ".") { + ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") return }