aboutsummaryrefslogtreecommitdiff
path: root/src/internal/godebug
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-10-17 15:34:50 -0400
committerGopher Robot <gobot@golang.org>2022-10-18 14:49:44 +0000
commit8dc08394f0d5f83523080e4dd99fded26b7c1ceb (patch)
tree06dc72d439c842aea68df4834e1310ac207fade7 /src/internal/godebug
parent9fedc481ea09a0539cd2669312429ef5416a8949 (diff)
downloadgo-8dc08394f0d5f83523080e4dd99fded26b7c1ceb.tar.xz
internal/godebug: remove dependency on os
The immediate reason is that we want to use godebug from math/rand, and math/rand importing godebug importing os causes an import cycle in package testing. More generally, the new approach to backward compatibility outlined in discussion #55090 will require using this package from other similarly sensitive places, perhaps even package os itself. Best to remove all dependencies. Preparation for #54880. Change-Id: Ia01657a2d90e707a8121a336c9db3b7247c0198f Reviewed-on: https://go-review.googlesource.com/c/go/+/439418 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/internal/godebug')
-rw-r--r--src/internal/godebug/export_test.go7
-rw-r--r--src/internal/godebug/godebug.go7
-rw-r--r--src/internal/godebug/godebug_test.go9
3 files changed, 18 insertions, 5 deletions
diff --git a/src/internal/godebug/export_test.go b/src/internal/godebug/export_test.go
new file mode 100644
index 0000000000..e84d9a9912
--- /dev/null
+++ b/src/internal/godebug/export_test.go
@@ -0,0 +1,7 @@
+// 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.
+
+package godebug
+
+var Xget = get
diff --git a/src/internal/godebug/godebug.go b/src/internal/godebug/godebug.go
index ac434e5fd8..65a8c4e305 100644
--- a/src/internal/godebug/godebug.go
+++ b/src/internal/godebug/godebug.go
@@ -5,11 +5,14 @@
// Package godebug parses the GODEBUG environment variable.
package godebug
-import "os"
+import _ "unsafe" // go:linkname
+
+//go:linkname getGODEBUG
+func getGODEBUG() string
// Get returns the value for the provided GODEBUG key.
func Get(key string) string {
- return get(os.Getenv("GODEBUG"), key)
+ return get(getGODEBUG(), key)
}
// get returns the value part of key=value in s (a GODEBUG value).
diff --git a/src/internal/godebug/godebug_test.go b/src/internal/godebug/godebug_test.go
index 41b9117b73..d7a2a7a8d8 100644
--- a/src/internal/godebug/godebug_test.go
+++ b/src/internal/godebug/godebug_test.go
@@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package godebug
+package godebug_test
-import "testing"
+import (
+ . "internal/godebug"
+ "testing"
+)
func TestGet(t *testing.T) {
tests := []struct {
@@ -26,7 +29,7 @@ func TestGet(t *testing.T) {
{"foo=bar,baz", "loooooooong", ""},
}
for _, tt := range tests {
- got := get(tt.godebug, tt.key)
+ got := Xget(tt.godebug, tt.key)
if got != tt.want {
t.Errorf("get(%q, %q) = %q; want %q", tt.godebug, tt.key, got, tt.want)
}