File: project_read.ml

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 (51 lines) | stat: -rw-r--r-- 1,876 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
(** New parser integration for Project reading

    This module provides an alternative to Project.read that uses the new parser (obuild_lexer ->
    obuild_parser -> obuild_validate).

    It's in a separate module to avoid cyclic dependencies between Project and Obuild_validate. *)

open Filepath

(** Convert Project.Generator.t to Generators.custom *)
let convert_generator_to_custom (gen : Project.Generator.t) : Generators.custom =
  {
    Generators.custom_name = gen.Project.Generator.name;
    custom_suffix = gen.Project.Generator.suffix;
    custom_command = gen.Project.Generator.command;
    custom_outputs = gen.Project.Generator.outputs;
    custom_module_name = gen.Project.Generator.module_name;
  }

(** Register custom generators from project *)
let register_generators proj =
  (* Clear any previously registered custom generators *)
  Generators.clear_custom_generators ();
  (* Register new ones *)
  List.iter (fun gen ->
    Generators.register_custom (convert_generator_to_custom gen)
  ) proj.Project.generators

(** Read project file using the new parser *)
let read () =
  let path = Project.findPath () in
  let proj =
    try Obuild_validate.parse_and_convert_file (fp_to_string path) with
    | Obuild_validate.Validation_error (loc, msg) ->
        raise
          (Project.InvalidConfFile
             (Printf.sprintf "%d:%d: %s" loc.Location.line loc.Location.col msg))
    | Obuild_parser.Parser_error (loc, msg) ->
        raise
          (Project.InvalidConfFile
             (Printf.sprintf "%d:%d: %s" loc.Location.line loc.Location.col msg))
  in
  (* Apply ocaml_extra_args side effect *)
  (match proj.Project.ocaml_extra_args with
  | Some args -> Gconf.gconf.Gconf.ocaml_extra_args <- args
  | None -> ());
  (* Register custom generators *)
  register_generators proj;
  (* Validate file existence *)
  Project.check proj;
  proj