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

Use merge_all() in emit_archive. #3068

Merged
Merged
Changes from 3 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
26 changes: 22 additions & 4 deletions go/private/actions/archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ load(
"emit_compilepkg",
)

load("//go/private/skylib/lib:versions.bzl", "versions")

def emit_archive(go, source = None, _recompile_suffix = ""):
"""See go/toolchains.rst#archive for full documentation."""

Expand All @@ -65,10 +67,26 @@ def emit_archive(go, source = None, _recompile_suffix = ""):
direct = [get_archive(dep) for dep in source.deps]
runfiles = source.runfiles
data_files = runfiles.files
for a in direct:
runfiles = runfiles.merge(a.runfiles)
if a.source.mode != go.mode:
fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode)))

# After bazel version 5.0.0, skylark introduced a new API called merge_all().
# There is a recommendation in the release notes to use merge_all() if
# we hit the depth limit because of using merge() in a loop, we saw
# some repos hitting this issue after upgrading to 5.0.0
# To keep it backwards compatible, we will fallback to the old logic if
# the version is not at least 5.0.0
moisesvega marked this conversation as resolved.
Show resolved Hide resolved
# https://blog.bazel.build/2022/01/19/bazel-5.0.html#starlark-build-language
if versions.is_at_least("5.0.0", versions.get()):
files = []
for a in direct:
files.append(a.runfiles)
if a.source.mode != go.mode:
fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode)))
runfiles.merge_all(files)
else:
for a in direct:
runfiles = runfiles.merge(a.runfiles)
if a.source.mode != go.mode:
fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode)))

importmap = "main" if source.library.is_main else source.library.importmap
importpath, _ = effective_importpath_pkgpath(source.library)
Expand Down