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

Make go_deps restarts less costly #1667

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
# limitations under the License.

load("//internal:go_repository.bzl", "go_repository")
load(":go_mod.bzl", "deps_from_go_mod", "sums_from_go_mod")
load(
":go_mod.bzl",
"deps_from_go_mod",
"prefetch_files",
"sums_from_go_mod",
)
load(
":default_gazelle_overrides.bzl",
"DEFAULT_BUILD_EXTRA_ARGS_BY_PATH",
Expand Down Expand Up @@ -191,6 +196,10 @@ def _noop(_):
pass

def _go_deps_impl(module_ctx):
for module in module_ctx.modules:
for from_file_tag in module.tags.from_file:
prefetch_files(module_ctx, from_file_tag.go_mod)

module_resolutions = {}
sums = {}
replace_map = {}
Expand Down
22 changes: 15 additions & 7 deletions internal/bzlmod/go_mod.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ visibility([
"//tests/bzlmod/...",
])

def prefetch_files(module_ctx, go_mod_label):
go_mod_path = module_ctx.path(go_mod_label)
go_sum_path = module_ctx.path(go_mod_path.dirname.get_child("go.sum"))
if go_sum_path.exists:
module_ctx.path(_get_go_sum_label(go_mod_label))

def deps_from_go_mod(module_ctx, go_mod_label):
"""Loads the entries from a go.mod file.

Expand Down Expand Up @@ -225,13 +231,8 @@ def sums_from_go_mod(module_ctx, go_mod_label):
_check_go_mod_name(go_mod_label.name)

# We go through a Label so that the module extension is restarted if go.sum
# changes. We have to use a canonical label as we may not have visibility
# into the module that provides the go.sum.
go_sum_label = Label("@@{}//{}:{}".format(
go_mod_label.workspace_name,
go_mod_label.package,
"go.sum",
))
# changes.
go_sum_label = _get_go_sum_label(go_mod_label)
go_sum_content = module_ctx.read(go_sum_label)
return parse_go_sum(go_sum_content)

Expand All @@ -252,3 +253,10 @@ def _canonicalize_raw_version(raw_version):
if raw_version.startswith("v"):
return raw_version[1:]
return raw_version

def _get_go_sum_label(go_mod_label):
return Label("@@{}//{}:{}".format(
go_mod_label.workspace_name,
go_mod_label.package,
"go.sum",
))
Loading