From f7a7d32cb2eb49df4a481704c0a54941d97dccae Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Thu, 8 Feb 2024 09:57:20 -0700 Subject: [PATCH] Add ability to disable the version conflict failure, instead we warn. --- internal/bzlmod/go_deps.bzl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl index 411b523cb..485ce2ffd 100644 --- a/internal/bzlmod/go_deps.bzl +++ b/internal/bzlmod/go_deps.bzl @@ -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. @@ -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: @@ -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: @@ -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), }, )