aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/build_tag_goexperiment.txt
blob: 26ad029845ee6edf58e459725e60d98303b4b696 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# compile_ext will fail if the buildtags that are enabled (or not enabled) for the
# framepointer and fieldtrack experiments are not consistent with the value of
# GOEXPSTRING (which comes from objabi.Expstring()).

[short] skip
go run m

-- expt_main.go --
package main

import (
	"os"
	"strings"
)

func main() {
  fp()
  ft()
}

func hasExpEntry(s string) bool {
	// script_test.go defines GOEXPSTRING to be the value of
	// objabi.Expstring(), which gives the enabled experiments baked into the
	// toolchain.
	g := os.Getenv("GOEXPSTRING")
	for _, f := range strings.Split(g, ",") {
		if f == s {
			return true
		}
	}
	return false
}

-- fp_off.go --
// +build !goexperiment.framepointer

package main

import (
	"fmt"
	"os"
)

func fp() {
	if hasExpEntry("framepointer") {
		fmt.Println("in !framepointer build, but objabi.Expstring() has 'framepointer'")
		os.Exit(1)
	}
}

-- fp_on.go --
// +build goexperiment.framepointer

package main

import (
	"fmt"
	"os"
)

func fp() {
	if !hasExpEntry("framepointer") {
		fmt.Println("in framepointer build, but objabi.Expstring() does not have 'framepointer', is", os.Getenv("GOEXPSTRING"))
		os.Exit(1)
	}
}

-- ft_off.go --
// +build !goexperiment.fieldtrack

package main

import (
	"fmt"
	"os"
)

func ft() {
	if hasExpEntry("fieldtrack") {
		fmt.Println("in !fieldtrack build, but objabi.Expstring() has 'fieldtrack'")
		os.Exit(1)
	}
}

-- ft_on.go --
// +build goexperiment.fieldtrack

package main

import (
	"fmt"
	"os"
)

func ft() {
	if !hasExpEntry("fieldtrack") {
		fmt.Println("in fieldtrack build, but objabi.Expstring() does not have 'fieldtrack', is", os.Getenv("GOEXPSTRING"))
		os.Exit(1)
	}
}

-- go.mod --
module m
go 1.14