soong_zip: support globs in -f and -D arguments

-f and -D arguments can now take globs in the Soong format.

Also update the use of soong_zip that jars resources to escape the
globs in the arguments, and then shell-escape them when writing to
the rsp file so the glob escape are not intepreted by ReadRespFile.

Also remove an unused argument to the buildAAR rule that could
have contained values that needed escaping.

Test: m checkbuild
Change-Id: I7f20bb169dc01f952d2a7681ec6ee9c05737ed37
This commit is contained in:
Colin Cross 2018-09-18 17:05:15 -07:00
parent 3f4d116496
commit 08e28abc4e
5 changed files with 25 additions and 7 deletions

View file

@ -103,10 +103,10 @@ var buildAAR = pctx.AndroidStaticRule("buildAAR",
`cp ${manifest} ${outDir}/AndroidManifest.xml && ` +
`cp ${classesJar} ${outDir}/classes.jar && ` +
`cp ${rTxt} ${outDir}/R.txt && ` +
`${config.SoongZipCmd} -jar -o $out -C ${outDir} -D ${outDir} ${resArgs}`,
`${config.SoongZipCmd} -jar -o $out -C ${outDir} -D ${outDir}`,
CommandDeps: []string{"${config.SoongZipCmd}"},
},
"manifest", "classesJar", "rTxt", "resArgs", "outDir")
"manifest", "classesJar", "rTxt", "outDir")
func BuildAAR(ctx android.ModuleContext, outputFile android.WritablePath,
classesJar, manifest, rTxt android.Path, res android.Paths) {

View file

@ -321,7 +321,7 @@ func TransformResourcesToJar(ctx android.ModuleContext, outputFile android.Writa
Output: outputFile,
Implicits: deps,
Args: map[string]string{
"jarArgs": strings.Join(proptools.NinjaEscape(jarArgs), " "),
"jarArgs": strings.Join(proptools.NinjaAndShellEscape(jarArgs), " "),
},
})
}

View file

@ -20,6 +20,8 @@ import (
"strings"
"android/soong/android"
"github.com/google/blueprint/pathtools"
)
var resourceExcludes = []string{
@ -64,7 +66,7 @@ func ResourceDirsToJarArgs(ctx android.ModuleContext,
if !strings.HasPrefix(path, dir.String()) {
panic(fmt.Errorf("path %q does not start with %q", path, dir))
}
args = append(args, "-f", path)
args = append(args, "-f", pathtools.MatchEscape(path))
}
}
}
@ -107,7 +109,7 @@ func resourceFilesToJarArgs(ctx android.ModuleContext,
if i == 0 || dir != lastDir {
args = append(args, "-C", dir)
}
args = append(args, "-f", path)
args = append(args, "-f", pathtools.MatchEscape(path))
lastDir = dir
}

View file

@ -199,6 +199,11 @@ func main() {
flags.Parse(expandedArgs[1:])
if flags.NArg() > 0 {
fmt.Fprintf(os.Stderr, "unexpected arguments %s\n", strings.Join(flags.Args(), " "))
usage()
}
err := zip.Run(zip.ZipArgs{
FileArgs: fArgs,
OutputFilePath: *out,

View file

@ -224,9 +224,20 @@ func Run(args ZipArgs) (err error) {
noCompression := args.CompressionLevel == 0
for _, fa := range args.FileArgs {
srcs := fa.SourceFiles
var srcs []string
for _, s := range fa.SourceFiles {
globbed, _, err := pathtools.Glob(s, nil, pathtools.DontFollowSymlinks)
if err != nil {
return err
}
srcs = append(srcs, globbed...)
}
if fa.GlobDir != "" {
srcs = append(srcs, recursiveGlobFiles(fa.GlobDir)...)
globbed, _, err := pathtools.Glob(filepath.Join(fa.GlobDir, "**/*"), nil, pathtools.DontFollowSymlinks)
if err != nil {
return err
}
srcs = append(srcs, globbed...)
}
for _, src := range srcs {
err := fillPathPairs(fa, src, &pathMappings, args.NonDeflatedFiles, noCompression)