Merge "bp2build java_resources that only contain a filegroup"

This commit is contained in:
Alix Espino
2023-05-26 13:59:42 +00:00
committed by Gerrit Code Review
4 changed files with 72 additions and 2 deletions

View File

@@ -761,6 +761,11 @@ var (
// aidl
"aidl",
"libaidl-common",
// java_resources containing only a single filegroup
"libauto_value_plugin",
"auto_value_plugin_resources",
"auto_value_extension",
}
Bp2buildModuleTypeAlwaysConvertList = []string{
@@ -835,7 +840,6 @@ var (
"libprotobuf-internal-python-srcs", // TODO(b/210751803), we don't handle path property for filegroups
"libprotobuf-java-full", // TODO(b/210751803), we don't handle path property for filegroups
"libprotobuf-java-util-full", // TODO(b/210751803), we don't handle path property for filegroups
"auto_value_plugin_resources", // TODO(b/210751803), we don't handle path property for filegroups
// go deps:
"analyze_bcpf", // depends on bpmodify a blueprint_go_binary.

View File

@@ -177,6 +177,17 @@ func (fg *fileGroup) ConvertWithBp2build(ctx TopDownMutatorContext) {
}
}
type FileGroupPath interface {
GetPath(ctx TopDownMutatorContext) string
}
func (fg *fileGroup) GetPath(ctx TopDownMutatorContext) string {
if fg.properties.Path != nil {
return *fg.properties.Path
}
return ""
}
type fileGroupProperties struct {
// srcs lists files that will be included in this filegroup
Srcs []string `android:"path"`
@@ -207,6 +218,7 @@ type fileGroup struct {
BazelModuleBase
DefaultableModuleBase
FileGroupAsLibrary
FileGroupPath
properties fileGroupProperties
srcs Paths
}
@@ -214,6 +226,7 @@ type fileGroup struct {
var _ MixedBuildBuildable = (*fileGroup)(nil)
var _ SourceFileProducer = (*fileGroup)(nil)
var _ FileGroupAsLibrary = (*fileGroup)(nil)
var _ FileGroupPath = (*fileGroup)(nil)
// filegroup contains a list of files that are referenced by other modules
// properties (such as "srcs") using the syntax ":<name>". filegroup are

View File

@@ -826,3 +826,43 @@ func TestJavaLibraryArchVariantSrcsWithExcludes(t *testing.T) {
},
})
}
func TestJavaLibraryJavaResourcesSingleFilegroup(t *testing.T) {
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
Filesystem: map[string]string{
"res/a.res": "",
"res/b.res": "",
"res/dir1/b.res": "",
},
Description: "java_library",
Blueprint: `java_library {
name: "java-lib-1",
srcs: ["a.java"],
java_resources: [":filegroup1"],
bazel_module: { bp2build_available: true },
}
filegroup {
name: "filegroup1",
path: "foo",
srcs: ["foo/a", "foo/b"],
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
"srcs": `["a.java"]`,
"resources": `[":filegroup1"]`,
"resource_strip_prefix": `"foo"`,
}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
MakeBazelTargetNoRestrictions("filegroup", "filegroup1", AttrNameToString{
"srcs": `[
"foo/a",
"foo/b",
]`}),
},
}, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
})
}

View File

@@ -2704,6 +2704,15 @@ type javaResourcesAttributes struct {
Resource_strip_prefix *string
}
func (m *Library) javaResourcesGetSingleFilegroupStripPrefix(ctx android.TopDownMutatorContext) (string, bool) {
if otherM, ok := ctx.ModuleFromName(m.properties.Java_resources[0]); ok && len(m.properties.Java_resources) == 1 {
if fg, isFilegroup := otherM.(android.FileGroupPath); isFilegroup {
return filepath.Join(ctx.OtherModuleDir(otherM), fg.GetPath(ctx)), true
}
}
return "", false
}
func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorContext) *javaResourcesAttributes {
var resources bazel.LabelList
var resourceStripPrefix *string
@@ -2713,8 +2722,12 @@ func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorConte
}
if m.properties.Java_resources != nil {
if prefix, ok := m.javaResourcesGetSingleFilegroupStripPrefix(ctx); ok {
resourceStripPrefix = proptools.StringPtr(prefix)
} else {
resourceStripPrefix = proptools.StringPtr(ctx.ModuleDir())
}
resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources))
resourceStripPrefix = proptools.StringPtr(ctx.ModuleDir())
}
//TODO(b/179889880) handle case where glob includes files outside package