-
Notifications
You must be signed in to change notification settings - Fork 7
/
myocamlbuild.ml
71 lines (62 loc) · 1.96 KB
/
myocamlbuild.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
open Nonstd
open Solvuu_build.Std
let project_name = "epidisco"
let version = "0.0.0-dev"
let findlib_deps = [
"biokepi";
"ppx_deriving.std";
"ppx_deriving_cmdliner";
]
let meta_dot_ml = "src/lib/metadata.ml"
let generate_meta_data () =
let cmd_option cmd =
try
Some (
Ocamlbuild_pack.My_unix.run_and_read cmd
|> fun x -> String.sub x 0 (String.length x - 1)
)
with _ -> None in
let git_last_commit () = cmd_option "git rev-parse HEAD" in
let git_describe () = cmd_option "git describe --tags --long --dirty" in
let option_to_string =
Option.value_map ~default:"None" ~f:(sprintf "Some %S") in
Solvuu_build.Util.Rule.rule
~name:"meta-data-generation"
~prods:[meta_dot_ml]
~deps:[]
~insert:`bottom
begin fun env builder ->
let def name ~doc fmt =
ksprintf (fun s -> sprintf "\n(** %s *)\nlet %s = %s" doc name s) fmt in
let lines =
List.map ~f:(sprintf "%s\n") [
"(** Metadata Module Generated by the Build System *)";
def "version" ~doc:"Official version string of the current build"
"lazy %S" version;
def "git_commit" ~doc:"Current Git commit (if avaiable at build-time)"
"%s" (git_last_commit () |> option_to_string);
def "git_description"
~doc:"Current result of [\"git describe\"] \
(if avaiable at build-time)"
"%s" (git_describe () |> option_to_string);
] in
let open Ocamlbuild_plugin in
Seq [
Echo (lines, meta_dot_ml);
]
end
let lib : Project.item =
Project.lib project_name
~thread:()
~bin_annot:()
~findlib_deps
~ml_files:(`Add [Filename.basename meta_dot_ml])
~dir:"src/lib"
~style:(`Pack project_name)
let ocamlinit_postfix = [
sprintf "open %s" (String.capitalize_ascii project_name);
]
let () =
Project.basic1 ~project_name ~version ~ocamlinit_postfix
~additional_rules:[generate_meta_data]
[lib]