forked from facebook/pyre-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.ml
215 lines (192 loc) · 5.74 KB
/
configuration.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
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
(* Copyright (c) 2016-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. *)
open Core
open Pyre
module Features = struct
type t = {
click_to_fix: bool;
go_to_definition: bool;
hover: bool;
}
[@@deriving yojson, show]
let default = { click_to_fix = true; go_to_definition = false; hover = false }
let create feature_string =
feature_string
>>| (fun feature_string ->
let json_string = Yojson.Safe.from_string feature_string in
let default_from_string string =
let { click_to_fix; go_to_definition; hover } = default in
match string with
| "click_to_fix" -> click_to_fix
| "go_to_definition" -> go_to_definition
| "hover" -> hover
| _ -> false
in
let parse_feature string =
match Yojson.Safe.Util.member string json_string with
| `Bool value -> value
| _ -> default_from_string string
in
let click_to_fix = parse_feature "click_to_fix" in
let go_to_definition = parse_feature "go_to_definition" in
let hover = parse_feature "hover" in
{ click_to_fix; go_to_definition; hover })
|> Option.value ~default
end
module Analysis = struct
type incremental_style =
| Shallow
| FineGrained
[@@deriving show]
type t = {
infer: bool;
configuration_file_hash: string option;
parallel: bool;
analyze_external_sources: bool;
filter_directories: Path.t list option;
ignore_all_errors: Path.t list option;
number_of_workers: int;
local_root: Path.t;
debug: bool;
project_root: Path.t;
source_path: Path.t list;
search_path: SearchPath.t list;
taint_model_paths: Path.t list;
expected_version: string option;
strict: bool;
show_error_traces: bool;
excludes: Str.regexp list; [@opaque]
extensions: string list;
store_type_check_resolution: bool;
incremental_style: incremental_style;
include_hints: bool;
perform_autocompletion: bool;
features: Features.t;
ignore_infer: Path.t list;
log_directory: Path.t;
}
[@@deriving show]
let equal first second =
Bool.equal first.infer second.infer
&& [%compare.equal: string option] first.expected_version second.expected_version
&& Bool.equal first.strict second.strict
let create
?(infer = false)
?configuration_file_hash
?(parallel = true)
?(analyze_external_sources = false)
?filter_directories
?ignore_all_errors
?(number_of_workers = 4)
?(local_root = Path.current_working_directory ())
?(project_root = Path.create_absolute "/")
?(search_path = [])
?(taint_model_paths = [])
?expected_version
?(strict = false)
?(debug = false)
?(show_error_traces = false)
?(excludes = [])
?(extensions = [])
?(store_type_check_resolution = true)
?(incremental_style = Shallow)
?(include_hints = false)
?(perform_autocompletion = false)
?(features = Features.default)
?(ignore_infer = [])
?log_directory
~source_path
()
=
{
infer;
configuration_file_hash;
parallel;
analyze_external_sources;
filter_directories;
ignore_all_errors;
number_of_workers;
local_root;
debug;
project_root;
source_path;
search_path;
taint_model_paths;
expected_version;
strict;
show_error_traces;
excludes =
List.map excludes ~f:(fun exclude_regex ->
Str.global_substitute
(Str.regexp_string "${SOURCE_DIRECTORY}")
(fun _ -> Path.absolute local_root)
exclude_regex
|> Str.regexp);
extensions;
store_type_check_resolution;
incremental_style;
include_hints;
perform_autocompletion;
features;
ignore_infer;
log_directory =
( match log_directory with
| Some directory -> Path.create_absolute directory
| None -> Path.append local_root ~element:".pyre" );
}
let log_directory { log_directory; _ } = log_directory
let search_path { source_path; search_path; _ } =
(* Have an ordering of search_path > source_path with the parser. search_path precedes
* local_root due to the possibility of having a subdirectory of the root in the search path. *)
search_path @ List.map source_path ~f:(fun path -> SearchPath.Root path)
let features { features; _ } = features
end
module Server = struct
type load_parameters = {
shared_memory_path: Path.t;
changed_files_path: Path.t option;
}
type load =
| LoadFromFiles of load_parameters
| LoadFromProject of {
project_name: string;
metadata: string option;
}
type saved_state_action =
| Save of string
| Load of load
type socket_path = {
path: Path.t;
link: Path.t;
}
type t = {
(* Server-specific configuration options *)
socket: socket_path;
json_socket: socket_path;
adapter_socket: socket_path;
lock_path: Path.t;
pid_path: Path.t;
log_path: Path.t;
daemonize: bool;
saved_state_action: saved_state_action option;
(* Analysis configuration *)
configuration: Analysis.t;
}
(* Required to appease the compiler. *)
let global : t option ref = ref None
let set_global configuration = global := Some configuration
let get_global () = !global
end
module StaticAnalysis = struct
type t = {
result_json_path: Path.t option;
dump_call_graph: bool;
verify_models: bool;
(* Analysis configuration *)
configuration: Analysis.t;
rule_filter: int list option;
find_obscure_flows: bool;
}
end