]> Cypherpunks repositories - gostls13.git/commitdiff
all: use "noopt" build tag for checking optimization disabled
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 16 Aug 2022 11:51:57 +0000 (18:51 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 17 Aug 2022 04:02:17 +0000 (04:02 +0000)
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>

src/cmd/dist/build.go
src/cmd/dist/test.go
src/internal/testenv/noopt.go [new file with mode: 0644]
src/internal/testenv/opt.go [new file with mode: 0644]
src/internal/testenv/testenv.go

index 7c44c4a60528c15987d3d16e08b22d6e6eaa5475..4440b44aae9f2758bcb81af855e98e4813097a10 100644 (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
+               }
+       }
+}
index 42ff0f939167db75ed5f31f36e80ac05a9f27ea0..1c22568ebdf703f58b0b92da2c925490f515423b 100644 (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
diff --git a/src/internal/testenv/noopt.go b/src/internal/testenv/noopt.go
new file mode 100644 (file)
index 0000000..ae2a3d0
--- /dev/null
@@ -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
+}
diff --git a/src/internal/testenv/opt.go b/src/internal/testenv/opt.go
new file mode 100644 (file)
index 0000000..1bb96f7
--- /dev/null
@@ -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
+}
index 4f8c0975736c1335269217d27f819cb50b0002d8..7b435fd002ab44818e56c0e8a2dc550dbdcb0207 100644 (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.