Skip to content

Commit

Permalink
Merge pull request #215 from mtelvers/opam-2.2
Browse files Browse the repository at this point in the history
Add opam 2.2
  • Loading branch information
mtelvers authored Jul 15, 2024
2 parents 2a85231 + 29cc6d8 commit 6df7653
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
83 changes: 49 additions & 34 deletions src-opam/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,23 @@ let install_opam_from_source_windows ?cyg ?prefix
?(enable_0install_solver = false) ?(with_vendored_deps = false)
?(msvs = false) ~branch ~hash () =
Windows.Cygwin.run_sh ?cyg
"cd /tmp/opam-sources && cp -P -R -p . ../opam-build-%s && cd \
../opam-build-%s && git checkout %s && git config --global --add \
safe.directory /tmp/opam-build-%s"
branch branch hash branch
@@ Windows.Cygwin.run_sh ?cyg "cd /tmp/opam-build-%s && make compiler %s"
branch
(if msvs then "OCAML_PORT=msvc64" else "")
"git clone /tmp/opam /tmp/opam-build-%s && cd /tmp/opam-build-%s && git \
config --global --add safe.directory /tmp/opam-build-%s && git checkout \
%s"
branch branch branch hash
@@ Windows.Cygwin.run_sh ?cyg
"cd /tmp/opam-build-%s && ./configure --enable-cold-check %s%s%s%s && \
make && make install"
"cd /tmp/opam-build-%s && env \
PATH=\"/tmp/opam/bootstrap/ocaml/bin:$PATH\" ./configure \
--enable-cold-check %s%s%s%s && env \
PATH=\"/tmp/opam/bootstrap/ocaml/bin:$PATH\" make && make install && \
mv /usr/local/bin/opam.exe /usr/local/bin/opam-%s.exe"
branch
(if msvs then "" else "--with-private-runtime")
(if with_vendored_deps then " --with-vendored_deps" else "")
(if with_vendored_deps then " --with-vendored-deps" else "")
(Option.fold prefix ~none:"" ~some:(fun prefix ->
Printf.sprintf {| --prefix="%s"|} prefix))
(if enable_0install_solver then " --with-0install-solver" else "")
(* Docker doesn't allow copying executables from /usr/local/bin
(why??), so tar the opam installation. *)
@@ Windows.Cygwin.run_sh ?cyg
{|cd /usr/local/bin && tar -cf /cygdrive/c/opam.tar .|}
branch

let bubblewrap_minimum = (0, 4, 1)
let bubblewrap_latest = (0, 8, 0)
Expand Down Expand Up @@ -193,6 +190,7 @@ let header ?arch ?maintainer ?img ?tag d =
type opam_hashes = {
opam_2_0_hash : string;
opam_2_1_hash : string;
opam_2_2_hash : string;
opam_master_hash : string;
}

Expand All @@ -212,12 +210,13 @@ let opam_master_branch opam_master_hash =
enable_0install_solver = true;
with_vendored_deps = true;
public_name = "opam-dev";
aliases = [ "opam-2.2" ];
(* TODO: Remove/update when opam 2.2 is branched *)
aliases = [];
}

let create_opam_branches opam_hashes =
let { opam_2_0_hash; opam_2_1_hash; opam_master_hash } = opam_hashes in
let { opam_2_0_hash; opam_2_1_hash; opam_2_2_hash; opam_master_hash } =
opam_hashes
in
( opam_master_hash,
[
{
Expand All @@ -237,12 +236,26 @@ let create_opam_branches opam_hashes =
public_name = "opam-2.1";
aliases = [];
};
{
branch = "2.2";
hash = opam_2_2_hash;
enable_0install_solver = true;
with_vendored_deps = true;
public_name = "opam-2.2";
aliases = [];
};
opam_master_branch opam_master_hash;
] )

let create_opam_branches_windows opam_hashes =
let { opam_master_hash; _ } = opam_hashes in
(opam_master_hash, [ opam_master_branch opam_master_hash ])
let opam_master_hash, branches = create_opam_branches opam_hashes in
( opam_master_hash,
List.filter
(* Note this is a lexicographic comparison
* branches are "2.0", "2.1", "2.2" and "master"
* Select "master" and 2.2 and later *)
(fun { branch; _ } -> branch >= "2.2")
branches )

let install_opams ?prefix opam_master_hash opam_branches =
run
Expand All @@ -261,8 +274,9 @@ let install_opams_windows ?cyg ?prefix ?msvs opam_master_hash opam_branches =
Windows.Cygwin.Git.init ?cyg ~repos:[ "/tmp/opam-sources" ] ()
@@ Windows.Cygwin.run_sh ?cyg
"git clone https://github.com/ocaml/opam /tmp/opam && cd /tmp/opam && \
cp -P -R -p . ../opam-sources && git checkout %s"
git checkout %s && make compiler %s"
opam_master_hash
(if Option.value ~default:false msvs then "OCAML_PORT=msvc64" else "")
@@ List.fold_left
(fun acc { branch; hash; enable_0install_solver; with_vendored_deps; _ } ->
acc
Expand All @@ -283,22 +297,23 @@ let copy_opams ~src ~dst opam_branches =
aliases)
empty opam_branches

(* FIXME: only support building opam master for now *)
let copy_opams_windows = function
| [ { public_name; aliases; _ } ] ->
copy ~from:"opam-builder" ~src:[ {|C:\opam.tar|} ] ~dst:{|C:\TEMP\|} ()
@@ run
{|C:\cygwin64\bin\tar.exe -xf /cygdrive/c/TEMP/opam.tar -C /usr/local/bin && del C:\TEMP\opam.tar|}
@@ run
{|mklink C:\cygwin64\bin\%s.exe C:\cygwin64\usr\local\bin\opam.exe|}
public_name
let copy_opams_windows opam_branches =
List.fold_left
(fun acc { branch; public_name; aliases; _ } ->
acc
(* Docker doesn't allow copying executables to /usr/local/bin *)
@@ copy ~from:"opam-builder"
~src:[ {|C:\cygwin64\usr\local\bin\opam-|} ^ branch ^ ".exe" ]
~dst:({|C:\|} ^ public_name ^ ".exe")
()
@@ run {|move C:\%s.exe C:\cygwin64\usr\local\bin|} public_name
@@@ List.map
(fun alias ->
run {|mklink C:\cygwin64\bin\%s.exe C:\cygwin64\bin\%s.exe|} alias
public_name)
aliases
|> crunch
| _ -> invalid_arg "Only a single opam branch can be build on Windows."
run
{|mklink C:\cygwin64\bin\%s.exe C:\cygwin64\usr\local\bin\%s.exe|}
alias public_name)
aliases)
empty opam_branches

(* Apk based Dockerfile *)
let apk_opam2 ?(labels = []) ?arch ~opam_hashes distro () =
Expand Down
1 change: 1 addition & 0 deletions src-opam/opam.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ val install_opam_from_source :
type opam_hashes = {
opam_2_0_hash : string;
opam_2_1_hash : string;
opam_2_2_hash : string;
opam_master_hash : string;
}

Expand Down

0 comments on commit 6df7653

Please sign in to comment.