From d4d21af8b111f2964e185c3a7b1f814e7327ba75 Mon Sep 17 00:00:00 2001 From: Mark Elvers Date: Wed, 4 Dec 2024 14:31:40 +0000 Subject: [PATCH 1/5] Fake `dune-project` file --- lib/opam_build.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/opam_build.ml b/lib/opam_build.ml index c1b6c157..05b9aa5b 100644 --- a/lib/opam_build.ml +++ b/lib/opam_build.ml @@ -65,8 +65,10 @@ let pin_opam_files ~network ?work_dir groups = work_dir |> Option.value ~default:dir in - Printf.sprintf "opam pin add -yn %s %s" pkg - (Filename.quote (Fpath.to_string dir)))) + Printf.sprintf "opam pin add -yn %s %s && echo '(lang dune 3.0)' > %s" pkg + (Filename.quote (Fpath.to_string dir)) + (Filename.quote (Fpath.to_string (Fpath.( // ) dir (Fpath.v "dune-project")))) + )) |> String.concat " && \n" |> run ~network "%s"; ] From face39e0fa3e9ade21645e4423e41837be99db7d Mon Sep 17 00:00:00 2001 From: Mark Elvers Date: Wed, 4 Dec 2024 16:22:45 +0000 Subject: [PATCH 2/5] Fix tests --- test/service/test_spec.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/service/test_spec.ml b/test/service/test_spec.ml index d2194253..799dfa05 100644 --- a/test/service/test_spec.ml +++ b/test/service/test_spec.ml @@ -14,7 +14,7 @@ let expected_macos_spec = (shell "cd ~/opam-repository && (git cat-file -e f207d3f018d642d1fcddb2c118e7fa8e65f4e366 || git fetch origin master) && git reset -q --hard f207d3f018d642d1fcddb2c118e7fa8e65f4e366 && git log --no-decorate -n1 --oneline && opam update -u")) (copy (src bondi.opam) (dst ./src/./)) (run (network host) - (shell "opam pin add -yn bondi.dev './src/./'")) + (shell "opam pin add -yn bondi.dev './src/./' && echo '(lang dune 3.0)' > './src/./dune-project'")) (env DEPS "base-bigarray.base base-threads.base base-unix.base dune.3.6.0 menhir.20220210 menhirLib.20220210 menhirSdk.20220210 ocaml.4.14.0 ocaml-base-compiler.4.14.0 ocaml-config.2 ocaml-options-vanilla.1") (env CI true) (env OCAMLCI true) @@ -49,7 +49,7 @@ let expected_linux_spec = (shell "cd ~/opam-repository && (git cat-file -e f207d3f018d642d1fcddb2c118e7fa8e65f4e366 || git fetch origin master) && git reset -q --hard f207d3f018d642d1fcddb2c118e7fa8e65f4e366 && git log --no-decorate -n1 --oneline && opam update -u")) (copy (src bondi.opam) (dst ./)) (run (network host) - (shell "opam pin add -yn bondi.dev './'")) + (shell "opam pin add -yn bondi.dev './' && echo '(lang dune 3.0)' > './dune-project'")) (env DEPS "base-bigarray.base base-threads.base base-unix.base dune.3.6.0 menhir.20220210 menhirLib.20220210 menhirSdk.20220210 ocaml.4.14.0 ocaml-base-compiler.4.14.0 ocaml-config.2 ocaml-options-vanilla.1") (env CI true) (env OCAMLCI true) From a1ec0ca3099b4fef3777c8b2f35a4ea2df89d119 Mon Sep 17 00:00:00 2001 From: Mark Elvers Date: Wed, 4 Dec 2024 19:29:10 +0000 Subject: [PATCH 3/5] @fmt --- lib/opam_build.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/opam_build.ml b/lib/opam_build.ml index 05b9aa5b..a03c401c 100644 --- a/lib/opam_build.ml +++ b/lib/opam_build.ml @@ -65,10 +65,13 @@ let pin_opam_files ~network ?work_dir groups = work_dir |> Option.value ~default:dir in - Printf.sprintf "opam pin add -yn %s %s && echo '(lang dune 3.0)' > %s" pkg + Printf.sprintf + "opam pin add -yn %s %s && echo '(lang dune 3.0)' > %s" + pkg (Filename.quote (Fpath.to_string dir)) - (Filename.quote (Fpath.to_string (Fpath.( // ) dir (Fpath.v "dune-project")))) - )) + (Filename.quote + (Fpath.to_string + (Fpath.( // ) dir (Fpath.v "dune-project")))))) |> String.concat " && \n" |> run ~network "%s"; ] From b259c8b69f280436328708aea520f2671f8185db Mon Sep 17 00:00:00 2001 From: Mark Elvers Date: Wed, 4 Dec 2024 21:37:46 +0000 Subject: [PATCH 4/5] Fix Windows and add test --- lib/opam_build.ml | 35 +++++++++++++++---- test/service/test_spec.ml | 73 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 9 deletions(-) diff --git a/lib/opam_build.ml b/lib/opam_build.ml index a03c401c..182c4f6a 100644 --- a/lib/opam_build.ml +++ b/lib/opam_build.ml @@ -65,17 +65,32 @@ let pin_opam_files ~network ?work_dir groups = work_dir |> Option.value ~default:dir in - Printf.sprintf - "opam pin add -yn %s %s && echo '(lang dune 3.0)' > %s" - pkg - (Filename.quote (Fpath.to_string dir)) - (Filename.quote - (Fpath.to_string - (Fpath.( // ) dir (Fpath.v "dune-project")))))) + Printf.sprintf "opam pin add -yn %s %s" pkg + (Filename.quote (Fpath.to_string dir)))) |> String.concat " && \n" |> run ~network "%s"; ] +let create_dune_project_files ~network ?dune_work_dir groups = + if groups = [] then [] + else + let open Obuilder_spec in + [ + groups + |> List.map (fun (dir, _, _) -> + let dir = + Option.map + (fun work_dir -> Fpath.( // ) work_dir dir) + dune_work_dir + |> Option.value ~default:dir + in + Printf.sprintf "echo '(lang dune 3.0)' > %s" + (Filename.quote + (Fpath.to_string (Fpath.( // ) dir (Fpath.v "dune-project"))))) + |> String.concat " && \n" + |> run ~network "%s"; + ] + (* Get the packages directly in "." *) let rec get_root_opam_packages = function | [] -> [] @@ -155,6 +170,11 @@ let install_project_deps ~opam_version ~opam_files ~selection = | `linux -> None | `freeBSD -> None in + let dune_work_dir = + match Variant.os selection.Selection.variant with + | `macOS | `linux | `freeBSD | `openBSD -> work_dir + | `windows -> Some (Fpath.v "/cygdrive/c/Users/opam/src") + in (* XXX: don't overwrite default config? *) let opamrc = "" in let opam_version_str = Opam_version.to_string opam_version in @@ -206,6 +226,7 @@ let install_project_deps ~opam_version ~opam_files ~selection = commit commit; ] @ pin_opam_files ~network ?work_dir groups + @ create_dune_project_files ~network ?dune_work_dir groups @ [ env "DEPS" non_root_pkgs; env "CI" "true"; diff --git a/test/service/test_spec.ml b/test/service/test_spec.ml index 799dfa05..c2b0f8a4 100644 --- a/test/service/test_spec.ml +++ b/test/service/test_spec.ml @@ -14,7 +14,9 @@ let expected_macos_spec = (shell "cd ~/opam-repository && (git cat-file -e f207d3f018d642d1fcddb2c118e7fa8e65f4e366 || git fetch origin master) && git reset -q --hard f207d3f018d642d1fcddb2c118e7fa8e65f4e366 && git log --no-decorate -n1 --oneline && opam update -u")) (copy (src bondi.opam) (dst ./src/./)) (run (network host) - (shell "opam pin add -yn bondi.dev './src/./' && echo '(lang dune 3.0)' > './src/./dune-project'")) + (shell "opam pin add -yn bondi.dev './src/./'")) + (run (network host) + (shell "echo '(lang dune 3.0)' > './src/./dune-project'")) (env DEPS "base-bigarray.base base-threads.base base-unix.base dune.3.6.0 menhir.20220210 menhirLib.20220210 menhirSdk.20220210 ocaml.4.14.0 ocaml-base-compiler.4.14.0 ocaml-config.2 ocaml-options-vanilla.1") (env CI true) (env OCAMLCI true) @@ -49,7 +51,9 @@ let expected_linux_spec = (shell "cd ~/opam-repository && (git cat-file -e f207d3f018d642d1fcddb2c118e7fa8e65f4e366 || git fetch origin master) && git reset -q --hard f207d3f018d642d1fcddb2c118e7fa8e65f4e366 && git log --no-decorate -n1 --oneline && opam update -u")) (copy (src bondi.opam) (dst ./)) (run (network host) - (shell "opam pin add -yn bondi.dev './' && echo '(lang dune 3.0)' > './dune-project'")) + (shell "opam pin add -yn bondi.dev './'")) + (run (network host) + (shell "echo '(lang dune 3.0)' > './dune-project'")) (env DEPS "base-bigarray.base base-threads.base base-unix.base dune.3.6.0 menhir.20220210 menhirLib.20220210 menhirSdk.20220210 ocaml.4.14.0 ocaml-base-compiler.4.14.0 ocaml-config.2 ocaml-options-vanilla.1") (env CI true) (env OCAMLCI true) @@ -64,6 +68,40 @@ let expected_linux_spec = ) |} +(* Expected obuilder spec for windows server 2022 build of bondi. *) +let expected_windows_spec = + {| +((from windows-server-2022-amd64-ocaml-4.14) + (comment windows-server-2022-4.14.0_opam-2.3) + (user (uid 1000) (gid 1000)) (env CLICOLOR_FORCE 1) + (env OPAMCOLOR always) + (workdir /src) + (run (shell "sudo ln -f /usr/bin/opam-2.3 /usr/bin/opam")) + (run (shell "opam init --reinit -ni")) + (run (shell "uname -rs && opam exec -- ocaml -version && opam --version")) + (workdir /src) + (run (shell "sudo chown opam /src")) + (run (cache (opam-archives (target /home/opam/.opam/download-cache))) + (network host) (shell "cd ~/opam-repository && (git cat-file -e f207d3f018d642d1fcddb2c118e7fa8e65f4e366 || git fetch origin master) && git reset -q --hard f207d3f018d642d1fcddb2c118e7fa8e65f4e366 && git log --no-decorate -n1 --oneline && opam update -u")) + (copy (src bondi.opam) (dst ./)) + (run (network host) (shell "opam pin add -yn bondi.dev './'")) + (run (network host) + (shell "echo '(lang dune 3.0)' > './dune-project'")) + (env DEPS "arch-x86_64.1 base-bigarray.base base-threads.base base-unix.base conf-mingw-w64-gcc-x86_64.1 dune.3.17.0 flexdll.0.43 host-arch-x86_64.1 host-system-mingw.1 menhir.20240715 menhirCST.20240715 menhirLib.20240715 menhirSdk.20240715 mingw-w64-shims.0.2.0 ocaml.4.14.2 ocaml-base-compiler.4.14.2 ocaml-config.3 ocaml-env-mingw64.1 ocaml-options-vanilla.1 system-mingw.1") + (env CI true) + (env OCAMLCI true) + (run (cache (opam-archives (target /home/opam/.opam/download-cache))) + (network host) + (shell "opam update --depexts && opam install --cli=2.3 --depext-only -y bondi.dev $DEPS")) + (run (cache + (opam-archives (target /home/opam/.opam/download-cache))) + (network host) + (shell "opam install $DEPS")) + (copy (src .) (dst /src)) + (run (shell "opam exec -- dune build @install @check @runtest && rm -rf _build")) +) +|} + (* Create testable Sexp for Alcotest. *) let sexp = Alcotest.testable Sexplib0__Sexp.pp_hum Sexplib0__Sexp.equal @@ -145,8 +183,39 @@ let test_linux_spec () = in Alcotest.(check sexp) "validate" expected actual +let test_windows_spec () = + let open Ocaml_ci in + let expected = Sexplib__Pre_sexp.of_string expected_windows_spec in + let variant = + Variant.v ~arch:`X86_64 ~distro:"windows-server-2022" + ~ocaml_version:Ocaml_version.Releases.v4_14_0 ~opam_version:`V2_3 + |> Result.get_ok + in + let actual = + Opam_build.spec + ~base: + "windows-server-2022-amd64-ocaml-4.14" + ~opam_version:`V2_3 ~opam_files:[ "bondi.opam" ] + ~selection: + Selection. + { + variant; + packages = + [ + "bondi.dev"; + "arch-x86_64.1"; "base-bigarray.base"; "base-threads.base"; "base-unix.base"; "conf-mingw-w64-gcc-x86_64.1"; "dune.3.17.0"; "flexdll.0.43"; "host-arch-x86_64.1"; "host-system-mingw.1"; "menhir.20240715"; "menhirCST.20240715"; "menhirLib.20240715"; "menhirSdk.20240715"; "mingw-w64-shims.0.2.0"; "ocaml.4.14.2"; "ocaml-base-compiler.4.14.2"; "ocaml-config.3"; "ocaml-env-mingw64.1"; "ocaml-options-vanilla.1"; "system-mingw.1"; + ]; + only_packages = []; + commit = "f207d3f018d642d1fcddb2c118e7fa8e65f4e366"; + lower_bound = false; + } + |> Obuilder_spec.sexp_of_t + in + Alcotest.(check sexp) "validate" expected actual + let tests = [ Alcotest.test_case "macos" `Quick test_macos_spec; Alcotest.test_case "linux" `Quick test_linux_spec; + Alcotest.test_case "windows" `Quick test_windows_spec; ] From fbe073f609c5c3d5090e306ad4964627f3d593d1 Mon Sep 17 00:00:00 2001 From: Mark Elvers Date: Wed, 4 Dec 2024 22:08:54 +0000 Subject: [PATCH 5/5] Format test code --- test/service/test_spec.ml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/test/service/test_spec.ml b/test/service/test_spec.ml index c2b0f8a4..0baac5dd 100644 --- a/test/service/test_spec.ml +++ b/test/service/test_spec.ml @@ -192,9 +192,7 @@ let test_windows_spec () = |> Result.get_ok in let actual = - Opam_build.spec - ~base: - "windows-server-2022-amd64-ocaml-4.14" + Opam_build.spec ~base:"windows-server-2022-amd64-ocaml-4.14" ~opam_version:`V2_3 ~opam_files:[ "bondi.opam" ] ~selection: Selection. @@ -203,7 +201,26 @@ let test_windows_spec () = packages = [ "bondi.dev"; - "arch-x86_64.1"; "base-bigarray.base"; "base-threads.base"; "base-unix.base"; "conf-mingw-w64-gcc-x86_64.1"; "dune.3.17.0"; "flexdll.0.43"; "host-arch-x86_64.1"; "host-system-mingw.1"; "menhir.20240715"; "menhirCST.20240715"; "menhirLib.20240715"; "menhirSdk.20240715"; "mingw-w64-shims.0.2.0"; "ocaml.4.14.2"; "ocaml-base-compiler.4.14.2"; "ocaml-config.3"; "ocaml-env-mingw64.1"; "ocaml-options-vanilla.1"; "system-mingw.1"; + "arch-x86_64.1"; + "base-bigarray.base"; + "base-threads.base"; + "base-unix.base"; + "conf-mingw-w64-gcc-x86_64.1"; + "dune.3.17.0"; + "flexdll.0.43"; + "host-arch-x86_64.1"; + "host-system-mingw.1"; + "menhir.20240715"; + "menhirCST.20240715"; + "menhirLib.20240715"; + "menhirSdk.20240715"; + "mingw-w64-shims.0.2.0"; + "ocaml.4.14.2"; + "ocaml-base-compiler.4.14.2"; + "ocaml-config.3"; + "ocaml-env-mingw64.1"; + "ocaml-options-vanilla.1"; + "system-mingw.1"; ]; only_packages = []; commit = "f207d3f018d642d1fcddb2c118e7fa8e65f4e366";