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

Fix go.work use ROOT moddir #1800

Merged
merged 1 commit into from
May 11, 2024
Merged
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
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 (
.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a scenario I wasn't aware of, thanks for adding it!

./pkg
./tools
./proto
./tools
)

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