Pass rsp files into sbox and rewrapper
The current implementation causes inputs listed in an rsp file used with sbox to be duplicated 3 times in the build.ninja file; once as a dependency of the rule, once in the rspfile_content field of the rule with the paths rewritten to be relative to the sandbox, and once in the rule to write the sbox manifest. When RBE is enabled it also gets a fourth copy in the list of files to be treated as inputs by rewrapper. Reduce this to a single copy by using "$in" for the rspfile_content so that the files only have to be listed in the input dependencies of the rule, and then add support to sbox to rewrite the rsp file while copying it into the sandbox, and pass it to rewrapper as well. Test: m lint-check Change-Id: I3f46f61119508d39a8bb231c99fc130153fb6f04
This commit is contained in:
@@ -17,6 +17,7 @@ package response
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
@@ -68,3 +69,44 @@ func ReadRspFile(r io.Reader) ([]string, error) {
|
||||
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func rspUnsafeChar(r rune) bool {
|
||||
switch {
|
||||
case 'A' <= r && r <= 'Z',
|
||||
'a' <= r && r <= 'z',
|
||||
'0' <= r && r <= '9',
|
||||
r == '_',
|
||||
r == '+',
|
||||
r == '-',
|
||||
r == '.',
|
||||
r == '/':
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
var rspEscaper = strings.NewReplacer(`'`, `'\''`)
|
||||
|
||||
// WriteRspFile writes a list of files to a file in Ninja's response file format.
|
||||
func WriteRspFile(w io.Writer, files []string) error {
|
||||
for i, f := range files {
|
||||
if i != 0 {
|
||||
_, err := io.WriteString(w, " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if strings.IndexFunc(f, rspUnsafeChar) != -1 {
|
||||
f = `'` + rspEscaper.Replace(f) + `'`
|
||||
}
|
||||
|
||||
_, err := io.WriteString(w, f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -94,3 +94,30 @@ func TestReadRspFile(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteRspFile(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
in []string
|
||||
out string
|
||||
}{
|
||||
{
|
||||
name: "ninja rsp file",
|
||||
in: []string{"a", "b", "@", "foo'bar", `foo"bar`},
|
||||
out: "a b '@' 'foo'\\''bar' 'foo\"bar'",
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
err := WriteRspFile(buf, testCase.in)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %q", err)
|
||||
}
|
||||
if buf.String() != testCase.out {
|
||||
t.Errorf("expected %q got %q", testCase.out, buf.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user