File: project.mli

package info (click to toggle)
ocaml-obuild 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,456 kB
  • sloc: ml: 14,491; sh: 211; ansic: 34; makefile: 11
file content (327 lines) | stat: -rw-r--r-- 9,394 bytes parent folder | download
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
(** Project configuration file (.obuild) parsing and representation

    This module handles parsing and representation of obuild project files,
    which define libraries, executables, tests, and build configuration. *)

(** {1 Exceptions} *)

exception NoConfFile
(** Raised when no .obuild configuration file is found *)

exception MultipleConfFiles
(** Raised when multiple .obuild files exist in the same directory *)

exception InvalidConfFile of string
(** Raised when configuration file has invalid syntax or structure *)

exception MissingField of string
(** Raised when a required field is missing *)

exception UnknownDependencyName of string
(** Raised when a dependency name cannot be resolved *)

exception UnsupportedFutureVersion of int
(** Raised when .obuild file uses a newer format version *)

exception ModuleNotFound of Target.target * Hier.t
(** Raised when a declared module file doesn't exist *)

exception ModuleListEmpty of Libname.t
(** Raised when a library has no modules defined *)

exception FileNotFound of Target.target * Filepath.filename
(** Raised when a referenced file doesn't exist *)

exception LicenseFileNotFound of Filepath.filepath
(** Raised when the declared license file doesn't exist *)

exception BlockSectionAsValue of string
(** Raised when trying to use a block section as a simple value *)

exception ExecutableWithNoMain of string
(** Raised when an executable has no main file defined *)

exception UnknownStdlib of string
(** Raised when an unknown stdlib is specified *)

exception UnknownExtraDepFormat of string
(** Raised when extra dependency format is invalid *)

exception UnknownFlag of string
(** Raised when an unknown flag is referenced *)

exception BadOcamlVersion of (string * Expr.t)
(** Raised when OCaml version constraint is invalid *)

exception LibraryNotFound of Libname.t
(** Raised when a library cannot be found in the project *)

exception ExecutableNotFound of string
(** Raised when an executable cannot be found in the project *)

exception BenchNotFound of string
(** Raised when a benchmark cannot be found in the project *)

exception TestNotFound of string
(** Raised when a test cannot be found in the project *)

exception ExampleNotFound of string
(** Raised when an example cannot be found in the project *)

(** {1 Library Configuration} *)

module Library : sig
  type t = {
    name : Libname.t;
    description : string;
    target : Target.target;
    modules : Hier.t list;
    pack : bool;
    syntax : bool;
    subs : t list;
  }
  (** Library configuration with optional sublibraries *)

  val make : Libname.t -> t
  (** Create a new library with default settings *)

  val make_prefix : Libname.t -> string -> t
  (** Create a sublibrary with prefixed name *)

  val make_from_string : string -> t
  (** Create a library from string name *)

  val to_target : t -> Target.target
  (** Extract target from library *)

  val to_targets : t -> Target.target list
  (** Get all targets (library + sublibraries) *)

  val flatten : t -> t list
  (** Flatten library hierarchy into list *)

  val find : t list -> Libname.t -> t
  (** Find library by name in list
      @raise LibraryNotFound if not found *)

  val check_modules_not_empty : t -> unit
  (** Verify library has modules defined
      @raise ModuleListEmpty if empty *)
end

(** {1 Executable Configuration} *)

module Executable : sig
  type t = {
    name : string;
    main : Filepath.filename;
    target : Target.target;
  }
  (** Executable configuration *)

  val make : string -> t
  (** Create new executable with default settings *)

  val to_target : t -> Target.target
  (** Extract target from executable *)

  val find : t list -> string -> t
  (** Find executable by name in list
      @raise ExecutableNotFound if not found *)
end

(** {1 Test Configuration} *)

module Test : sig
  type test_type = ExitCode
  (** Test type - currently only exit code tests supported *)

  type t = {
    name : string;
    main : Filepath.filename;
    target : Target.target;
    rundir : Filepath.filepath option;
    runopt : string list;
    type_ : test_type;
  }
  (** Test configuration *)

  val make :
    name:string ->
    main:Filepath.filename ->
    target:Target.target ->
    rundir:Filepath.filepath option ->
    runopt:string list ->
    t
  (** Create test from parameters. Buildable defaults to CLI option "build-tests". *)

  val to_target : t -> Target.target
  (** Extract target from test *)

  val find : t list -> string -> t
  (** Find test by name in list
      @raise TestNotFound if not found *)
end

(** {1 Benchmark Configuration} *)

module Bench : sig
  type t = {
    name : string;
    main : Filepath.filename;
    target : Target.target;
  }
  (** Benchmark configuration *)

  val make :
    name:string ->
    main:Filepath.filename ->
    target:Target.target ->
    t
  (** Create benchmark from parameters. Buildable defaults to CLI option "build-benchs". *)

  val to_target : t -> Target.target
  (** Extract target from benchmark *)

  val find : t list -> string -> t
  (** Find benchmark by name in list
      @raise BenchNotFound if not found *)
end

(** {1 Example Configuration} *)

module Example : sig
  type t = {
    name : string;
    main : Filepath.filename;
    target : Target.target;
  }
  (** Example executable configuration *)

  val make :
    name:string ->
    main:Filepath.filename ->
    target:Target.target ->
    t
  (** Create example from parameters. Buildable defaults to CLI option "build-examples". *)

  val to_target : t -> Target.target
  (** Extract target from example *)

  val find : t list -> string -> t
  (** Find example by name in list
      @raise ExampleNotFound if not found *)
end

(** {1 Flag Configuration} *)

module Flag : sig
  type t = {
    name : string;
    description : string;
    default : bool option;
  }
  (** Compile-time flag configuration *)
end

(** {1 Generator Configuration} *)

module Generator : sig
  type t = {
    name : string;                    (** Generator name for reference *)
    suffix : string option;           (** File extension for automatic detection (e.g., "mly") *)
    command : string;                 (** Command template with variables: ${src}, ${dest}, ${base}, ${sources} *)
    outputs : string list;            (** Output file patterns *)
    module_name : string option;      (** Module name pattern if different from base *)
  }
  (** Custom generator configuration.
      Generators with a suffix are automatically triggered during module discovery.
      Generators without a suffix must be used via explicit generate blocks. *)

  val make : string -> t
  (** Create a new generator with default settings *)
end

(** {1 Main Project Type} *)

type t = {
  name : string;
  version : string;
  synopsis : string;
  description : string;
  license : string;
  license_file : Filepath.filepath option;
  authors : string list;
  obuild_ver : int;
  ocaml_ver : Expr.t option;
  homepage : string;
  flags : Flag.t list;
  generators : Generator.t list;
  libs : Library.t list;
  exes : Executable.t list;
  tests : Test.t list;
  benchs : Bench.t list;
  examples : Example.t list;
  extra_srcs : Filepath.filepath list;
  extra_tools : Filepath.filename list;
  configure_script : Filepath.filepath option;
  ocaml_extra_args : string list option;
}
(** Project configuration structure *)

val make : t
(** Empty project with default values *)

(** {1 Project File Operations} *)

val findPath : unit -> Filepath.filepath
(** Find .obuild configuration file in current directory.
    @raise NoConfFile if no .obuild file found
    @raise MultipleConfFiles if multiple .obuild files found *)

val digest : unit -> Digest.t
(** Compute digest of project configuration file *)

val write : Filepath.filepath -> t -> unit
(** [write file proj] writes project configuration to file *)

val check : t -> unit
(** [check proj] validates the project configuration.
    Checks that required files and modules exist on disk.
    @raise ModuleNotFound if a declared module doesn't exist
    @raise FileNotFound if a referenced file doesn't exist
    @raise LicenseFileNotFound if license file is missing
    @raise ExecutableWithNoMain if executable has no main file
    @raise BadOcamlVersion if OCaml version constraint fails *)

(** {1 Target Operations} *)

val get_all_buildable_targets : t -> (string * bool) list -> Target.target list
(** [get_all_buildable_targets proj user_flags] returns all buildable targets
    given user-specified flags *)

val get_all_installable_targets : t -> (string * bool) list -> Target.target list
(** [get_all_installable_targets proj user_flags] returns all installable targets
    given user-specified flags *)

(** {1 Lookup Functions} *)

val find_lib : t -> Libname.t -> Library.t
(** Find library in project by name
    @raise LibraryNotFound if not found *)

val find_exe : t -> string -> Executable.t
(** Find executable in project by name
    @raise ExecutableNotFound if not found *)

val find_test : t -> string -> Test.t
(** Find test in project by name
    @raise TestNotFound if not found *)

val find_bench : t -> string -> Bench.t
(** Find benchmark in project by name
    @raise BenchNotFound if not found *)

val find_example : t -> string -> Example.t
(** Find example in project by name
    @raise ExampleNotFound if not found *)