Skip to content

Commit c411886

Browse files
cuonglmgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent c04977f commit c411886

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

src/cmd/dist/build.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var (
5555

5656
rebuildall bool
5757
defaultclang bool
58+
noOpt bool
5859

5960
vflag int // verbosity
6061
)
@@ -1325,6 +1326,7 @@ func cmdbootstrap() {
13251326
}
13261327

13271328
gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now
1329+
setNoOpt()
13281330
goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
13291331
goBootstrap := pathf("%s/go_bootstrap", tooldir)
13301332
cmdGo := pathf("%s/go", gorootBin)
@@ -1510,6 +1512,9 @@ func appendCompilerFlags(args []string) []string {
15101512

15111513
func goCmd(goBinary string, cmd string, args ...string) {
15121514
goCmd := []string{goBinary, cmd}
1515+
if noOpt {
1516+
goCmd = append(goCmd, "-tags=noopt")
1517+
}
15131518
goCmd = appendCompilerFlags(goCmd)
15141519
if vflag > 0 {
15151520
goCmd = append(goCmd, "-v")
@@ -1525,6 +1530,9 @@ func goCmd(goBinary string, cmd string, args ...string) {
15251530

15261531
func checkNotStale(goBinary string, targets ...string) {
15271532
goCmd := []string{goBinary, "list"}
1533+
if noOpt {
1534+
goCmd = append(goCmd, "-tags=noopt")
1535+
}
15281536
goCmd = appendCompilerFlags(goCmd)
15291537
goCmd = append(goCmd, "-f={{if .Stale}}\tSTALE {{.ImportPath}}: {{.StaleReason}}{{end}}")
15301538

@@ -1800,3 +1808,12 @@ func IsRuntimePackagePath(pkgpath string) bool {
18001808
}
18011809
return rval
18021810
}
1811+
1812+
func setNoOpt() {
1813+
for _, gcflag := range strings.Split(gogcflags, " ") {
1814+
if gcflag == "-N" || gcflag == "-l" {
1815+
noOpt = true
1816+
break
1817+
}
1818+
}
1819+
}

src/cmd/dist/test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
func cmdtest() {
2727
gogcflags = os.Getenv("GO_GCFLAGS")
28+
setNoOpt()
2829

2930
var t tester
3031

@@ -325,10 +326,17 @@ func (t *tester) goTest() []string {
325326
}
326327

327328
func (t *tester) tags() string {
328-
if t.iOS() {
329+
ios := t.iOS()
330+
switch {
331+
case ios && noOpt:
332+
return "-tags=lldb,noopt"
333+
case ios:
329334
return "-tags=lldb"
335+
case noOpt:
336+
return "-tags=noopt"
337+
default:
338+
return "-tags="
330339
}
331-
return "-tags="
332340
}
333341

334342
// timeoutDuration converts the provided number of seconds into a

src/internal/testenv/noopt.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build noopt
6+
7+
package testenv
8+
9+
// OptimizationOff reports whether optimization is disabled.
10+
func OptimizationOff() bool {
11+
return true
12+
}

src/internal/testenv/opt.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !noopt
6+
7+
package testenv
8+
9+
// OptimizationOff reports whether optimization is disabled.
10+
func OptimizationOff() bool {
11+
return false
12+
}

src/internal/testenv/testenv.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,10 @@ func SkipIfShortAndSlow(t testing.TB) {
412412
func SkipIfOptimizationOff(t testing.TB) {
413413
if OptimizationOff() {
414414
t.Helper()
415-
t.Skip("skipping test with optimization disabled on builder")
415+
t.Skip("skipping test with optimization disabled")
416416
}
417417
}
418418

419-
// OptimizationOff reports whether optimization is disabled.
420-
func OptimizationOff() bool {
421-
return strings.HasSuffix(Builder(), "-noopt")
422-
}
423-
424419
// RunWithTimeout runs cmd and returns its combined output. If the
425420
// subprocess exits with a non-zero status, it will log that status
426421
// and return a non-nil error, but this is not considered fatal.

0 commit comments

Comments
 (0)