update cmd/go flags for 1.18

As of 1.18beta1. I used bash commands like:

	diff -u <(go1.17.5 help build) <(gotip help build)

While here, supply -buildinfo=false and -buildvcs=false to go build.
We already remove that information by discarding the _gomod_.go file,
but we might as well pass the flags too.
If anything, it lets the toolchain avoid the work entirely.
Note that we can't use these flags on Go 1.17 for now, though.

Add a TODO that came to mind while writing this, too.
pull/436/head
Daniel Martí 3 years ago committed by lu4p
parent 93b2873c28
commit 5abd3c468d

@ -269,6 +269,8 @@ type errJustExit int
func (e errJustExit) Error() string { return fmt.Sprintf("exit: %d", e) } func (e errJustExit) Error() string { return fmt.Sprintf("exit: %d", e) }
var goVersionSemver string
func goVersionOK() bool { func goVersionOK() bool {
const ( const (
minGoVersionSemver = "v1.17.0" minGoVersionSemver = "v1.17.0"
@ -285,8 +287,8 @@ func goVersionOK() bool {
return false return false
} }
versionSemver := "v" + strings.TrimPrefix(version, "go") goVersionSemver = "v" + strings.TrimPrefix(version, "go")
if semver.Compare(versionSemver, minGoVersionSemver) < 0 { if semver.Compare(goVersionSemver, minGoVersionSemver) < 0 {
fmt.Fprintf(os.Stderr, "Go version %q is too old; please upgrade to Go %s\n", version, suggestedGoVersion) fmt.Fprintf(os.Stderr, "Go version %q is too old; please upgrade to Go %s\n", version, suggestedGoVersion)
return false return false
} }
@ -487,8 +489,15 @@ This command wraps "go %s". Below is its help:
goArgs := []string{ goArgs := []string{
command, command,
"-trimpath", "-trimpath",
toolexecFlag.String(),
} }
if semver.Compare(goVersionSemver, "v1.18.0") >= 0 {
// TODO: remove the conditional once we drop support for 1.17
goArgs = append(goArgs,
"-buildinfo=false",
"-buildvcs=false",
)
}
goArgs = append(goArgs, toolexecFlag.String())
if flagDebugDir != "" { if flagDebugDir != "" {
// In case the user deletes the debug directory, // In case the user deletes the debug directory,
// and a previous build is cached, // and a previous build is cached,
@ -883,7 +892,7 @@ var cannotObfuscate = map[string]bool{
"crypto/x509/internal/macos": true, "crypto/x509/internal/macos": true,
} }
// Obtained from "go list -deps runtime" on Go master (1.18) as of Nov 2021. // Obtained from "go list -deps runtime" on Go 1.18beta1.
// Note that the same command on Go 1.17 results in a subset of this list. // Note that the same command on Go 1.17 results in a subset of this list.
var runtimeAndDeps = map[string]bool{ var runtimeAndDeps = map[string]bool{
"internal/goarch": true, "internal/goarch": true,
@ -1797,7 +1806,7 @@ func alterTrimpath(flags []string) []string {
return flagSetValue(flags, "-trimpath", sharedTempDir+"=>;"+trimpath) return flagSetValue(flags, "-trimpath", sharedTempDir+"=>;"+trimpath)
} }
// forwardBuildFlags is obtained from 'go help build' as of Go 1.17. // forwardBuildFlags is obtained from 'go help build' as of Go 1.18beta1.
var forwardBuildFlags = map[string]bool{ var forwardBuildFlags = map[string]bool{
// These shouldn't be used in nested cmd/go calls. // These shouldn't be used in nested cmd/go calls.
"-a": false, "-a": false,
@ -1806,12 +1815,15 @@ var forwardBuildFlags = map[string]bool{
"-v": false, "-v": false,
// These are always set by garble. // These are always set by garble.
"-trimpath": false, "-trimpath": false,
"-toolexec": false, "-toolexec": false,
"-buildinfo": false,
"-buildvcs": false,
"-p": true, "-p": true,
"-race": true, "-race": true,
"-msan": true, "-msan": true,
"-asan": true,
"-work": true, "-work": true,
"-asmflags": true, "-asmflags": true,
"-buildmode": true, "-buildmode": true,
@ -1826,10 +1838,11 @@ var forwardBuildFlags = map[string]bool{
"-modfile": true, "-modfile": true,
"-pkgdir": true, "-pkgdir": true,
"-tags": true, "-tags": true,
"-workfile": true,
"-overlay": true, "-overlay": true,
} }
// booleanFlags is obtained from 'go help build' and 'go help testflag' as of Go 1.17. // booleanFlags is obtained from 'go help build' and 'go help testflag' as of Go 1.18beta1.
var booleanFlags = map[string]bool{ var booleanFlags = map[string]bool{
// Shared build flags. // Shared build flags.
"-a": true, "-a": true,
@ -1839,9 +1852,12 @@ var booleanFlags = map[string]bool{
"-x": true, "-x": true,
"-race": true, "-race": true,
"-msan": true, "-msan": true,
"-asan": true,
"-linkshared": true, "-linkshared": true,
"-modcacherw": true, "-modcacherw": true,
"-trimpath": true, "-trimpath": true,
"-buildinfo": true,
"-buildvcs": true,
// Test flags (TODO: support its special -args flag) // Test flags (TODO: support its special -args flag)
"-c": true, "-c": true,

@ -159,6 +159,9 @@ func (p *listedPackage) obfuscatedImportPath() string {
// and all of its dependencies // and all of its dependencies
func appendListedPackages(patterns ...string) error { func appendListedPackages(patterns ...string) error {
startTime := time.Now() startTime := time.Now()
// TODO: perhaps include all top-level build flags set by garble,
// including -buildinfo=false and -buildvcs=false.
// They shouldn't affect "go list" here, but might as well be consistent.
args := []string{"list", "-json", "-deps", "-export", "-trimpath"} args := []string{"list", "-json", "-deps", "-export", "-trimpath"}
args = append(args, cache.ForwardBuildFlags...) args = append(args, cache.ForwardBuildFlags...)
args = append(args, patterns...) args = append(args, patterns...)

Loading…
Cancel
Save