mirror of
https://github.com/golang/go
synced 2024-11-19 03:24:40 -07:00
cmd/go: add $DOLLAR to the predefined variables for go generate
Without some hook like this, it's impossible to get a $ into the generate command, which is necessary if you're trying to do some shell scripting or regular expressions. We could use backslash escaping but that's already tricky enough because the strings are processed as Go strings. Using $ like this means we need no more mechanism, just a predefined variable. We may need to revisit this but I hope we can avoid new quoting rules. Change-Id: Ieb478c8cc767a866765282472239ed3c1e5669a8 Reviewed-on: https://go-review.googlesource.com/8091 Reviewed-by: Dave Cheney <dave@cheney.net> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
e2543ef62c
commit
f338d94285
@ -64,6 +64,8 @@ Go generate sets several variables when it runs the generator:
|
|||||||
The base name of the file.
|
The base name of the file.
|
||||||
$GOPACKAGE
|
$GOPACKAGE
|
||||||
The name of the package of the file containing the directive.
|
The name of the package of the file containing the directive.
|
||||||
|
$DOLLAR
|
||||||
|
A dollar sign.
|
||||||
|
|
||||||
Other than variable substitution and quoted-string evaluation, no
|
Other than variable substitution and quoted-string evaluation, no
|
||||||
special processing such as "globbing" is performed on the command
|
special processing such as "globbing" is performed on the command
|
||||||
@ -348,6 +350,8 @@ func (g *Generator) expandEnv(word string) string {
|
|||||||
sub = g.file
|
sub = g.file
|
||||||
case "GOPACKAGE":
|
case "GOPACKAGE":
|
||||||
sub = g.pkg
|
sub = g.pkg
|
||||||
|
case "DOLLAR":
|
||||||
|
sub = "$"
|
||||||
default:
|
default:
|
||||||
sub = os.Getenv(envVar)
|
sub = os.Getenv(envVar)
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ var splitTests = []splitTest{
|
|||||||
{"$GOPACKAGE", []string{"sys"}},
|
{"$GOPACKAGE", []string{"sys"}},
|
||||||
{"a $XXNOTDEFINEDXX b", []string{"a", "", "b"}},
|
{"a $XXNOTDEFINEDXX b", []string{"a", "", "b"}},
|
||||||
{"/$XXNOTDEFINED/", []string{"//"}},
|
{"/$XXNOTDEFINED/", []string{"//"}},
|
||||||
|
{"/$DOLLAR/", []string{"/$/"}},
|
||||||
{"yacc -o $GOARCH/yacc_$GOFILE", []string{"go", "tool", "yacc", "-o", runtime.GOARCH + "/yacc_proc.go"}},
|
{"yacc -o $GOARCH/yacc_$GOFILE", []string{"go", "tool", "yacc", "-o", runtime.GOARCH + "/yacc_proc.go"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user