From 593fb2ec0ed65bcb983facc1d90fc3c4c667cfa7 Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Tue, 1 Oct 2024 11:41:26 +0200 Subject: [PATCH] lint: fix W59 for local url (rsync) that are not archives --- master_changes.md | 1 + src/state/opamFileTools.ml | 12 +++++++++--- tests/reftests/lint.test | 8 ++------ tests/reftests/pin.test | 6 ------ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/master_changes.md b/master_changes.md index 3674ea7dde2..024eadbeb77 100644 --- a/master_changes.md +++ b/master_changes.md @@ -52,6 +52,7 @@ users) ## Source ## Lint + * [BUG] fix lint W59 with local urls that are not archives [#6219 @rjbou - fix #6218] ## Repository diff --git a/src/state/opamFileTools.ml b/src/state/opamFileTools.ml index 804a54c6a17..c27ed93f5b7 100644 --- a/src/state/opamFileTools.ml +++ b/src/state/opamFileTools.ml @@ -396,9 +396,15 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t = | #OpamUrl.version_control -> true | _ -> false) in + let url_archive = + let open OpamStd.Option.Op in + t.url >>| OpamFile.URL.url >>| (fun u -> + OpamSystem.is_archive_from_string u.OpamUrl.path) + in let is_url_archive = - not (OpamFile.OPAM.has_flag Pkgflag_Conf t) && - url_vcs = Some false + not (OpamFile.OPAM.has_flag Pkgflag_Conf t) + && url_vcs = Some false + && url_archive = Some true in let check_upstream = check_upstream && is_url_archive in let check_double compare to_str lst = @@ -1001,7 +1007,7 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t = |> List.map OpamHash.to_string |> OpamStd.Format.pretty_list)]) t.url) - (url_vcs = Some true + (url_vcs = Some true && url_archive = Some false && OpamStd.Option.Op.(t.url >>| fun u -> OpamFile.URL.checksum u <> []) = Some true); cond 68 `Warning diff --git a/tests/reftests/lint.test b/tests/reftests/lint.test index 942dad30a53..d2bc8384ac4 100644 --- a/tests/reftests/lint.test +++ b/tests/reftests/lint.test @@ -909,13 +909,9 @@ url { src:"file://$basedir/an-archive" } EOF ### sh add-url.sh ### opam lint ./lint.opam -${BASEDIR}/lint.opam: Warnings. - warning 59: url doesn't contain a checksum +${BASEDIR}/lint.opam: Passed. ### opam lint ./lint.opam --check-upstream -${BASEDIR}/lint.opam: Errors. - warning 59: url doesn't contain a checksum - error 60: Upstream check failed: "Source not found: ${BASEDIR}/an-archive" -# Return code 1 # +${BASEDIR}/lint.opam: Passed. ### # package with local archive url ### opam-version: "2.0" diff --git a/tests/reftests/pin.test b/tests/reftests/pin.test index cdaecb87c81..09916bccde0 100644 --- a/tests/reftests/pin.test +++ b/tests/reftests/pin.test @@ -499,9 +499,6 @@ The following actions will be performed: -> installed nip-path.ved Done. ### opam pin edit nip-path -[WARNING] The opam file didn't pass validation: - warning 59: url doesn't contain a checksum -Proceed anyway ('no' will re-edit)? [y/n] y You can edit this file again with "opam pin edit nip-path", export it with "opam show nip-path --raw" Save the new opam file back to "${BASEDIR}/nip-path/nip-path.opam"? [y/n] y The following actions will be performed: @@ -523,9 +520,6 @@ The following actions will be performed: # Return code 31 # ### opam pin add ./nip-path2 --edit Package nip-path2 does not exist, create as a NEW package? [y/n] y -[WARNING] The opam file didn't pass validation: - warning 59: url doesn't contain a checksum -Proceed anyway ('no' will re-edit)? [y/n] y You can edit this file again with "opam pin edit nip-path2", export it with "opam show nip-path2 --raw" nip-path2 is now pinned to file://${BASEDIR}/nip-path2 (version ved)