package bisect_ppx

  1. Overview
  2. Docs

Source file register.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
(* This file is part of Bisect_ppx, released under the MIT license. See
   LICENSE.md for details, or visit
   https://github.com/aantron/bisect_ppx/blob/master/LICENSE.md. *)



module Common = Bisect_common

let conditional = ref false

let enabled () =
  match !conditional with
  | false ->
    `Enabled
  | true ->
    match Sys.getenv "BISECT_ENABLE" with
    | exception Not_found ->
      `Disabled
    | s when (String.uppercase [@ocaml.warning "-3"]) s = "YES" ->
      `Enabled
    | _ ->
      `Disabled

let conditional_exclude_file filename =
  match enabled () with
  | `Enabled -> Exclusions.add_file filename
  | `Disabled -> ()

let switches = [
  ("--exclude",
   Arg.String (fun s ->
    prerr_endline "bisect_ppx argument '--exclude' is deprecated.";
    prerr_endline "Use '--exclusions' instead.";
    Exclusions.add s),
   " Deprecated");

  ("--exclusions",
   Arg.String conditional_exclude_file,
   "<filename>  Exclude functions listed in given file");

  ("--exclude-file",
   Arg.String (fun s ->
    prerr_endline "bisect_ppx argument '--exclude-file' is deprecated.";
    prerr_endline "It has been renamed to '--exclusions'.";
    conditional_exclude_file s),
   " Deprecated");

  ("--conditional",
  Arg.Set conditional,
  " Do not instrument unless environment variable BISECT_ENABLE is YES");

  ("--no-comment-parsing",
  Arg.Unit (fun () ->
    prerr_endline "bisect_ppx argument '--no-comment-parsing' is deprecated."),
  " Deprecated");

  ("-mode",
  (Arg.Symbol (["safe"; "fast"; "faster"], fun _ ->
    prerr_endline "bisect_ppx argument '-mode' is deprecated.")),
  " Deprecated") ;
]

let deprecated = Common.deprecated "bisect_ppx"

let switches =
  switches
  |> deprecated "-exclude"
  |> deprecated "-exclude-file"
  |> deprecated "-conditional"
  |> deprecated "-no-comment-parsing"
  |> Arg.align



let () =
  Migrate_parsetree.Driver.register
    ~name:"bisect_ppx" ~args:switches ~position:100
    Migrate_parsetree.Versions.ocaml_410 begin fun _config _cookies ->
      match enabled () with
      | `Enabled ->
        Ppx_tools_410.Ast_mapper_class.to_mapper (new Instrument.instrumenter)
      | `Disabled ->
        Migrate_parsetree.Ast_410.shallow_identity
    end
OCaml

Innovation. Community. Security.