Skip to content

Commit

Permalink
Add ability to disable the version conflict failure, instead we warn.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner authored and Stefan Penner committed Feb 8, 2024
1 parent 9d36861 commit f7a7d32
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ _go_repository_config = repository_rule(
},
)

def fail_if_duplicate_modules_have_different_versions(version, previous, module_tag, module_name_to_go_dot_mod_label, go_works):
def fail_on_version_conflict(version, previous, module_tag, module_name_to_go_dot_mod_label, go_works, fail_or_warn):
"""
Check if duplicate modules have different versions, and fail with a useful error message if they do.
Expand Down Expand Up @@ -249,7 +249,12 @@ def fail_if_duplicate_modules_have_different_versions(version, previous, module_
else:
corrective_measure = "To correct this, run: go work sync."

fail("Multiple versions of {} found:\n - {} contains {}\n - {} contains {}.\n{}".format(module_tag.path, current_label, humanize_comparable_version(version), previous_label, humanize_comparable_version(previous.version), corrective_measure))
message = "Multiple versions of {} found:\n - {} contains {}\n - {} contains {}.\n{}".format(module_tag.path, current_label, humanize_comparable_version(version), previous_label, humanize_comparable_version(previous.version), corrective_measure)

if fail_or_warn:
fail(message)
else:
print(message)

def _fail_if_not_root(module, from_file_tag):
if module.is_root != True:
Expand Down Expand Up @@ -426,8 +431,10 @@ def _go_deps_impl(module_ctx):
version = semver.to_comparable(raw_version)
previous = paths.get(module_tag.path)

fail_or_warn = len([x for x in module.tags.from_file if x.fail_on_version_conflict == True ]) > 0

# rather then failing, we could do MVS here, or some other heuristic
fail_if_duplicate_modules_have_different_versions(version, previous, module_tag, module_name_to_go_dot_mod_label, go_works)
fail_on_version_conflict(version, previous, module_tag, module_name_to_go_dot_mod_label, go_works, fail_or_warn)
paths[module_tag.path] = struct(version = version, module_tag = module_tag)

if module_tag.path not in module_resolutions or version > module_resolutions[module_tag.path].version:
Expand Down Expand Up @@ -606,6 +613,7 @@ _from_file_tag = tag_class(
attrs = {
"go_mod": attr.label(mandatory = False),
"go_work": attr.label(mandatory = False),
"fail_on_version_conflict": attr.bool(default = True),
},
)

Expand Down

0 comments on commit f7a7d32

Please sign in to comment.