From 79985819fedb7af103e19318064deb1b0b8fa240 Mon Sep 17 00:00:00 2001 From: Sam Delmerico Date: Wed, 23 Mar 2022 20:20:42 +0000 Subject: convert java_resources with bp2build Test: b build --platforms=//build/bazel/platforms:linux_x86 //external/jarjar:jarjar-binary and try to use on a jar Change-Id: Id6f4e6937687fd575360fbacaeda55c41922636e --- java/java_resources.go | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'java/java_resources.go') diff --git a/java/java_resources.go b/java/java_resources.go index 787d74a0d..b0dc5a1cf 100644 --- a/java/java_resources.go +++ b/java/java_resources.go @@ -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, + }) + } + } - deps = append(deps, files...) + return deps +} + +func ResourceDirsToJarArgs(ctx android.ModuleContext, + resourceDirs, excludeResourceDirs, excludeResourceFiles []string) (args []string, deps android.Paths) { + resDeps := ResourceDirsToFiles(ctx, resourceDirs, excludeResourceDirs, excludeResourceFiles) - if len(files) > 0 { - args = append(args, "-C", dir.String()) + for _, resDep := range resDeps { + dir, files := resDep.dir, resDep.files - 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)) + if len(files) > 0 { + args = append(args, "-C", dir.String()) + deps = append(deps, files...) + + 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 -- cgit v1.2.3-59-g8ed1b