-
Notifications
You must be signed in to change notification settings - Fork 1
/
myocamlbuild.ml
141 lines (127 loc) · 3.29 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
open Nonstd
open Solvuu_build.Std
let project_name = "coclobas"
let version = "0.0.3-dev"
let build_tests =
try Sys.getenv "WITH_TESTS" = "true" with _ -> false
let findlib_deps = [
"nonstd";
"sosa";
"pvem_lwt_unix";
"cohttp.lwt";
"trakeva_of_uri";
"cmdliner";
"ppx_deriving.std";
"ppx_deriving_yojson";
"uuidm";
"base64";
"odate";
]
let meta_dot_ml = "src/lib/meta.ml"
let generate_meta_data () =
let git_last_commit () =
try
Some (
Ocamlbuild_pack.My_unix.run_and_read "git rev-parse HEAD"
|> fun x -> String.sub x 0 (String.length x - 1)
)
with _ -> None in
Solvuu_build.Util.Rule.rule
~name:"meta-data-generation"
~prods:[meta_dot_ml]
~deps:[]
~insert:`bottom
begin fun env builder ->
let lines = List.map ~f:(sprintf "%s\n") [
"(** Metadata Module Generated by the Build System *)";
"";
sprintf "let version = %S" version;
"";
sprintf "let git_commit = %s"
(Option.value_map (git_last_commit ()) ~default:"None"
~f:(sprintf "Some %S"));
] 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 ketrew_backend : Project.item option =
let item =
Project.lib (project_name ^ "_ketrew_backend")
~thread:()
~bin_annot:()
~findlib_deps:("ketrew" :: findlib_deps)
~dir:"src/ketrew_backend"
~style:(`Pack (project_name ^ "_ketrew_backend"))
~internal_deps:[lib]
~install:(`Findlib (project_name ^ ".ketrew_backend"))
in
if Project.dep_opts_sat item ["ketrew"]
then Some item
else None
let app : Project.item =
Project.app project_name
~thread:()
~file:"src/app/main.ml"
~internal_deps:[lib]
let test_findlib_deps = [
"ppx_deriving_cmdliner"
]
let test : Project.item option =
if build_tests
then Some (
Project.app (project_name ^ "-test")
~thread:()
~bin_annot:()
~file:"src/test/client_server.ml"
~install:`No
~internal_deps:[lib]
~findlib_deps:test_findlib_deps
) else None
let linked_ketrew : Project.item option =
match ketrew_backend with
| Some kb ->
Some (
Project.app (project_name ^ "-ketrew")
~thread:()
~bin_annot:()
~file:"src/test/cocloketrew.ml"
~internal_deps:[lib; kb]
)
| _ -> None
let test_ketrew_workflow : Project.item option =
match build_tests, ketrew_backend with
| true, Some kb ->
Some (
Project.app (project_name ^ "-ketrew-workflow-test")
~thread:()
~bin_annot:()
~install:`No
~file:"src/test/workflow_test.ml"
~internal_deps:[lib; kb]
~findlib_deps:test_findlib_deps
)
| _, _ -> None
let ocamlinit_postfix = [
sprintf "open %s" (String.capitalize_ascii project_name);
]
let () =
Project.basic1 ~project_name ~version ~ocamlinit_postfix
~additional_rules:[generate_meta_data]
(List.filter_opt [
Some lib;
Some app;
test;
ketrew_backend;
linked_ketrew;
test_ketrew_workflow;
])