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
(* This Source Code Form is subject to the terms of the Mozilla Public License,
   v. 2.0. If a copy of the MPL was not distributed with this file, You can
   obtain one at http://mozilla.org/MPL/2.0/. *)



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 Exclusions.add,
  "<pattern>  Exclude functions matching pattern") ;

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

  ("-mode",
  (Arg.Symbol (["safe"; "fast"; "faster"], ignore)),
  "  Ignored") ;

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



open Migrate_parsetree
open Ppx_tools_405

let () =
  Driver.register ~name:"bisect_ppx" ~args:switches
    Versions.ocaml_405 begin fun _config _cookies ->
      match enabled () with
      | `Enabled ->
        Ast_mapper_class.to_mapper (new Instrument.instrumenter)
      | `Disabled ->
        Ast_405.shallow_identity
    end