Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip over godebug lines in go.mod/go.work files #1946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/bzlmod/go_mod.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def parse_go_work(content, go_work_label):
state["use"].append(tokens[0])
elif current_directive == "replace":
_parse_replace_directive(state, tokens, go_work_label.name, line_no)
elif current_directive == "godebug":
pass
else:
fail("{}:{}: unexpected directive '{}'".format(go_work_label.name, line_no, current_directive))
elif tokens[0] == "go":
Expand All @@ -101,6 +103,9 @@ def parse_go_work(content, go_work_label):
state["use"].append(tokens[1])
elif tokens[0] == "toolchain":
continue
elif tokens[0] == "godebug":
if tokens[1] == "(":
current_directive = tokens[0]
else:
fail("{}:{}: unexpected directive '{}'".format(go_work_label.name, line_no, tokens[0]))

Expand Down Expand Up @@ -210,7 +215,7 @@ def parse_go_mod(content, path):
continue

if not current_directive:
if tokens[0] not in ["module", "go", "require", "replace", "exclude", "retract", "toolchain"]:
if tokens[0] not in ["module", "go", "require", "replace", "exclude", "retract", "toolchain", "godebug"]:
fail("{}:{}: unexpected token '{}' at start of line".format(path, line_no, tokens[0]))
if len(tokens) == 1:
fail("{}:{}: expected another token after '{}'".format(path, line_no, tokens[0]))
Expand Down
14 changes: 14 additions & 0 deletions tests/bzlmod/go_mod_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ _GO_MOD_21_CONTENT = """go 1.21.0rc1
module example.com

toolchain go1.22.2

godebug (
default=go1.21
panicnil=1
asynctimerchan=0
)
godebug tlsrsakex=1
"""

_EXPECTED_GO_MOD_21_PARSE_RESULT = struct(
Expand Down Expand Up @@ -114,6 +121,13 @@ use (
replace github.com/go-fsnotify/fsnotify => github.com/fsnotify/fsnotify v1.4.2
replace github.com/bmatcuk/doublestar/v4 v4.0.2 => github.com/bmatcuk/doublestar/v4 v4.0.3
replace example.org/hello => ../fixtures/hello

godebug (
default=go1.21
panicnil=1
asynctimerchan=0
)
godebug tlsrsakex=1
"""

_EXPECTED_GO_WORK_PARSE_RESULT = struct(
Expand Down