1
0
mirror of https://github.com/golang/go synced 2024-11-17 21:34:49 -07:00

all: use "noopt" build tag for checking optimization disabled

Fixes #49390

Change-Id: Ie5a5e097635c9fdcf4509455007283009a7d3021
Reviewed-on: https://go-review.googlesource.com/c/go/+/423256
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cuong Manh Le 2022-08-16 18:51:57 +07:00 committed by Gopher Robot
parent c04977fa76
commit c411886c75
5 changed files with 52 additions and 8 deletions

17
src/cmd/dist/build.go vendored
View File

@ -55,6 +55,7 @@ var (
rebuildall bool
defaultclang bool
noOpt bool
vflag int // verbosity
)
@ -1325,6 +1326,7 @@ func cmdbootstrap() {
}
gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now
setNoOpt()
goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
goBootstrap := pathf("%s/go_bootstrap", tooldir)
cmdGo := pathf("%s/go", gorootBin)
@ -1510,6 +1512,9 @@ func appendCompilerFlags(args []string) []string {
func goCmd(goBinary string, cmd string, args ...string) {
goCmd := []string{goBinary, cmd}
if noOpt {
goCmd = append(goCmd, "-tags=noopt")
}
goCmd = appendCompilerFlags(goCmd)
if vflag > 0 {
goCmd = append(goCmd, "-v")
@ -1525,6 +1530,9 @@ func goCmd(goBinary string, cmd string, args ...string) {
func checkNotStale(goBinary string, targets ...string) {
goCmd := []string{goBinary, "list"}
if noOpt {
goCmd = append(goCmd, "-tags=noopt")
}
goCmd = appendCompilerFlags(goCmd)
goCmd = append(goCmd, "-f={{if .Stale}}\tSTALE {{.ImportPath}}: {{.StaleReason}}{{end}}")
@ -1800,3 +1808,12 @@ func IsRuntimePackagePath(pkgpath string) bool {
}
return rval
}
func setNoOpt() {
for _, gcflag := range strings.Split(gogcflags, " ") {
if gcflag == "-N" || gcflag == "-l" {
noOpt = true
break
}
}
}

12
src/cmd/dist/test.go vendored
View File

@ -25,6 +25,7 @@ import (
func cmdtest() {
gogcflags = os.Getenv("GO_GCFLAGS")
setNoOpt()
var t tester
@ -325,10 +326,17 @@ func (t *tester) goTest() []string {
}
func (t *tester) tags() string {
if t.iOS() {
ios := t.iOS()
switch {
case ios && noOpt:
return "-tags=lldb,noopt"
case ios:
return "-tags=lldb"
case noOpt:
return "-tags=noopt"
default:
return "-tags="
}
return "-tags="
}
// timeoutDuration converts the provided number of seconds into a

View File

@ -0,0 +1,12 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build noopt
package testenv
// OptimizationOff reports whether optimization is disabled.
func OptimizationOff() bool {
return true
}

View File

@ -0,0 +1,12 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !noopt
package testenv
// OptimizationOff reports whether optimization is disabled.
func OptimizationOff() bool {
return false
}

View File

@ -412,15 +412,10 @@ func SkipIfShortAndSlow(t testing.TB) {
func SkipIfOptimizationOff(t testing.TB) {
if OptimizationOff() {
t.Helper()
t.Skip("skipping test with optimization disabled on builder")
t.Skip("skipping test with optimization disabled")
}
}
// OptimizationOff reports whether optimization is disabled.
func OptimizationOff() bool {
return strings.HasSuffix(Builder(), "-noopt")
}
// RunWithTimeout runs cmd and returns its combined output. If the
// subprocess exits with a non-zero status, it will log that status
// and return a non-nil error, but this is not considered fatal.