From 3b9f65636b800786958fb474ebd8586a3fa7e879 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Wed, 1 Jan 2025 19:26:21 +0900 Subject: [PATCH] Use dune-build-info to manage version information Signed-off-by: Sora Morimoto --- VERSION | 1 - compiler/bin-js_of_ocaml/dune | 3 +-- compiler/bin-js_of_ocaml/info.ml | 7 +----- compiler/bin-jsoo_minify/cmd_arg.ml | 7 +----- compiler/bin-jsoo_minify/dune | 2 +- compiler/bin-wasm_of_ocaml/dune | 2 +- compiler/bin-wasm_of_ocaml/info.ml | 7 +----- compiler/lib/build_info.ml | 6 +---- compiler/lib/compiler_version.mli | 23 ------------------ compiler/lib/dune | 10 ++------ dune | 10 -------- dune-project | 1 + js_of_ocaml-compiler.opam | 1 + lib/js_of_ocaml/dune | 9 +------ lib/js_of_ocaml/sys_js.ml | 5 +--- lib/runtime/dune | 12 +++------- lib/runtime/jsoo_runtime.ml | 4 +--- lib/version/dune | 4 ++++ lib/version/jsoo_version.ml | 4 ++++ tools/version/dune | 24 ------------------- tools/version/gen/dune | 3 --- tools/version/gen/gen.ml | 37 ----------------------------- 22 files changed, 25 insertions(+), 157 deletions(-) delete mode 100644 VERSION delete mode 100644 compiler/lib/compiler_version.mli create mode 100644 lib/version/dune create mode 100644 lib/version/jsoo_version.ml delete mode 100644 tools/version/dune delete mode 100644 tools/version/gen/dune delete mode 100644 tools/version/gen/gen.ml diff --git a/VERSION b/VERSION deleted file mode 100644 index 450ad1e283..0000000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -5.9.1 diff --git a/compiler/bin-js_of_ocaml/dune b/compiler/bin-js_of_ocaml/dune index f246e9d57d..eb988716f1 100644 --- a/compiler/bin-js_of_ocaml/dune +++ b/compiler/bin-js_of_ocaml/dune @@ -4,10 +4,9 @@ (package js_of_ocaml-compiler) (libraries jsoo_cmdline - js_of_ocaml-compiler cmdliner - compiler-libs.common js_of_ocaml-compiler.runtime-files + js_of_ocaml-compiler.version (select findlib_support.ml from diff --git a/compiler/bin-js_of_ocaml/info.ml b/compiler/bin-js_of_ocaml/info.ml index 099739beaa..be038a98c4 100644 --- a/compiler/bin-js_of_ocaml/info.ml +++ b/compiler/bin-js_of_ocaml/info.ml @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Js_of_ocaml_compiler open Cmdliner let make ~name ~doc ~description = @@ -41,9 +40,5 @@ let make ~name ~doc ~description = or (at your option) any later version." ] in - let version = - match Compiler_version.git_version with - | "" -> Compiler_version.s - | v -> Printf.sprintf "%s+%s" Compiler_version.s v - in + let version = Jsoo_version.get () in Cmd.info name ~version ~doc ~man diff --git a/compiler/bin-jsoo_minify/cmd_arg.ml b/compiler/bin-jsoo_minify/cmd_arg.ml index eaad97e11e..76fc6d2ea4 100644 --- a/compiler/bin-jsoo_minify/cmd_arg.ml +++ b/compiler/bin-jsoo_minify/cmd_arg.ml @@ -18,7 +18,6 @@ *) open! Js_of_ocaml_compiler.Stdlib -open Js_of_ocaml_compiler open Cmdliner type t = @@ -69,9 +68,5 @@ let info = or (at your option) any later version." ] in - let version = - match Compiler_version.git_version with - | "" -> Compiler_version.s - | v -> Printf.sprintf "%s+%s" Compiler_version.s v - in + let version = Jsoo_version.get () in Cmd.info "jsoo_minify" ~version ~doc ~man diff --git a/compiler/bin-jsoo_minify/dune b/compiler/bin-jsoo_minify/dune index a774e30b21..f70ca467b2 100644 --- a/compiler/bin-jsoo_minify/dune +++ b/compiler/bin-jsoo_minify/dune @@ -2,7 +2,7 @@ (name jsoo_minify) (public_name jsoo_minify) (package js_of_ocaml-compiler) - (libraries jsoo_cmdline js_of_ocaml-compiler cmdliner compiler-libs.common) + (libraries jsoo_cmdline cmdliner js_of_ocaml-compiler.version) (flags (:standard -safe-string))) diff --git a/compiler/bin-wasm_of_ocaml/dune b/compiler/bin-wasm_of_ocaml/dune index cd5f1a468a..a86f206c98 100644 --- a/compiler/bin-wasm_of_ocaml/dune +++ b/compiler/bin-wasm_of_ocaml/dune @@ -6,8 +6,8 @@ jsoo_cmdline wasm_of_ocaml-compiler cmdliner - compiler-libs.common js_of_ocaml-compiler.runtime-files + js_of_ocaml-compiler.version yojson (select findlib_support.ml diff --git a/compiler/bin-wasm_of_ocaml/info.ml b/compiler/bin-wasm_of_ocaml/info.ml index c297de5b6c..48c0c61426 100644 --- a/compiler/bin-wasm_of_ocaml/info.ml +++ b/compiler/bin-wasm_of_ocaml/info.ml @@ -16,7 +16,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Js_of_ocaml_compiler open Cmdliner let make ~name ~doc ~description = @@ -40,9 +39,5 @@ let make ~name ~doc ~description = or (at your option) any later version." ] in - let version = - match Compiler_version.git_version with - | "" -> Compiler_version.s - | v -> Printf.sprintf "%s+git-%s" Compiler_version.s v - in + let version = Jsoo_version.get () in Cmd.info name ~version ~doc ~man diff --git a/compiler/lib/build_info.ml b/compiler/lib/build_info.ml index 4de9956edf..e39dc26745 100644 --- a/compiler/lib/build_info.ml +++ b/compiler/lib/build_info.ml @@ -62,11 +62,7 @@ let kind t = | s -> kind_of_string s let create kind = - let version = - match Compiler_version.git_version with - | "" -> Compiler_version.s - | v -> Printf.sprintf "%s+%s" Compiler_version.s v - in + let version = Jsoo_version.get () in [ "use-js-string", string_of_bool (Config.Flag.use_js_string ()) ; "effects", string_of_effects_backend (Config.effects ()) ; "version", version diff --git a/compiler/lib/compiler_version.mli b/compiler/lib/compiler_version.mli deleted file mode 100644 index 58b490c567..0000000000 --- a/compiler/lib/compiler_version.mli +++ /dev/null @@ -1,23 +0,0 @@ -(* Js_of_ocaml compiler - * http://www.ocsigen.org/js_of_ocaml/ - * Copyright (C) 2014 Jérôme Vouillon - * Laboratoire PPS - CNRS Université Paris Diderot - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, with linking exception; - * either version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *) - -val s : string - -val git_version : string diff --git a/compiler/lib/dune b/compiler/lib/dune index 768d293c15..bc954d0e8f 100644 --- a/compiler/lib/dune +++ b/compiler/lib/dune @@ -3,8 +3,9 @@ (public_name js_of_ocaml-compiler) (synopsis "Js_of_ocaml compiler library") (libraries - compiler-libs.common compiler-libs.bytecomp + compiler-libs.common + js_of_ocaml-compiler.version menhirLib sedlex yojson) @@ -34,10 +35,3 @@ (menhir (modules annot_parser)) - -(rule - (targets compiler_version.ml) - (deps - (:input-file ../../version.ml.in)) - (action - (copy %{input-file} %{targets}))) diff --git a/dune b/dune index d5e65a5456..350a87f057 100644 --- a/dune +++ b/dune @@ -36,16 +36,6 @@ (tools/node_wrapper.exe as node) (tools/node_wrapper.exe as node.exe)))) -(rule - (targets version.ml.in) - (action - (with-stdout-to - %{targets} - (run - %{dep:tools/version/gen/gen.exe} - %{dep:VERSION} - %{dep:tools/version/GIT-VERSION})))) - (data_only_dirs _wikidoc doc-dev janestreet) (vendored_dirs) diff --git a/dune-project b/dune-project index 1cb47d81d2..d6290ad724 100644 --- a/dune-project +++ b/dune-project @@ -19,6 +19,7 @@ "Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js") (depends (ocaml (and (>= 4.08) (< 5.4))) + dune-build-info (num :with-test) (ppx_expect (and (>= v0.16.1) :with-test)) (ppxlib (>= 0.15.0)) diff --git a/js_of_ocaml-compiler.opam b/js_of_ocaml-compiler.opam index 53956ccb1e..2f8970b1e7 100644 --- a/js_of_ocaml-compiler.opam +++ b/js_of_ocaml-compiler.opam @@ -14,6 +14,7 @@ bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues" depends: [ "dune" {>= "3.17"} "ocaml" {>= "4.08" & < "5.4"} + "dune-build-info" "num" {with-test} "ppx_expect" {>= "v0.16.1" & with-test} "ppxlib" {>= "0.15.0"} diff --git a/lib/js_of_ocaml/dune b/lib/js_of_ocaml/dune index df22bcb59a..bc1543c2d7 100644 --- a/lib/js_of_ocaml/dune +++ b/lib/js_of_ocaml/dune @@ -1,7 +1,7 @@ (library (name js_of_ocaml) (public_name js_of_ocaml) - (libraries js_of_ocaml-compiler.runtime) + (libraries js_of_ocaml-compiler.runtime js_of_ocaml-compiler.version) (foreign_stubs (language c) (names js_of_ocaml_stubs)) @@ -20,10 +20,3 @@ (with-stdout-to %{targets} (run ../gen_stubs/gen_stubs.exe %{jsoo} --except %{runtime})))) - -(rule - (targets lib_version.ml) - (deps - (:input-file ../../version.ml.in)) - (action - (copy %{input-file} %{targets}))) diff --git a/lib/js_of_ocaml/sys_js.ml b/lib/js_of_ocaml/sys_js.ml index 79455100fe..862c35dfd0 100644 --- a/lib/js_of_ocaml/sys_js.ml +++ b/lib/js_of_ocaml/sys_js.ml @@ -57,7 +57,4 @@ let mount ~path f = let unmount ~path = unmount path -let js_of_ocaml_version = - if String.equal Lib_version.git_version "" - then Lib_version.s - else Lib_version.s ^ "+" ^ Lib_version.git_version +let js_of_ocaml_version = Jsoo_version.get () diff --git a/lib/runtime/dune b/lib/runtime/dune index 207bb9c0d7..91b2f94087 100644 --- a/lib/runtime/dune +++ b/lib/runtime/dune @@ -1,9 +1,10 @@ (library (name jsoo_runtime) + (public_name js_of_ocaml-compiler.runtime) + (libraries js_of_ocaml-compiler.version) (foreign_stubs (language c) - (names js_of_ocaml_runtime_stubs)) - (public_name js_of_ocaml-compiler.runtime)) + (names js_of_ocaml_runtime_stubs))) (rule (targets js_of_ocaml_runtime_stubs.c) @@ -14,10 +15,3 @@ (with-stdout-to %{targets} (run ../gen_stubs/gen_stubs.exe %{deps})))) - -(rule - (targets runtime_version.ml) - (deps - (:input-file ../../version.ml.in)) - (action - (copy %{input-file} %{targets}))) diff --git a/lib/runtime/jsoo_runtime.ml b/lib/runtime/jsoo_runtime.ml index af0457de38..9f257eecc1 100644 --- a/lib/runtime/jsoo_runtime.ml +++ b/lib/runtime/jsoo_runtime.ml @@ -143,9 +143,7 @@ module Sys = struct | _ -> assert false end - let version = Runtime_version.s - - let git_version = Runtime_version.git_version + let version = Jsoo_version.get () end module Error : sig diff --git a/lib/version/dune b/lib/version/dune new file mode 100644 index 0000000000..9718434c72 --- /dev/null +++ b/lib/version/dune @@ -0,0 +1,4 @@ +(library + (name jsoo_version) + (public_name js_of_ocaml-compiler.version) + (libraries dune-build-info)) diff --git a/lib/version/jsoo_version.ml b/lib/version/jsoo_version.ml new file mode 100644 index 0000000000..623467378e --- /dev/null +++ b/lib/version/jsoo_version.ml @@ -0,0 +1,4 @@ +let get () = + match Build_info.V1.version () with + | None -> "dev" + | Some v -> Build_info.V1.Version.to_string v diff --git a/tools/version/dune b/tools/version/dune deleted file mode 100644 index af3a2b3008..0000000000 --- a/tools/version/dune +++ /dev/null @@ -1,24 +0,0 @@ -(* -*- tuareg -*- *) -open StdLabels -open Jbuild_plugin.V1 - -let git_version = - let placeholder = "%%VERSION%%" in - match run_and_read_lines "git describe --always --dirty" with - | exception _ -> "" - | version :: _ -> - if "%%" ^ "VERSION" ^ "%%" = placeholder - then version - else placeholder - | [] -> "" - -let dyn = - Printf.sprintf - {| -(rule - (target GIT-VERSION) - (action (with-stdout-to %%{target} (echo "%s")))) -|} - git_version - -let () = send dyn diff --git a/tools/version/gen/dune b/tools/version/gen/dune deleted file mode 100644 index 8fadbfebab..0000000000 --- a/tools/version/gen/dune +++ /dev/null @@ -1,3 +0,0 @@ -(executable - (name gen) - (libraries unix)) diff --git a/tools/version/gen/gen.ml b/tools/version/gen/gen.ml deleted file mode 100644 index 1af6c52203..0000000000 --- a/tools/version/gen/gen.ml +++ /dev/null @@ -1,37 +0,0 @@ -let version = Sys.argv.(1) - -let git_version = Sys.argv.(2) - -let version = - let ic = open_in version in - let version = try input_line ic with End_of_file -> "" in - close_in ic; - version - -let git_version = - let ic = open_in git_version in - let git_version = try input_line ic with End_of_file -> "" in - close_in ic; - git_version - -let drop_prefix ~prefix s = - let plen = String.length prefix in - if plen > String.length s - then None - else - try - for i = 0 to String.length prefix - 1 do - if not (Char.equal s.[i] prefix.[i]) then raise Exit - done; - Some (String.sub s plen (String.length s - plen)) - with Exit -> None - -let git_version = - match drop_prefix ~prefix:(version ^ "-") git_version with - | Some v -> v - | None -> git_version - -let () = Printf.printf {| -let s = "%s" -let git_version = "%s" -|} version git_version