diff options
Diffstat (limited to 'meta/recipes-devtools/go/go-1.19/add_godebug.patch')
| -rw-r--r-- | meta/recipes-devtools/go/go-1.19/add_godebug.patch | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go-1.19/add_godebug.patch b/meta/recipes-devtools/go/go-1.19/add_godebug.patch new file mode 100644 index 0000000000..0c3d2d2855 --- /dev/null +++ b/meta/recipes-devtools/go/go-1.19/add_godebug.patch | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | |||
| 2 | Upstream-Status: Backport [see text] | ||
| 3 | |||
| 4 | https://github.com/golong/go.git as of commit 22c1d18a27... | ||
| 5 | Copy src/internal/godebug from go 1.19 since it does not | ||
| 6 | exist in 1.17. | ||
| 7 | |||
| 8 | Signed-off-by: Joe Slater <joe.slater@windriver.com> | ||
| 9 | --- | ||
| 10 | |||
| 11 | --- /dev/null | ||
| 12 | +++ go/src/internal/godebug/godebug.go | ||
| 13 | @@ -0,0 +1,34 @@ | ||
| 14 | +// Copyright 2021 The Go Authors. All rights reserved. | ||
| 15 | +// Use of this source code is governed by a BSD-style | ||
| 16 | +// license that can be found in the LICENSE file. | ||
| 17 | + | ||
| 18 | +// Package godebug parses the GODEBUG environment variable. | ||
| 19 | +package godebug | ||
| 20 | + | ||
| 21 | +import "os" | ||
| 22 | + | ||
| 23 | +// Get returns the value for the provided GODEBUG key. | ||
| 24 | +func Get(key string) string { | ||
| 25 | + return get(os.Getenv("GODEBUG"), key) | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +// get returns the value part of key=value in s (a GODEBUG value). | ||
| 29 | +func get(s, key string) string { | ||
| 30 | + for i := 0; i < len(s)-len(key)-1; i++ { | ||
| 31 | + if i > 0 && s[i-1] != ',' { | ||
| 32 | + continue | ||
| 33 | + } | ||
| 34 | + afterKey := s[i+len(key):] | ||
| 35 | + if afterKey[0] != '=' || s[i:i+len(key)] != key { | ||
| 36 | + continue | ||
| 37 | + } | ||
| 38 | + val := afterKey[1:] | ||
| 39 | + for i, b := range val { | ||
| 40 | + if b == ',' { | ||
| 41 | + return val[:i] | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + return val | ||
| 45 | + } | ||
| 46 | + return "" | ||
| 47 | +} | ||
| 48 | --- /dev/null | ||
| 49 | +++ go/src/internal/godebug/godebug_test.go | ||
| 50 | @@ -0,0 +1,34 @@ | ||
| 51 | +// Copyright 2021 The Go Authors. All rights reserved. | ||
| 52 | +// Use of this source code is governed by a BSD-style | ||
| 53 | +// license that can be found in the LICENSE file. | ||
| 54 | + | ||
| 55 | +package godebug | ||
| 56 | + | ||
| 57 | +import "testing" | ||
| 58 | + | ||
| 59 | +func TestGet(t *testing.T) { | ||
| 60 | + tests := []struct { | ||
| 61 | + godebug string | ||
| 62 | + key string | ||
| 63 | + want string | ||
| 64 | + }{ | ||
| 65 | + {"", "", ""}, | ||
| 66 | + {"", "foo", ""}, | ||
| 67 | + {"foo=bar", "foo", "bar"}, | ||
| 68 | + {"foo=bar,after=x", "foo", "bar"}, | ||
| 69 | + {"before=x,foo=bar,after=x", "foo", "bar"}, | ||
| 70 | + {"before=x,foo=bar", "foo", "bar"}, | ||
| 71 | + {",,,foo=bar,,,", "foo", "bar"}, | ||
| 72 | + {"foodecoy=wrong,foo=bar", "foo", "bar"}, | ||
| 73 | + {"foo=", "foo", ""}, | ||
| 74 | + {"foo", "foo", ""}, | ||
| 75 | + {",foo", "foo", ""}, | ||
| 76 | + {"foo=bar,baz", "loooooooong", ""}, | ||
| 77 | + } | ||
| 78 | + for _, tt := range tests { | ||
| 79 | + got := get(tt.godebug, tt.key) | ||
| 80 | + if got != tt.want { | ||
| 81 | + t.Errorf("get(%q, %q) = %q; want %q", tt.godebug, tt.key, got, tt.want) | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | +} | ||
