Skip to content

Commit

Permalink
Silently mark packages requiring an unsupported version of opam as un…
Browse files Browse the repository at this point in the history
…available
  • Loading branch information
kit-ty-kate committed Sep 12, 2023
1 parent bbc2212 commit 85f6ebe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/format/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions src/state/opamFileTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 19 additions & 18 deletions tests/reftests/repository.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 85f6ebe

Please sign in to comment.