Support ninja rsp files in soong_zip
Add a -r argument to soong_zip that reads a list of files from a file like the -l argument but treats it as a Ninja rsp file with escaping. Replace the -l arguments in Soong that are using rsp files with -r. Fixes: 162435077 Test: TestReadRespFile, TestZip Change-Id: I4605312e99406ab1bd0c37af9c5ad212393f0403
This commit is contained in:
@@ -62,6 +62,15 @@ func (listFiles) Set(s string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type rspFiles struct{}
|
||||
|
||||
func (rspFiles) String() string { return `""` }
|
||||
|
||||
func (rspFiles) Set(s string) error {
|
||||
fileArgsBuilder.RspFile(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
type dir struct{}
|
||||
|
||||
func (dir) String() string { return `""` }
|
||||
@@ -143,7 +152,8 @@ func main() {
|
||||
traceFile := flags.String("trace", "", "write trace to file")
|
||||
|
||||
flags.Var(&rootPrefix{}, "P", "path prefix within the zip at which to place files")
|
||||
flags.Var(&listFiles{}, "l", "file containing list of .class files")
|
||||
flags.Var(&listFiles{}, "l", "file containing list of files to zip")
|
||||
flags.Var(&rspFiles{}, "r", "file containing list of files to zip with Ninja rsp file escaping")
|
||||
flags.Var(&dir{}, "D", "directory to include in zip")
|
||||
flags.Var(&file{}, "f", "file to include in zip")
|
||||
flags.Var(&nonDeflatedFiles, "s", "file path to be stored within the zip without compression")
|
||||
|
24
zip/zip.go
24
zip/zip.go
@@ -150,6 +150,30 @@ func (b *FileArgsBuilder) List(name string) *FileArgsBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *FileArgsBuilder) RspFile(name string) *FileArgsBuilder {
|
||||
if b.err != nil {
|
||||
return b
|
||||
}
|
||||
|
||||
f, err := b.fs.Open(name)
|
||||
if err != nil {
|
||||
b.err = err
|
||||
return b
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
list, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
b.err = err
|
||||
return b
|
||||
}
|
||||
|
||||
arg := b.state
|
||||
arg.SourceFiles = ReadRespFile(list)
|
||||
b.fileArgs = append(b.fileArgs, arg)
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *FileArgsBuilder) Error() error {
|
||||
if b == nil {
|
||||
return nil
|
||||
|
@@ -49,6 +49,9 @@ var mockFs = pathtools.MockFs(map[string][]byte{
|
||||
"l_nl": []byte("a/a/a\na/a/b\nc\n"),
|
||||
"l_sp": []byte("a/a/a a/a/b c"),
|
||||
"l2": []byte("missing\n"),
|
||||
"rsp": []byte("'a/a/a'\na/a/b\n'@'\n'foo'\\''bar'"),
|
||||
"@ -> c": nil,
|
||||
"foo'bar -> c": nil,
|
||||
"manifest.txt": fileCustomManifest,
|
||||
})
|
||||
|
||||
@@ -246,6 +249,19 @@ func TestZip(t *testing.T) {
|
||||
fh("c", fileC, zip.Deflate),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rsp",
|
||||
args: fileArgsBuilder().
|
||||
RspFile("rsp"),
|
||||
compressionLevel: 9,
|
||||
|
||||
files: []zip.FileHeader{
|
||||
fh("a/a/a", fileA, zip.Deflate),
|
||||
fh("a/a/b", fileB, zip.Deflate),
|
||||
fh("@", fileC, zip.Deflate),
|
||||
fh("foo'bar", fileC, zip.Deflate),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "prefix in zip",
|
||||
args: fileArgsBuilder().
|
||||
@@ -568,6 +584,11 @@ func TestReadRespFile(t *testing.T) {
|
||||
in: `./cmd "\""-C`,
|
||||
out: []string{"./cmd", `"-C`},
|
||||
},
|
||||
{
|
||||
name: "ninja rsp file",
|
||||
in: "'a'\nb\n'@'\n'foo'\\''bar'\n'foo\"bar'",
|
||||
out: []string{"a", "b", "@", "foo'bar", `foo"bar`},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
Reference in New Issue
Block a user