Skip to content

Commit ba7eba9

Browse files
authored
Support (and ignore) ‘tool’ directive in go.mod files. (#2064)
See https://go.dev/doc/modules/gomod-ref#tool and https://go.dev/doc/go1.24#tools. Fixes #2031 <!-- Thanks for sending a PR! Before submitting: 1. If this is your first PR, please read CONTRIBUTING.md and sign the CLA first. We cannot review code without a signed CLA. 2. Please file an issue *first*. All features and most bug fixes should have an associated issue with a design discussed and decided upon. Small bug fixes and documentation improvements don't need issues. 3. New features and bug fixes must have tests. Documentation may need to be updated. If you're unsure what to update, send the PR, and we'll discuss in review. --> **What type of PR is this?** Feature **What package or component does this PR mostly affect?** all **What does this PR do? Why is it needed?** Don't fail parsing of go.mod if it contains a tool directive. **Which issues(s) does this PR fix?** Fixes #2031
1 parent da58629 commit ba7eba9

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

internal/bzlmod/go_mod.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def parse_go_mod(content, path):
210210
continue
211211

212212
if not current_directive:
213-
if tokens[0] not in ["module", "go", "require", "replace", "exclude", "retract", "toolchain"]:
213+
if tokens[0] not in ["module", "go", "require", "replace", "exclude", "retract", "toolchain", "tool"]:
214214
fail("{}:{}: unexpected token '{}' at start of line".format(path, line_no, tokens[0]))
215215
if len(tokens) == 1:
216216
fail("{}:{}: expected another token after '{}'".format(path, line_no, tokens[0]))

tests/bzlmod/go_mod_test.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module github.com/bazelbuild/bazel-gazelle
2525
retract v1.0.0
2626
2727
require golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
28+
29+
tool golang.org/x/tools/cmd/bisect
2830
"""
2931

3032
_EXPECTED_GO_MOD_PARSE_RESULT = struct(

0 commit comments

Comments
 (0)