From 93618ad0b833a70d77e41b2c3aaaa93ebecb6e04 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 5 Oct 2024 14:58:56 +0800 Subject: [PATCH] Skip over godebug lines in go.mod/go.work files Go 1.21 introduced support for godebug lines in go.mod and go.work files. Skip over these lines instead of failing Related #1945 --- internal/bzlmod/go_mod.bzl | 7 ++++++- tests/bzlmod/go_mod_test.bzl | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/bzlmod/go_mod.bzl b/internal/bzlmod/go_mod.bzl index 5baed71e9..264ac630a 100644 --- a/internal/bzlmod/go_mod.bzl +++ b/internal/bzlmod/go_mod.bzl @@ -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": @@ -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])) @@ -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])) diff --git a/tests/bzlmod/go_mod_test.bzl b/tests/bzlmod/go_mod_test.bzl index c05ba03a1..3d9e47e82 100644 --- a/tests/bzlmod/go_mod_test.bzl +++ b/tests/bzlmod/go_mod_test.bzl @@ -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( @@ -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(