File: jbuild_plugin.ml

package info (click to toggle)
ocaml-dune 3.20.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,564 kB
  • sloc: ml: 175,178; asm: 28,570; ansic: 5,251; sh: 1,096; lisp: 625; makefile: 148; python: 125; cpp: 48; javascript: 10
file content (54 lines) | stat: -rw-r--r-- 1,429 bytes parent folder | download | duplicates (2)
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
let directive_table = Toploop.directive_table [@@ocaml.warning "-3"]

let () =
  Hashtbl.add directive_table "require" (Toploop.Directive_string ignore);
  Hashtbl.add
    directive_table
    "use"
    (Toploop.Directive_string
       (fun _ -> failwith "#use is not allowed inside a dune file in OCaml syntax"));
  Hashtbl.add
    directive_table
    "use_mod"
    (Toploop.Directive_string
       (fun _ -> failwith "#use is not allowed inside a dune file in OCaml syntax"))
;;

module V1 = struct
  (*$ begin_vars $*)
  let context = "dummy_context"
  let ocaml_version = "dummy_version"
  let ocamlc_config = []
  let send_target = "dummy_send_target"

  (*$ end_vars $*)

  let send s =
    let oc = open_out_bin send_target in
    output_string oc s;
    close_out oc
  ;;

  let run_and_read_lines cmd =
    let tmp_fname = Filename.temp_file "dune" ".output" in
    at_exit (fun () -> Sys.remove tmp_fname);
    let n = Printf.ksprintf Sys.command "%s > %s" cmd (Filename.quote tmp_fname) in
    let rec loop ic acc =
      match input_line ic with
      | exception End_of_file ->
        close_in ic;
        List.rev acc
      | line -> loop ic (line :: acc)
    in
    let output = loop (open_in tmp_fname) [] in
    if n = 0
    then output
    else
      Printf.ksprintf
        failwith
        "Command failed: %%s\nExit code: %%d\nOutput:\n%%s"
        cmd
        n
        (String.concat "\n" output)
  ;;
end