mirror of
https://github.com/golang/go
synced 2024-11-19 23:24:45 -07:00
cmd/go: accept more spaces in -gcflags arguments
Earlier versions of Go were not very picky about leading spaces in the -gcflags values. Make the new pattern-enhanced parser equally lax. Fixes #22943. Change-Id: I5cf4d3e81412e895a4b52af325853ed48d0b73f4 Reviewed-on: https://go-review.googlesource.com/81498 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
8bb51a73e9
commit
2f8bcc8940
@ -5177,7 +5177,7 @@ func TestGcflagsPatterns(t *testing.T) {
|
|||||||
tg.setenv("GOPATH", "")
|
tg.setenv("GOPATH", "")
|
||||||
tg.setenv("GOCACHE", "off")
|
tg.setenv("GOCACHE", "off")
|
||||||
|
|
||||||
tg.run("build", "-v", "-gcflags=-e", "fmt")
|
tg.run("build", "-v", "-gcflags= \t\r\n -e", "fmt")
|
||||||
tg.grepStderr("fmt", "did not rebuild fmt")
|
tg.grepStderr("fmt", "did not rebuild fmt")
|
||||||
tg.grepStderrNot("reflect", "incorrectly rebuilt reflect")
|
tg.grepStderrNot("reflect", "incorrectly rebuilt reflect")
|
||||||
|
|
||||||
@ -5186,7 +5186,7 @@ func TestGcflagsPatterns(t *testing.T) {
|
|||||||
tg.grepStderr("reflect", "did not rebuild reflect")
|
tg.grepStderr("reflect", "did not rebuild reflect")
|
||||||
tg.grepStderrNot("runtime", "incorrectly rebuilt runtime")
|
tg.grepStderrNot("runtime", "incorrectly rebuilt runtime")
|
||||||
|
|
||||||
tg.run("build", "-x", "-v", "-gcflags=reflect=-N", "fmt")
|
tg.run("build", "-x", "-v", "-gcflags= \t\r\n reflect \t\r\n = \t\r\n -N", "fmt")
|
||||||
tg.grepStderr("fmt", "did not rebuild fmt")
|
tg.grepStderr("fmt", "did not rebuild fmt")
|
||||||
tg.grepStderr("reflect", "did not rebuild reflect")
|
tg.grepStderr("reflect", "did not rebuild reflect")
|
||||||
tg.grepStderr("compile.* -N .*-p reflect", "did not build reflect with -N flag")
|
tg.grepStderr("compile.* -N .*-p reflect", "did not build reflect with -N flag")
|
||||||
|
@ -41,6 +41,8 @@ func (f *PerPackageFlag) Set(v string) error {
|
|||||||
func (f *PerPackageFlag) set(v, cwd string) error {
|
func (f *PerPackageFlag) set(v, cwd string) error {
|
||||||
f.present = true
|
f.present = true
|
||||||
match := func(p *Package) bool { return p.Internal.CmdlinePkg || p.Internal.CmdlineFiles } // default predicate with no pattern
|
match := func(p *Package) bool { return p.Internal.CmdlinePkg || p.Internal.CmdlineFiles } // default predicate with no pattern
|
||||||
|
// For backwards compatibility with earlier flag splitting, ignore spaces around flags.
|
||||||
|
v = strings.TrimSpace(v)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
// Special case: -gcflags="" means no flags for command-line arguments
|
// Special case: -gcflags="" means no flags for command-line arguments
|
||||||
// (overrides previous -gcflags="-whatever").
|
// (overrides previous -gcflags="-whatever").
|
||||||
@ -55,7 +57,7 @@ func (f *PerPackageFlag) set(v, cwd string) error {
|
|||||||
if i == 0 {
|
if i == 0 {
|
||||||
return fmt.Errorf("missing <pattern> in <pattern>=<value>")
|
return fmt.Errorf("missing <pattern> in <pattern>=<value>")
|
||||||
}
|
}
|
||||||
pattern := v[:i]
|
pattern := strings.TrimSpace(v[:i])
|
||||||
match = MatchPackage(pattern, cwd)
|
match = MatchPackage(pattern, cwd)
|
||||||
v = v[i+1:]
|
v = v[i+1:]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user