catala/compiler/catala_utils/get_version.ml
Louis Gesbert 7b25a42970 Better version handling
Always generate the version through git when possible, and encode that within
the binaries so that `catala --version` does'nt give misleading information.

Previously we used dune's builtin functionality, but that resorts to a hack at
install time which is unpleasant and doesn't work with our use of `opam
install`.

The cost is a re-linking of catala_utils and the binaries upon git commit, which
is hardly noticeable.
2024-01-24 11:41:34 +01:00

18 lines
642 B
OCaml

(** This trivial binary is run at build-time to get the correct version from the
build environment (either the CATALA_VERSION) environment variable if
defined, or `git describe`, or resorting to just "dev" if none of these can
be found *)
let v =
match Sys.getenv_opt "CATALA_VERSION" with
| None | Some "" -> (
let ic = Unix.open_process_in "git describe --tags --dirty 2>/dev/null" in
let v = try input_line ic with _ -> "dev" in
match Unix.close_process_in ic with Unix.WEXITED 0 -> v | _ -> "dev")
| Some v -> v
let () =
print_string "let v = \"";
print_string (String.escaped v);
print_endline "\""