Merge "convert java_resources with bp2build"
This commit is contained in:
45
java/java.go
45
java/java.go
@@ -2018,7 +2018,49 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module,
|
||||
}
|
||||
}
|
||||
|
||||
type javaResourcesAttributes struct {
|
||||
Resources bazel.LabelListAttribute
|
||||
Resource_strip_prefix *string
|
||||
}
|
||||
|
||||
func (m *Library) convertJavaResourcesAttributes(ctx android.TopDownMutatorContext) *javaResourcesAttributes {
|
||||
var resources bazel.LabelList
|
||||
var resourceStripPrefix *string
|
||||
|
||||
if m.properties.Java_resources != nil {
|
||||
resources.Append(android.BazelLabelForModuleSrc(ctx, m.properties.Java_resources))
|
||||
}
|
||||
|
||||
//TODO(b/179889880) handle case where glob includes files outside package
|
||||
resDeps := ResourceDirsToFiles(
|
||||
ctx,
|
||||
m.properties.Java_resource_dirs,
|
||||
m.properties.Exclude_java_resource_dirs,
|
||||
m.properties.Exclude_java_resources,
|
||||
)
|
||||
|
||||
for i, resDep := range resDeps {
|
||||
dir, files := resDep.dir, resDep.files
|
||||
|
||||
resources.Append(bazel.MakeLabelList(android.RootToModuleRelativePaths(ctx, files)))
|
||||
|
||||
// Bazel includes the relative path from the WORKSPACE root when placing the resource
|
||||
// inside the JAR file, so we need to remove that prefix
|
||||
resourceStripPrefix = proptools.StringPtr(dir.String())
|
||||
if i > 0 {
|
||||
// TODO(b/226423379) allow multiple resource prefixes
|
||||
ctx.ModuleErrorf("bp2build does not support more than one directory in java_resource_dirs (b/226423379)")
|
||||
}
|
||||
}
|
||||
|
||||
return &javaResourcesAttributes{
|
||||
Resources: bazel.MakeLabelListAttribute(resources),
|
||||
Resource_strip_prefix: resourceStripPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
type javaCommonAttributes struct {
|
||||
*javaResourcesAttributes
|
||||
Srcs bazel.LabelListAttribute
|
||||
Plugins bazel.LabelListAttribute
|
||||
Javacopts bazel.StringListAttribute
|
||||
@@ -2095,7 +2137,8 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
|
||||
}
|
||||
|
||||
commonAttrs := &javaCommonAttributes{
|
||||
Srcs: javaSrcs,
|
||||
Srcs: javaSrcs,
|
||||
javaResourcesAttributes: m.convertJavaResourcesAttributes(ctx),
|
||||
Plugins: bazel.MakeLabelListAttribute(
|
||||
android.BazelLabelForModuleDeps(ctx, m.properties.Plugins),
|
||||
),
|
||||
|
@@ -33,8 +33,13 @@ var resourceExcludes = []string{
|
||||
"**/*~",
|
||||
}
|
||||
|
||||
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
||||
resourceDirs, excludeResourceDirs, excludeResourceFiles []string) (args []string, deps android.Paths) {
|
||||
type resourceDeps struct {
|
||||
dir android.Path
|
||||
files android.Paths
|
||||
}
|
||||
|
||||
func ResourceDirsToFiles(ctx android.BaseModuleContext,
|
||||
resourceDirs, excludeResourceDirs, excludeResourceFiles []string) (deps []resourceDeps) {
|
||||
var excludeDirs []string
|
||||
var excludeFiles []string
|
||||
|
||||
@@ -55,21 +60,36 @@ func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
||||
dirs := ctx.Glob(android.PathForSource(ctx, ctx.ModuleDir()).Join(ctx, resourceDir).String(), excludeDirs)
|
||||
for _, dir := range dirs {
|
||||
files := ctx.GlobFiles(filepath.Join(dir.String(), "**/*"), excludeFiles)
|
||||
deps = append(deps, resourceDeps{
|
||||
dir: dir,
|
||||
files: files,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return deps
|
||||
}
|
||||
|
||||
func ResourceDirsToJarArgs(ctx android.ModuleContext,
|
||||
resourceDirs, excludeResourceDirs, excludeResourceFiles []string) (args []string, deps android.Paths) {
|
||||
resDeps := ResourceDirsToFiles(ctx, resourceDirs, excludeResourceDirs, excludeResourceFiles)
|
||||
|
||||
for _, resDep := range resDeps {
|
||||
dir, files := resDep.dir, resDep.files
|
||||
|
||||
if len(files) > 0 {
|
||||
args = append(args, "-C", dir.String())
|
||||
deps = append(deps, files...)
|
||||
|
||||
if len(files) > 0 {
|
||||
args = append(args, "-C", dir.String())
|
||||
|
||||
for _, f := range files {
|
||||
path := f.String()
|
||||
if !strings.HasPrefix(path, dir.String()) {
|
||||
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
||||
}
|
||||
args = append(args, "-f", pathtools.MatchEscape(path))
|
||||
for _, f := range files {
|
||||
path := f.String()
|
||||
if !strings.HasPrefix(path, dir.String()) {
|
||||
panic(fmt.Errorf("path %q does not start with %q", path, dir))
|
||||
}
|
||||
args = append(args, "-f", pathtools.MatchEscape(path))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return args, deps
|
||||
|
Reference in New Issue
Block a user