From 85f6ebe8b32c10d755f1a94150ad65b83b4aee0c Mon Sep 17 00:00:00 2001 From: Kate Date: Tue, 12 Sep 2023 17:09:34 +0100 Subject: [PATCH] Silently mark packages requiring an unsupported version of opam as unavailable --- master_changes.md | 1 + src/format/opamFile.ml | 4 ++-- src/state/opamFileTools.ml | 4 ++++ tests/reftests/repository.test | 37 +++++++++++++++++----------------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/master_changes.md b/master_changes.md index 3c2b50005b0..2e4b2391851 100644 --- a/master_changes.md +++ b/master_changes.md @@ -55,6 +55,7 @@ users) ## Repository * Fix `OPAMCURL` and `OPAMFETCH` handling [#5607 @rjbou - fix #5597] + * Silently mark packages requiring an unsupported version of opam as unavailable [#5665 @kit-ty-kate - fix #5631] ## Lock diff --git a/src/format/opamFile.ml b/src/format/opamFile.ml index 54701b9426d..ab9f5d569aa 100644 --- a/src/format/opamFile.ml +++ b/src/format/opamFile.ml @@ -136,7 +136,7 @@ module MakeIO (F : IO_Arg) = struct with | OpamSystem.File_not_found _ -> None - | e -> + | Pp.Bad_format _ as e -> OpamStd.Exn.fatal e; if OpamFormatConfig.(!r.strict) then (OpamConsole.error "%s" @@ -166,7 +166,7 @@ module MakeIO (F : IO_Arg) = struct let read_from_f f input = try f input with - | (Pp.Bad_version _ | Pp.Bad_format _) as e-> + | Pp.Bad_format _ as e -> if OpamFormatConfig.(!r.strict) then (OpamConsole.error "%s" (Pp.string_of_bad_format e); OpamConsole.error_and_exit `File_error "Strict mode: aborting") diff --git a/src/state/opamFileTools.ml b/src/state/opamFileTools.ml index df182e48893..6ad387b2b29 100644 --- a/src/state/opamFileTools.ml +++ b/src/state/opamFileTools.ml @@ -1192,6 +1192,10 @@ let read_opam dir = (OpamPp.string_of_bad_format (OpamPp.Bad_format (snd err))); None | None, None -> None + | exception (OpamPp.Bad_version _bf) -> + log "opam-version unsupported on %s. Add as dummy unavailable package." + (OpamFile.to_string opam_file); + Some (OpamFile.OPAM.with_available (FBool false) OpamFile.OPAM.empty) let read_repo_opam ~repo_name ~repo_root dir = let open OpamStd.Option.Op in diff --git a/tests/reftests/repository.test b/tests/reftests/repository.test index 64321a6638d..6b14a7b9ff7 100644 --- a/tests/reftests/repository.test +++ b/tests/reftests/repository.test @@ -605,14 +605,12 @@ some-field-that-do-not-exist: true <><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><> [oper] synchronised from file://${BASEDIR}/OPER3 -[ERROR] In ${OPAMTMP}/oper/packages/bad-opam-version/bad-opam-version.1/opam: - unsupported or missing file format version; should be 2.0 or older -[ERROR] Strict mode: aborting -[ERROR] Could not update repository "oper": OpamStd.OpamSys.Exit(30) +opam-file opam-version unsupported on ${OPAMTMP}/oper/packages/bad-opam-version/bad-opam-version.1/opam. Add as dummy unavailable package. [repo] no changes from file://${BASEDIR}/REPO [repo2] no changes from file://${BASEDIR}/REPO2 -# Return code 40 # +Now run 'opam upgrade' to apply any package updates. ### opam list -A --all-versions -s +bad-opam-version.1 foo.1 foo.2 foo.3 @@ -630,14 +628,15 @@ opam-version: "2.0" <><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><> [oper] synchronised from file://${BASEDIR}/OPER3 -[ERROR] Could not update repository "oper": In ${OPAMTMP}/oper/packages/bad-opam-version/bad-opam-version.1/opam: - unsupported or missing file format version; should be 2.0 or older +opam-file opam-version unsupported on ${OPAMTMP}/oper/packages/bad-opam-version/bad-opam-version.1/opam. Add as dummy unavailable package. [repo] synchronised from file://${BASEDIR}/REPO -[ERROR] Could not update repository "repo": In ${OPAMTMP}/repo/packages/bad-opam-version/bad-opam-version.2/opam: - unsupported or missing file format version; should be 2.0 or older +opam-file opam-version unsupported on ${OPAMTMP}/repo/packages/bad-opam-version/bad-opam-version.2/opam. Add as dummy unavailable package. [repo2] no changes from file://${BASEDIR}/REPO2 -# Return code 40 # +Now run 'opam upgrade' to apply any package updates. ### opam list -A --all-versions -s +a.1 +bad-opam-version.1 +bad-opam-version.2 foo.1 foo.2 foo.3 @@ -650,14 +649,16 @@ third.3 ### opam list -A --all-versions -s ### opam repository --this-switch add repo ./REPO [repo] Initialised -[ERROR] Could not update repository "repo": In ${BASEDIR}/OPAM/repo/repo/packages/bad-opam-version/bad-opam-version.2/opam: - unsupported or missing file format version; should be 2.0 or older -[ERROR] Initial repository fetch failed -# Return code 40 # ### opam repository --this-switch add oper ./OPER3 [oper] Initialised -[ERROR] Could not update repository "oper": In ${BASEDIR}/OPAM/repo/oper/packages/bad-opam-version/bad-opam-version.1/opam: - unsupported or missing file format version; should be 2.0 or older -[ERROR] Initial repository fetch failed -# Return code 40 # ### opam list -A --all-versions -s +a.1 +bad-opam-version.1 +bad-opam-version.2 +foo.1 +foo.2 +foo.3 +foo.4 +foo.5 +foo.6 +third.3