Skip to content

Commit

Permalink
Fix go.work use ROOT moddir (#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunshcn committed May 11, 2024
1 parent ba2ce36 commit 8643a9d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions internal/bzlmod/go_mod.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def use_spec_to_label(repo_name, use_directive):
if use_directive.endswith("/"):
use_directive = use_directive[:-1]

if use_directive == ".":
use_directive = ""

return Label("@@{}//{}:go.mod".format(repo_name, use_directive))

def go_work_from_label(module_ctx, go_work_label):
Expand Down Expand Up @@ -141,7 +144,7 @@ def _relativize_replace_paths(go_mod, go_mod_path):
new_go_mod = {
attr: getattr(go_mod, attr)
for attr in dir(go_mod)
if not type(getattr(go_mod, attr)) == 'builtin_function_or_method'
if not type(getattr(go_mod, attr)) == "builtin_function_or_method"
}

new_go_mod["replace_map"] = new_replace_map
Expand Down Expand Up @@ -300,7 +303,7 @@ def _parse_replace_directive(state, tokens, path, line_no):
from_version = _canonicalize_raw_version(tokens[1]),
to_path = from_path,
local_path = tokens[3],
version = COMPARES_HIGHEST_SENTINEL
version = COMPARES_HIGHEST_SENTINEL,
)

# pattern: replace from_path => to_path
Expand All @@ -309,7 +312,7 @@ def _parse_replace_directive(state, tokens, path, line_no):
from_version = None,
to_path = from_path,
local_path = tokens[2],
version = COMPARES_HIGHEST_SENTINEL
version = COMPARES_HIGHEST_SENTINEL,
)
else:
fail("{}:{}: unexpected tokens '{}'".format(path, line_no, tokens))
Expand Down
3 changes: 3 additions & 0 deletions tests/bcr/go_work/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/bazelbuild/bazel-gazelle/tests/bcr/go_work

go 1.21.0
3 changes: 2 additions & 1 deletion tests/bcr/go_work/go.work
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
go 1.21

use (
.
./pkg
./tools
./proto
./tools
)

replace example.org/hello => ../../fixtures/hello

0 comments on commit 8643a9d

Please sign in to comment.