aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/objabi
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2018-04-30 19:01:57 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2018-05-04 01:01:50 +0000
commit17fbb83693d5d4b880bb128d7afdb137840f76ec (patch)
tree6f3da9c42a8f14cc34a65510313a62da0d7d6e35 /src/cmd/internal/objabi
parent498c803c19caa94d9d37eb378deed786117bbeab (diff)
downloadgo-17fbb83693d5d4b880bb128d7afdb137840f76ec.tar.xz
cmd/go, cmd/compile: use Windows response files to avoid arg length limits
Fixes #18468 Change-Id: Ic88a8daf67db949e5b59f9aa466b37e7f7890713 Reviewed-on: https://go-review.googlesource.com/110395 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/internal/objabi')
-rw-r--r--src/cmd/internal/objabi/flag.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/cmd/internal/objabi/flag.go b/src/cmd/internal/objabi/flag.go
index ecb9e39a6b..30cd7dccac 100644
--- a/src/cmd/internal/objabi/flag.go
+++ b/src/cmd/internal/objabi/flag.go
@@ -8,6 +8,8 @@ import (
"flag"
"fmt"
"io"
+ "io/ioutil"
+ "log"
"os"
"strconv"
"strings"
@@ -28,9 +30,46 @@ func Flagprint(w io.Writer) {
func Flagparse(usage func()) {
flag.Usage = usage
+ os.Args = expandArgs(os.Args)
flag.Parse()
}
+// expandArgs expands "response files" arguments in the provided slice.
+//
+// A "response file" argument starts with '@' and the rest of that
+// argument is a filename with CR-or-CRLF-separated arguments. Each
+// argument in the named files can also contain response file
+// arguments. See Issue 18468.
+//
+// The returned slice 'out' aliases 'in' iff the input did not contain
+// any response file arguments.
+//
+// TODO: handle relative paths of recursive expansions in different directories?
+// Is there a spec for this? Are relative paths allowed?
+func expandArgs(in []string) (out []string) {
+ // out is nil until we see a "@" argument.
+ for i, s := range in {
+ if strings.HasPrefix(s, "@") {
+ if out == nil {
+ out = make([]string, 0, len(in)*2)
+ out = append(out, in[:i]...)
+ }
+ slurp, err := ioutil.ReadFile(s[1:])
+ if err != nil {
+ log.Fatal(err)
+ }
+ args := strings.Split(strings.TrimSpace(strings.Replace(string(slurp), "\r", "", -1)), "\n")
+ out = append(out, expandArgs(args)...)
+ } else if out != nil {
+ out = append(out, s)
+ }
+ }
+ if out == nil {
+ return in
+ }
+ return
+}
+
func AddVersionFlag() {
flag.Var(versionFlag{}, "V", "print version and exit")
}