Skip to content

Commit

Permalink
Merge pull request #33 from hernoufM/opam-version
Browse files Browse the repository at this point in the history
Fix : opam version bindings
  • Loading branch information
rjbou committed May 5, 2023
2 parents e45a1e8 + 0a7f274 commit 4750def
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 37 deletions.
27 changes: 22 additions & 5 deletions src/opamBundleMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ let create_bundle ocamlv opamv repo debug output env test doc yes self_extract
();
let packages = List.map fst packages_targets in
let ocamlv = match ocamlv with
| Some v -> v
| Some v ->
OpamConsole.formatted_msg "OCaml version is set to %s.\n"
(OpamConsole.colorise `bold @@ OpamPackage.Version.to_string v);
v
| None ->
let v =
try
Expand All @@ -85,9 +88,22 @@ let create_bundle ocamlv opamv repo debug output env test doc yes self_extract
(OpamConsole.colorise `bold @@ OpamPackage.Version.to_string v);
v
in
let opamv = match opamv with
| Some v -> v
| None -> OpamPackage.Version.of_string "2.1.0~rc2"
let opamv =
match Option.map OpamPackage.Version.to_string opamv with
| Some v ->
let v = match v with
| "2.0" -> "2.0.10"
| "2.1" -> "2.1.4"
| _ -> v
in
OpamConsole.formatted_msg "Opam version is set to %s.\n"
(OpamConsole.colorise `bold v);
OpamPackage.Version.of_string v
| None ->
let default = "2.1.4" in
OpamConsole.formatted_msg "No opam version selected, will use %s.\n"
(OpamConsole.colorise `bold default);
OpamPackage.Version.of_string default
in
let output = match output, packages with
| Some f, _ ->
Expand Down Expand Up @@ -784,7 +800,8 @@ open Cmdliner

let pkg_version_conv =
Arg.conv ~docv:"VERSION" (
(fun s -> try Ok (OpamPackage.Version.of_string s) with Failure s ->
(fun s ->
try Ok (OpamPackage.Version.of_string s) with Failure s ->
Error (`Msg s)),
(fun ppf v -> Format.pp_print_string ppf (OpamPackage.Version.to_string v))
)
Expand Down
61 changes: 55 additions & 6 deletions tests/real/odoc.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ This test verify bundling of real package `odoc` with compiler version 4.02.3 an
$ export OPAMROOT=$PWD/OPAMROOT
$ export OPAMSTATUSLINE=never
$ export OPAMVERBOSE=-1
$ opam --version
2.1.4
$ opam-bundle odoc --ocaml=4.02.3 --opam=2.0 --self --yes 2>&1 | sed 's/arch =.*/arch = $ARCH/;s/os =.*/os = $OS/;s/os-distribution =.*/os-distribution = $OSDISTRIB/;s/os-version =.*/os-version = $OSVERSION/;s/os-family =.*/os-family = $OSFAMILLY/'
OCaml version is set to 4.02.3.
Opam version is set to 2.0.10.
No environment specified, will use the following for package resolution (based on the host system):
- arch = $ARCH
- os = $OS
Expand Down Expand Up @@ -56,13 +56,62 @@ This test verify bundling of real package `odoc` with compiler version 4.02.3 an
<><> Getting all archives <><><><><><><><><><><><><><><><><><><><><><><><><><><>
<><> Getting bootstrap packages <><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] Opam archive at https://github.com/ocaml/opam/releases/download/2.0/opam-full-2.0.tar.gz could not be obtained: curl error code 404
<><> Building bundle ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Done. Bundle generated as $TESTCASE_ROOT/odoc-bundle.tar.gz
Self-extracting archive generated as $TESTCASE_ROOT/odoc-bundle.sh
$ sh ./odoc-bundle.sh -y
sh: 0: cannot open ./odoc-bundle.sh: No such file
This bundle will compile the application to $TESTCASE_ROOT/odoc-bundle, WITHOUT installing
wrappers anywhere else.
================ Bootstrap: checking for prerequisites ================
Checking for cc... found
Checking for make... found
Checking for wget curl... found
Checking for patch... found
Checking for unzip... found
Checking for bunzip2... found
Checking for rsync... found
================ Bootstrap: compiling OCaml ================
This may take a while. Output is in $TESTCASE_ROOT/odoc-bundle/bootstrap.log
Uncompressing...
Something went wrong, see log in $TESTCASE_ROOT/odoc-bundle/bootstrap.log
[2]
$ sh ./odoc-bundle/compile.sh ../ODOC
sh: 0: cannot open ./odoc-bundle/compile.sh: No such file
[2]
This bundle will compile the application to $TESTCASE_ROOT/odoc-bundle, and put wrappers into
../ODOC/bin. You will need to retain $TESTCASE_ROOT/odoc-bundle for the wrappers to work.
Press enter to continue...
================ Bootstrap: checking for prerequisites ================
Checking for cc... found
Checking for make... found
Checking for wget curl... found
Checking for patch... found
Checking for unzip... found
Checking for bunzip2... found
Checking for rsync... found
================ Bootstrap: compiling OCaml ================
This may take a while. Output is in $TESTCASE_ROOT/odoc-bundle/bootstrap.log
Uncompressing...
Something went wrong, see log in $TESTCASE_ROOT/odoc-bundle/bootstrap.log
================ Compile: installing packages ================
Output is in $TESTCASE_ROOT/odoc-bundle/compile.log
./odoc-bundle/compile.sh: 59: cannot create $TESTCASE_ROOT/odoc-bundle/bootstrap/bin/sudo: Directory nonexistent
chmod: cannot access '$TESTCASE_ROOT/odoc-bundle/bootstrap/bin/sudo': No such file or directory
Compiling packages...
Something went wrong, see log in $TESTCASE_ROOT/odoc-bundle/compile.log
[50]
$ ODOC/bin/odoc
ODOC/bin/odoc: not found
[127]
93 changes: 84 additions & 9 deletions tests/real/opam-bundle.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ This test verify bundling of real package `opam-bundle` of version 0.4.
$ export OPAMROOT=$PWD/OPAMROOT
$ export OPAMSTATUSLINE=never
$ export OPAMVERBOSE=-1
$ opam --version
2.1.4
$ opam-bundle "opam-bundle@https://github.com/AltGr/opam-bundle/archive/refs/tags/0.4.tar.gz" opam-client.2.0.10 --self --opam=2.1 --ocaml=4.14.0 --yes 2>&1 | sed 's/arch =.*/arch = $ARCH/;s/os =.*/os = $OS/;s/os-distribution =.*/os-distribution = $OSDISTRIB/;s/os-version =.*/os-version = $OSVERSION/;s/os-family =.*/os-family = $OSFAMILLY/'
OCaml version is set to 4.14.0.
Opam version is set to 2.1.4.
No environment specified, will use the following for package resolution (based on the host system):
- arch = $ARCH
- os = $OS
Expand Down Expand Up @@ -60,13 +60,88 @@ This test verify bundling of real package `opam-bundle` of version 0.4.
<><> Getting all archives <><><><><><><><><><><><><><><><><><><><><><><><><><><>
<><> Getting bootstrap packages <><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] Opam archive at https://github.com/ocaml/opam/releases/download/2.1/opam-full-2.1.tar.gz could not be obtained: curl error code 404
<><> Building bundle ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
Done. Bundle generated as $TESTCASE_ROOT/opam-bundle-bundle.tar.gz
Self-extracting archive generated as $TESTCASE_ROOT/opam-bundle-bundle.sh
$ sh ./opam-bundle-bundle.sh -y
sh: 0: cannot open ./opam-bundle-bundle.sh: No such file
[2]
This bundle will compile the application to $TESTCASE_ROOT/opam-bundle-bundle, WITHOUT installing
wrappers anywhere else.
================ Bootstrap: checking for prerequisites ================
Checking for cc... found
Checking for make... found
Checking for wget curl... found
Checking for patch... found
Checking for unzip... found
Checking for bunzip2... found
Checking for rsync... found
================ Bootstrap: compiling OCaml ================
This may take a while. Output is in $TESTCASE_ROOT/opam-bundle-bundle/bootstrap.log
Uncompressing... done
Configuring... done
Compiling... done
Installing to temp prefix... done
================ Bootstrap: compiling opam ================
This may take a while. Output is in $TESTCASE_ROOT/opam-bundle-bundle/bootstrap.log
Uncompressing... done
Configuring... done
Compiling extra dependencies... done
Compiling... done
Installing to temp prefix... done
================ Configure: initialising opam ================
Output is in $TESTCASE_ROOT/opam-bundle-bundle/configure.log
Initialising... done
Creating sandbox... done
================ Compile: installing packages ================
Output is in $TESTCASE_ROOT/opam-bundle-bundle/compile.log
Compiling packages... done
Cleaning up... done
All compiled within $TESTCASE_ROOT/opam-bundle-bundle. To use the compiled packages:
- either re-run opam-bundle-bundle/compile.sh with a PREFIX argument to install command wrappers
(it won't recompile everything)

- or run the following to update the environment in the current shell, so that
they are in your PATH:
export PATH="$TESTCASE_ROOT/opam-bundle-bundle/bootstrap/bin:$PATH"; eval $(opam env --root "$TESTCASE_ROOT/opam-bundle-bundle/opam" --set-root)

$ sh ./opam-bundle-bundle/compile.sh ../BUNDLE
sh: 0: cannot open ./opam-bundle-bundle/compile.sh: No such file
[2]
This bundle will compile the application to $TESTCASE_ROOT/opam-bundle-bundle, and put wrappers into
../BUNDLE/bin. You will need to retain $TESTCASE_ROOT/opam-bundle-bundle for the wrappers to work.

Press enter to continue...
================ Bootstrap: checking for prerequisites ================

Checking for cc... found
Checking for make... found
Checking for wget curl... found
Checking for patch... found
Checking for unzip... found
Checking for bunzip2... found
Checking for rsync... found
Already compiled OCaml found
Already compiled opam found
Already initialised opam sandbox found

================ Compile: installing packages ================

Output is in $TESTCASE_ROOT/opam-bundle-bundle/compile.log
Compiling packages... done
Cleaning up... done
Wrapper opam-bundle installed successfully.
$ BUNDLE/bin/opam-bundle
BUNDLE/bin/opam-bundle: not found
[127]
opam-bundle: required argument PACKAGE is missing
Usage: opam-bundle [OPTION]… PACKAGE…
Try 'opam-bundle --help' for more information.
[1]
12 changes: 8 additions & 4 deletions tests/stub/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Repo initial setup with two packages `foo` and `bar` that depends on `foo` and o
$ export OPAMROOT=$PWD/OPAMROOT
$ export OPAMSTATUSLINE=never
$ export OPAMVERBOSE=-1
$ opam --version
2.1.4
$ cat > compile << EOF
> #!/bin/sh
> echo "I'm launching \$(basename \${0}) \$@!"
Expand Down Expand Up @@ -133,6 +131,8 @@ Running opam-bundle with sanitized output that contains remplaced platform speci
Bundle single package `foo`.
$ opam-bundle foo.1 --repository ./REPO --ocaml=4.14.0 -y 2>&1 | sed 's/arch =.*/arch = $ARCH/;s/os =.*/os = $OS/;s/os-distribution =.*/os-distribution = $OSDISTRIB/;s/os-version =.*/os-version = $OSVERSION/;s/os-family =.*/os-family = $OSFAMILLY/'
OCaml version is set to 4.14.0.
No opam version selected, will use 2.1.4.
No environment specified, will use the following for package resolution (based on the host system):
- arch = $ARCH
- os = $OS
Expand Down Expand Up @@ -164,7 +164,7 @@ Bundle single package `foo`.
foo-bundle/common.sh
foo-bundle/compile.sh
foo-bundle/configure.sh
foo-bundle/opam-full-2.1.0-rc2.tar.gz
foo-bundle/opam-full-2.1.4.tar.gz
foo-bundle/repo/
foo-bundle/repo/archives/
foo-bundle/repo/archives/foo.1/
Expand Down Expand Up @@ -238,6 +238,8 @@ Bundle single package `foo`.
Bundle package `bar` that depends on `foo`.
$ opam-bundle bar.1 --repository ./REPO --ocaml=4.14.0 -y 2>&1 | sed 's/arch =.*/arch = $ARCH/;s/os =.*/os = $OS/;s/os-distribution =.*/os-distribution = $OSDISTRIB/;s/os-version =.*/os-version = $OSVERSION/;s/os-family =.*/os-family = $OSFAMILLY/'
OCaml version is set to 4.14.0.
No opam version selected, will use 2.1.4.
No environment specified, will use the following for package resolution (based on the host system):
- arch = $ARCH
- os = $OS
Expand Down Expand Up @@ -270,7 +272,7 @@ Bundle package `bar` that depends on `foo`.
bar-bundle/common.sh
bar-bundle/compile.sh
bar-bundle/configure.sh
bar-bundle/opam-full-2.1.0-rc2.tar.gz
bar-bundle/opam-full-2.1.4.tar.gz
bar-bundle/repo/
bar-bundle/repo/archives/
bar-bundle/repo/archives/bar.1/
Expand Down Expand Up @@ -352,6 +354,8 @@ Cleaning up
Bundle package `bar` that depends on `foo` with self-extracting script.
$ opam-bundle bar.1 --self --repository ./REPO --ocaml=4.14.0 -y 2>&1 | sed 's/arch =.*/arch = $ARCH/;s/os =.*/os = $OS/;s/os-distribution =.*/os-distribution = $OSDISTRIB/;s/os-version =.*/os-version = $OSVERSION/;s/os-family =.*/os-family = $OSFAMILLY/'
OCaml version is set to 4.14.0.
No opam version selected, will use 2.1.4.
No environment specified, will use the following for package resolution (based on the host system):
- arch = $ARCH
- os = $OS
Expand Down
16 changes: 11 additions & 5 deletions tests/stub/env.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Repo initial setup with three packages `foo`, `bar`, and `baz`, with specific av
$ export OPAMROOT=$PWD/OPAMROOT
$ export OPAMSTATUSLINE=never
$ export OPAMVERBOSE=-1
$ opam --version
2.1.4
Stub executable
$ cat > compile << EOF
> #!/bin/sh
Expand Down Expand Up @@ -162,6 +160,8 @@ Bundle package `baz`, without '--environment' option. That should lookup current
are available on linux os (`foo` not included).
$ opam-bundle baz --repository ./REPO --ocaml=4.14.0 -y 2>&1 | sed 's/arch =.*/arch = $ARCH/;s/os =.*/os = $OS/;s/os-distribution =.*/os-distribution = $OSDISTRIB/;s/os-version =.*/os-version = $OSVERSION/;s/os-family =.*/os-family = $OSFAMILLY/'
OCaml version is set to 4.14.0.
No opam version selected, will use 2.1.4.
No environment specified, will use the following for package resolution (based on the host system):
- arch = $ARCH
- os = $OS
Expand Down Expand Up @@ -196,7 +196,7 @@ are available on linux os (`foo` not included).
baz-bundle/common.sh
baz-bundle/compile.sh
baz-bundle/configure.sh
baz-bundle/opam-full-2.1.0-rc2.tar.gz
baz-bundle/opam-full-2.1.4.tar.gz
baz-bundle/repo/
baz-bundle/repo/archives/
baz-bundle/repo/archives/bar.1/
Expand Down Expand Up @@ -241,6 +241,8 @@ Bundle package `baz`, with os="cygwin" constraint specified in '--environment' o
are available on cygwin os (`bar` not included).
$ opam-bundle baz --environment os="cygwin" --repository ./REPO --ocaml=4.14.0 -y 2>&1
OCaml version is set to 4.14.0.
No opam version selected, will use 2.1.4.
<><> Initialising repositories ><><><><><><><><><><><><><><><><><><><><><><><><>
[home] Initialised
Expand Down Expand Up @@ -271,7 +273,7 @@ are available on cygwin os (`bar` not included).
baz-bundle/common.sh
baz-bundle/compile.sh
baz-bundle/configure.sh
baz-bundle/opam-full-2.1.0-rc2.tar.gz
baz-bundle/opam-full-2.1.4.tar.gz
baz-bundle/repo/
baz-bundle/repo/archives/
baz-bundle/repo/archives/baz.1/
Expand Down Expand Up @@ -316,6 +318,8 @@ Bundle package `baz`, with empty constraint specified in '--environment' option.
all dependencies.
$ opam-bundle baz --environment --repository ./REPO --ocaml=4.14.0 -y 2>&1
OCaml version is set to 4.14.0.
No opam version selected, will use 2.1.4.
[NOTE] Empty environment
<><> Initialising repositories ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -348,7 +352,7 @@ all dependencies.
baz-bundle/common.sh
baz-bundle/compile.sh
baz-bundle/configure.sh
baz-bundle/opam-full-2.1.0-rc2.tar.gz
baz-bundle/opam-full-2.1.4.tar.gz
baz-bundle/repo/
baz-bundle/repo/archives/
baz-bundle/repo/archives/bar.1/
Expand Down Expand Up @@ -397,6 +401,8 @@ Trying bundle package `bar` on cygwin. That will fail, since this package isn't
$ opam-bundle bar --environment os="cygwin" --repository ./REPO --ocaml=4.14.0 -y 2>&1
OCaml version is set to 4.14.0.
No opam version selected, will use 2.1.4.
<><> Initialising repositories ><><><><><><><><><><><><><><><><><><><><><><><><>
[home] Initialised
Expand Down
Loading

0 comments on commit 4750def

Please sign in to comment.