Skip to content

Commit

Permalink
Use dune-build-info
Browse files Browse the repository at this point in the history
This uses dune-build-info to compute the version number.

It will be resolved in the following way:

- if (version) is set in (dune-project), it is used. This is what happens
  when using opam pins (through dune subst), or for released versions
  (through dune-release).
- otherwise, a description from [git describe] will be used. Caveat for
  this case: binaries under [_build/] will not have this information, but
  [dune install --prefix _install] will copy a valid binary under
  [_install/bin].

We require at least dune 2.7, since `dune-build-info` is broken on
flambda switches before this version.

See ocaml/dune#3599
  • Loading branch information
emillon committed Sep 9, 2020
1 parent 6b7501a commit 5760f1f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 61 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 2.2)
(lang dune 2.7)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; OCamlFormat ;
Expand Down
14 changes: 14 additions & 0 deletions lib/Version.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(**************************************************************************)
(* *)
(* OCamlFormat *)
(* *)
(* Copyright (c) Facebook, Inc. and its affiliates. *)
(* *)
(* This source code is licensed under the MIT license found in *)
(* the LICENSE file in the root directory of this source tree. *)
(* *)
(**************************************************************************)

let version =
let open Build_info.V1 in
version () |> Option.value_map ~f:Version.to_string ~default:"unknown"
22 changes: 22 additions & 0 deletions lib/Version.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(**************************************************************************)
(* *)
(* OCamlFormat *)
(* *)
(* Copyright (c) Facebook, Inc. and its affiliates. *)
(* *)
(* This source code is licensed under the MIT license found in *)
(* the LICENSE file in the root directory of this source tree. *)
(* *)
(**************************************************************************)

val version : string
(** A version number, or "unknown". This is provided by [dune-build-info],
which means that it will be resolved in the following way:
- if (version) is set in (dune-project), it is used. This is what happens
when using opam pins (through dune subst), or for released versions
(through dune-release).
- otherwise, a description from [git describe] will be used. Caveat for
this case: binaries under [_build/] will not have this information, but
[dune install --prefix _install] will copy a valid binary under
[_install/bin]. *)
9 changes: 1 addition & 8 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(rule
(targets Version.ml)
(deps (universe))
(action
(run ocaml %{dep:../tools/gen_version.mlt} Version.ml))
(mode fallback))

(ocamllex Literal_lexer)

(library
Expand All @@ -24,4 +17,4 @@
(:standard -open Base -open Import -open Compat))
;;INSERT_BISECT_HERE;;
(libraries format_ import ocaml-migrate-parsetree odoc.model odoc.parser
parse_wyc re uuseg uuseg.string token_latest compat))
parse_wyc re uuseg uuseg.string token_latest compat dune-build-info))
5 changes: 3 additions & 2 deletions ocamlformat.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bug-reports: "https://github.com/ocaml-ppx/ocamlformat/issues"
dev-repo: "git+https://github.com/ocaml-ppx/ocamlformat.git"
license: "MIT"
build: [
["ocaml" "tools/gen_version.mlt" "lib/Version.ml" version] {pinned}
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
Expand All @@ -27,8 +27,9 @@ depends: [
"base" {>= "v0.12.0" & < "v0.15"}
"base-unix"
"cmdliner"
"dune" {>= "2.2.0"}
"dune" {>= "2.7.0"}
"fix"
"dune-build-info"
"fpath"
"menhir"
"ocaml-migrate-parsetree" {>= "1.7.3" & < "2.0.0"}
Expand Down
50 changes: 0 additions & 50 deletions tools/gen_version.mlt

This file was deleted.

0 comments on commit 5760f1f

Please sign in to comment.