From eb63fe0bd6735af7c38291b3d2757b9f09890803 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 22:08:48 +0200 Subject: [PATCH 01/11] Tests: fix tests using local install --- testsuite/ocamlbuild_test.ml | 38 +++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/testsuite/ocamlbuild_test.ml b/testsuite/ocamlbuild_test.ml index f135b507..7cf67609 100644 --- a/testsuite/ocamlbuild_test.ml +++ b/testsuite/ocamlbuild_test.ml @@ -435,19 +435,51 @@ let print_colored header_color header name body_color body = (color_code header_color) header name (color_code body_color) body + let run ~root = let dir = Sys.getcwd () in let root = dir ^ "/" ^ root in rm root; Unix.mkdir root 0o750; + let install_lib_dir = Filename.concat root "install-lib" in + let install_bin_dir = Filename.concat root "install-bin" in let test_tree = Filename.dirname (Sys.argv.(0)) in let test_tree = if test_tree = "." then Sys.getcwd () else test_tree in let build_tree = Filename.dirname test_tree in - let ocamlbuild = Filename.concat build_tree "ocamlbuild.byte" in + + let copy l dest = + ignore(Sys.command (Printf.sprintf "mkdir -p %s" dest)); + List.iter (fun f -> ignore(Sys.command (Printf.sprintf "cp %s/%s %s" build_tree f dest))) l + in + let ocamlbuild = Printf.sprintf "%s/ocamlbuild.byte" install_bin_dir in + copy + [ "plugin-lib/ocamlbuildlib.cma"; + "plugin-lib/ocamlbuildlib.cmxa"; + "plugin-lib/ocamlbuildlib.a"; + "bin/ocamlbuild.cmo"; + "bin/ocamlbuild.cmx"; + "bin/ocamlbuild.o"; + "src/ocamlbuild_pack.cmi"; + "src/ocamlbuild_pack.cmx"; + "src/ocamlbuild_pack.o"; + "plugin-lib/ocamlbuild_plugin.cmi"; + "plugin-lib/ocamlbuild_plugin.cmx"; + "plugin-lib/ocamlbuild_plugin.o"; + "plugin-lib/ocamlbuild_executor.cmi"; + "plugin-lib/ocamlbuild_executor.cmx"; + "plugin-lib/ocamlbuild_executor.o"; + "plugin-lib/ocamlbuild_unix_plugin.cmi"; + "plugin-lib/ocamlbuild_unix_plugin.cmx"; + "plugin-lib/ocamlbuild_unix_plugin.o"] + install_lib_dir; + copy + [ "ocamlbuild.byte"; + "ocamlbuild.native" ] + install_bin_dir; let testsuite_opts = [ - (`install_bin_dir build_tree); - (`install_lib_dir (Filename.concat build_tree "src")); + (`install_bin_dir install_bin_dir); + (`install_lib_dir install_lib_dir); ] in let verbose = From d9e66a966449d78e42b5e995d5afcddd2200aa33 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 21:54:47 +0200 Subject: [PATCH 02/11] Fix make clean --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0ca7bd68..b7dd3ac2 100644 --- a/Makefile +++ b/Makefile @@ -435,7 +435,8 @@ plugin-lib/%.cmx: plugin-lib/%.ml clean:: rm -rf tmp/ - rm -f src/*.cm* *.cm* + rm -f src/*.cm* *.cm* bin/*.cm* plugin-lib/*.cm* + rm -f src/*.o *.o bin/*.o plugin-lib/*.o plugin-lib/*.a ifdef EXT_OBJ rm -f src/*$(EXT_OBJ) *$(EXT_OBJ) endif From cb2c9617eff965479c4c8420b10111458f90391a Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 21:56:33 +0200 Subject: [PATCH 03/11] Tests: fix requirements --- testsuite/external.ml | 2 +- testsuite/external_test_header.ml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/testsuite/external.ml b/testsuite/external.ml index 275341f5..4757ff19 100644 --- a/testsuite/external.ml +++ b/testsuite/external.ml @@ -31,7 +31,7 @@ let () = test "SubtoolOptions" to the subtool invocation (PR#5763)" (* testing for the 'menhir' executable directly is too hard to do in a portable way; test the ocamlfind package instead *) - ~requirements:(package_exists "menhirLib") + ~requirements:(req_and (package_exists "menhirLib") (package_exists "camlp4")) ~options:[`use_ocamlfind; `use_menhir; `tags ["package(camlp4.fulllib)"]] ~tree:[T.f "parser.mly" ~content:"%{ %} diff --git a/testsuite/external_test_header.ml b/testsuite/external_test_header.ml index 2b890e35..a9b030dd 100644 --- a/testsuite/external_test_header.ml +++ b/testsuite/external_test_header.ml @@ -5,3 +5,10 @@ let package_exists package = try ignore (package_directory package); Fullfilled with No_such_package _ -> Missing (Printf.sprintf "the ocamlfind package %s" package) + +let req_and a b = + match a, b with + | Fullfilled, Fullfilled -> Fullfilled + | Missing _ as x, Fullfilled + | Fullfilled, (Missing _ as x) -> x + | Missing a, Missing b -> Missing (Printf.sprintf "%s, %s" a b) From 71196d29c81580c8d091b6495d28076b4726b84f Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 21:57:05 +0200 Subject: [PATCH 04/11] Test: fix findlib detection --- testsuite/findlibonly_test_header.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/findlibonly_test_header.ml b/testsuite/findlibonly_test_header.ml index 5b147820..50863015 100644 --- a/testsuite/findlibonly_test_header.ml +++ b/testsuite/findlibonly_test_header.ml @@ -1,4 +1,4 @@ -match Sys.command "ocamlfind ocamlc" with +match Sys.command "ocamlfind ocamlc -version" with | 0 -> () | _ -> prerr_endline "Having ocamlfind installed is a prerequisite \ From e598a439be0c39275134592bd23b5fa2ad985c42 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 21:57:39 +0200 Subject: [PATCH 05/11] Tests: adapt a test for OCaml 5.2 --- testsuite/internal.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/testsuite/internal.ml b/testsuite/internal.ml index 1e92477c..f77ff125 100644 --- a/testsuite/internal.ml +++ b/testsuite/internal.ml @@ -216,7 +216,7 @@ Error: This expression has type int but an expression was expected of type unit because it is in the left-hand side of a sequence Command exited with code 2." -else +else if Sys.ocaml_version < "5.2.0" then "File \"hello.ml\", line 1, characters 9-10: 1 | let () = 1; () ^ @@ -224,6 +224,14 @@ Error: This expression has type int but an expression was expected of type unit because it is in the left-hand side of a sequence Command exited with code 2." +else +"File \"hello.ml\", line 1, characters 9-10: +1 | let () = 1; () + ^ +Error: This expression has type \"int\" but an expression was expected of type + \"unit\" + because it is in the left-hand side of a sequence +Command exited with code 2." ) ~targets:("hello.byte",[]) ();; From 5febb9d2435229e20eb8e3a635b1fbce6cf22e80 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 16:32:47 +0200 Subject: [PATCH 06/11] CI: setup gh-actions --- .github/workflows/build.yml | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..3f8bcf28 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,81 @@ +name: build + +on: + pull_request: + push: + branches: + - master + schedule: + # Prime the caches every Monday + - cron: 0 1 * * MON + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + ocaml-compiler: + - "4.08" + - "4.09" + - "4.10" + - "4.11" + - "4.12" + - "4.13" + - "4.14" + - "5.0" + - "5.1" + - "5.2" + + runs-on: ${{ matrix.os }} + + steps: + - name: Set git to use LF + if: matrix.ocaml-compiler < 5.2 + run: | + git config --global core.autocrlf false + git config --global core.eol lf + git config --global core.ignorecase false + + - name: Checkout tree + uses: actions/checkout@v4 + + - name: Set-up OCaml ${{ matrix.ocaml-compiler }} + if: runner.os == 'Windows' + uses: ocaml/setup-ocaml@v2 + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + opam-repositories: | + dra27: https://github.com/dra27/opam-repository.git#windows-5.0 + default: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset + opam: https://github.com/ocaml/opam-repository.git + dune-cache: true + opam-depext: ${{ !matrix.skip-test }} + opam-depext-flags: --with-test + + - name: Set-up OCaml ${{ matrix.ocaml-compiler }} + if: runner.os != 'Windows' + uses: ocaml/setup-ocaml@v2 + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + allow-prerelease-opam: true + dune-cache: true + opam-depext: ${{ !matrix.skip-test }} + opam-depext-flags: --with-test + + - run: opam install . --with-test --deps-only + + - run: VERBOSE=1 opam exec -- make test + + - run: OCAMLBUILD=$(pwd)/ocamlbuild.native opam exec -- make -C bootstrap + + - run: opam exec -- make distclean + - run: opam exec -- opam pin add -n -k path ocamlbuild . + - run: opam exec -- opam install -v ocamlbuild + - run: opam exec -- opam install -v mtime.1.0.0 # this tests topkg, with stub libraries + - run: opam exec -- opam install -v inotify.2.3 # this tests oasis, with stub libraries + if: matrix.ocaml-compiler < 5 + - run: opam exec -- opam install -v cpuid.0.1.1 # this tests the ocb-stubblr plugin + - run: opam exec -- opam install -v shcaml.0.2.1 # this tests the cppo plugin + if: matrix.ocaml-compiler < 5 From 3b140ba385371d252fe298f801c22d55588eee13 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 21:55:56 +0200 Subject: [PATCH 07/11] Adapt to new ocaml layout --- Makefile | 4 ++-- bootstrap/_tags | 1 + src/ocaml_specific.ml | 6 +++--- src/plugin.ml | 4 ++-- testsuite/internal_test_header.ml | 1 + 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b7dd3ac2..d4236e93 100644 --- a/Makefile +++ b/Makefile @@ -127,13 +127,13 @@ distclean:: clean # The executables ocamlbuild.byte: src/ocamlbuild_pack.cmo $(EXTRA_CMO) bin/ocamlbuild.cmo - $(OCAMLC) $(LINKFLAGS) -o $@ unix.cma $^ + $(OCAMLC) $(LINKFLAGS) -o $@ -I +unix unix.cma $^ ocamlbuildlight.byte: src/ocamlbuild_pack.cmo bin/ocamlbuildlight.cmo $(OCAMLC) $(LINKFLAGS) -o $@ $^ ocamlbuild.native: src/ocamlbuild_pack.cmx $(EXTRA_CMX) bin/ocamlbuild.cmx - $(OCAMLOPT) $(LINKFLAGS) -o $@ unix.cmxa $^ + $(OCAMLOPT) $(LINKFLAGS) -o $@ -I +unix unix.cmxa $^ # The libraries diff --git a/bootstrap/_tags b/bootstrap/_tags index 5b2d8fbb..f7683544 100644 --- a/bootstrap/_tags +++ b/bootstrap/_tags @@ -20,6 +20,7 @@ true: debug "src/discard_printf.ml": rectypes "ocamlbuildlib.cma" or "ocamlbuildlightlib.cma": linkall <**/*.byte> or <**/*.native> or <**/*.top>: use_unix +: use_unix "ocamlbuildlight.byte": -use_unix, nopervasives : for-pack(Ocamlbuild_pack) diff --git a/src/ocaml_specific.ml b/src/ocaml_specific.ml index 2b82c6a6..fdf48a8a 100644 --- a/src/ocaml_specific.ml +++ b/src/ocaml_specific.ml @@ -819,9 +819,9 @@ camlp4_flags' ["camlp4orr", S[A"camlp4of"; A"-parser"; A"reloaded"]; flag ["ocaml"; "pp"; "camlp4:no_quot"] (A"-no_quot");; -ocaml_lib ~extern:true "dynlink";; -ocaml_lib ~extern:true "unix";; -ocaml_lib ~extern:true "str";; +ocaml_lib ~extern:true ~dir:"+dynlink" "dynlink";; +ocaml_lib ~extern:true ~dir:"+unix" "unix";; +ocaml_lib ~extern:true ~dir:"+str" "str";; ocaml_lib ~extern:true "bigarray";; ocaml_lib ~extern:true "nums";; ocaml_lib ~extern:true "dbm";; diff --git a/src/plugin.ml b/src/plugin.ml index 451f7ece..5024f1f3 100644 --- a/src/plugin.ml +++ b/src/plugin.ml @@ -175,7 +175,7 @@ module Make(U:sig end) = let unix_lib = if use_ocamlfind_pkgs then `Package "unix" else if use_light_mode then `Nothing - else `Lib "unix" in + else `Lib ("+unix", "unix") in let ocamlbuild_lib = if use_ocamlfind_pkgs then `Package "ocamlbuild" @@ -198,7 +198,7 @@ module Make(U:sig end) = let spec = function | `Nothing -> N | `Package pkg -> S[A "-package"; A pkg] - | `Lib lib -> P (lib -.- cma) + | `Lib (inc, lib) -> S[A "-I"; A inc; P (lib -.- cma)] | `Local_lib llib -> S [A "-I"; A dir; P (in_dir (llib -.- cma))] | `Local_mod lmod -> P (in_dir (lmod -.- cmo)) in diff --git a/testsuite/internal_test_header.ml b/testsuite/internal_test_header.ml index ed19b8d3..32c85075 100644 --- a/testsuite/internal_test_header.ml +++ b/testsuite/internal_test_header.ml @@ -1,3 +1,4 @@ +#directory "+unix";; #load "unix.cma";; #mod_use "../src/ocamlbuild_config.ml";; From c31f7e149cfb089f835fcb68c8e9b5b935bbad51 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 22:24:09 +0200 Subject: [PATCH 08/11] Opam: add test dependencies --- ocamlbuild.opam | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ocamlbuild.opam b/ocamlbuild.opam index 38a3756c..f7cac7b7 100644 --- a/ocamlbuild.opam +++ b/ocamlbuild.opam @@ -32,4 +32,6 @@ conflicts: [ depends: [ "ocaml" {>= "4.03"} + "ocamlfind" {with-test} + "menhirLib" {with-test} ] From ae5a390f0797657129d94504295bf5add0df76b8 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 23:23:51 +0200 Subject: [PATCH 09/11] Makefile: small cleanup --- bootstrap/Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/bootstrap/Makefile b/bootstrap/Makefile index b94785e0..499e1066 100644 --- a/bootstrap/Makefile +++ b/bootstrap/Makefile @@ -8,7 +8,6 @@ setup: ln -sf ../src ln -sf ../bin ln -sf ../plugin-lib - mkdir -p dest stage1: setup @echo "BOOTSTRAP (1): building local ocamlbuild from '$(OCAMLBUILD)'" @@ -24,5 +23,4 @@ clean: @$(OCAMLBUILD) -build-dir _build_stage2 -clean @rm -f src bin plugin-lib @rm -f dest/ocamlbuild_{stage1,stage2}.native - @rmdir dest From 598138ad149eadb6c7674f785407023f4f287a48 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 23:24:25 +0200 Subject: [PATCH 10/11] Bootstrap: no plugin for bootstrap --- bootstrap/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap/Makefile b/bootstrap/Makefile index 499e1066..42bc84dc 100644 --- a/bootstrap/Makefile +++ b/bootstrap/Makefile @@ -11,11 +11,11 @@ setup: stage1: setup @echo "BOOTSTRAP (1): building local ocamlbuild from '$(OCAMLBUILD)'" - @$(OCAMLBUILD) -build-dir _build_stage1 bootstrap.otarget + @$(OCAMLBUILD) -build-dir _build_stage1 bootstrap.otarget -no-plugin stage2: stage1 @echo "BOOTSTRAP (2): building local ocamlbuild from local ocamlbuild" - @_build_stage1/bin/ocamlbuild.native -build-dir _build_stage2 bootstrap.otarget + @_build_stage1/bin/ocamlbuild.native -build-dir _build_stage2 bootstrap.otarget -no-plugin clean: @$(OCAMLBUILD) -clean From 92b6ab85eb8b3140a11e75d457c74cbf379f4ac8 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 16 May 2024 23:51:51 +0200 Subject: [PATCH 11/11] Misc: missing entries in gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 60ec2724..6a7cc597 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,8 @@ ocamlbuild.install Makefile.config /bootstrap/src +/bootstrap/bin +/bootstrap/plugin-lib /bootstrap/_build* /src/ocamlbuild_config.ml