Move response file handling to a separate package
sbox is going to need to read and write response files, move ReadRspFile
to its own package.
Test: response_test.go
Change-Id: Iecb5486b4aaeb2531828743ad8ef784df675e18e
diff --git a/zip/zip.go b/zip/zip.go
index 088ed0d..a6490d4 100644
--- a/zip/zip.go
+++ b/zip/zip.go
@@ -29,7 +29,8 @@
"sync"
"syscall"
"time"
- "unicode"
+
+ "android/soong/response"
"github.com/google/blueprint/pathtools"
@@ -164,14 +165,12 @@
}
defer f.Close()
- list, err := ioutil.ReadAll(f)
+ arg := b.state
+ arg.SourceFiles, err = response.ReadRspFile(f)
if err != nil {
b.err = err
return b
}
-
- arg := b.state
- arg.SourceFiles = ReadRespFile(list)
for i := range arg.SourceFiles {
arg.SourceFiles[i] = pathtools.MatchEscape(arg.SourceFiles[i])
}
@@ -253,49 +252,6 @@
Filesystem pathtools.FileSystem
}
-const NOQUOTE = '\x00'
-
-func ReadRespFile(bytes []byte) []string {
- var args []string
- var arg []rune
-
- isEscaping := false
- quotingStart := NOQUOTE
- for _, c := range string(bytes) {
- switch {
- case isEscaping:
- if quotingStart == '"' {
- if !(c == '"' || c == '\\') {
- // '\"' or '\\' will be escaped under double quoting.
- arg = append(arg, '\\')
- }
- }
- arg = append(arg, c)
- isEscaping = false
- case c == '\\' && quotingStart != '\'':
- isEscaping = true
- case quotingStart == NOQUOTE && (c == '\'' || c == '"'):
- quotingStart = c
- case quotingStart != NOQUOTE && c == quotingStart:
- quotingStart = NOQUOTE
- case quotingStart == NOQUOTE && unicode.IsSpace(c):
- // Current character is a space outside quotes
- if len(arg) != 0 {
- args = append(args, string(arg))
- }
- arg = arg[:0]
- default:
- arg = append(arg, c)
- }
- }
-
- if len(arg) != 0 {
- args = append(args, string(arg))
- }
-
- return args
-}
-
func zipTo(args ZipArgs, w io.Writer) error {
if args.EmulateJar {
args.AddDirectoryEntriesToZip = true