Skip to content

Commit 628a9fe

Browse files
authored
Merge pull request #499 from goblint/json-schema
Replace `Defaults` module with JSON schema
2 parents ea03b80 + 1f1deeb commit 628a9fe

File tree

15 files changed

+2125
-613
lines changed

15 files changed

+2125
-613
lines changed

docs/user-guide/configuring.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Configuring
2+
3+
## JSON conf files
4+
5+
### JSON schema
6+
7+
#### VSCode
8+
In `.vscode/settings.json` add the following:
9+
```json
10+
{
11+
"json.schemas": [
12+
{
13+
"fileMatch": [
14+
"/conf/*.json"
15+
],
16+
"url": "/src/util/options.schema.json"
17+
}
18+
]
19+
}
20+
```

dune-project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
(ppx_distr_guards (>= 0.2))
3333
ppx_deriving
3434
ppx_deriving_yojson
35+
(ppx_blob (>= 0.6.0))
3536
(ocaml-monadic (>= 0.5))
3637
(ounit2 :with-test)
3738
(odoc :with-doc)
3839
dune-site
40+
json-data-encoding
3941
(sha (>= 1.12))
4042
(conf-gmp (>= 3)) ; only needed transitively, but they don't have lower bound, which is needed on MacOS
4143
(conf-ruby :with-test)

goblint.opam

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ depends: [
2828
"ppx_distr_guards" {>= "0.2"}
2929
"ppx_deriving"
3030
"ppx_deriving_yojson"
31+
"ppx_blob" {>= "0.6.0"}
3132
"ocaml-monadic" {>= "0.5"}
3233
"ounit2" {with-test}
3334
"odoc" {with-doc}
3435
"dune-site"
36+
"json-data-encoding"
3537
"sha" {>= "1.12"}
3638
"conf-gmp" {>= "3"}
3739
"conf-ruby" {with-test}

goblint.opam.locked

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ homepage: "https://goblint.in.tum.de"
1818
doc: "https://goblint.readthedocs.io/en/latest/"
1919
bug-reports: "https://github.com/goblint/analyzer/issues"
2020
depends: [
21+
"angstrom" {= "0.15.0"}
2122
"apron" {= "v0.9.13"}
2223
"astring" {= "0.8.5" & with-doc}
2324
"base-bigarray" {= "base"}
@@ -26,12 +27,15 @@ depends: [
2627
"base-unix" {= "base"}
2728
"batteries" {= "3.4.0"}
2829
"benchmark" {= "1.6" & with-test}
30+
"bigarray-compat" {= "1.0.0"}
31+
"bigstringaf" {= "0.7.0"}
2932
"biniou" {= "1.2.1"}
3033
"camlidl" {= "1.09"}
3134
"cmdliner" {= "1.0.4" & with-doc}
3235
"conf-gmp" {= "3"}
3336
"conf-mpfr" {= "2"}
3437
"conf-perl" {= "1"}
38+
"conf-pkg-config" {= "2"}
3539
"conf-ruby" {= "1.0.0" & with-test}
3640
"cppo" {= "1.6.7"}
3741
"dune" {= "2.9.1"}
@@ -41,6 +45,7 @@ depends: [
4145
"fmt" {= "0.9.0" & with-doc}
4246
"fpath" {= "0.7.3" & with-doc}
4347
"goblint-cil" {= "1.8.2"}
48+
"json-data-encoding" {= "0.10"}
4449
"logs" {= "0.7.0" & with-doc}
4550
"mlgmpidl" {= "1.2.13"}
4651
"num" {= "1.4"}
@@ -51,11 +56,13 @@ depends: [
5156
"ocaml-migrate-parsetree" {= "2.2.0" & with-doc}
5257
"ocaml-monadic" {= "0.5"}
5358
"ocaml-options-vanilla" {= "1"}
59+
"ocaml-syntax-shims" {= "1.0.0"}
5460
"ocamlbuild" {= "0.14.0"}
5561
"ocamlfind" {= "1.9.1"}
5662
"odoc" {= "2.0.2" & with-doc}
5763
"odoc-parser" {= "0.9.0" & with-doc}
5864
"ounit2" {= "2.2.4" & with-test}
65+
"ppx_blob" {= "0.7.2"}
5966
"ppx_derivers" {= "1.2.1"}
6067
"ppx_deriving" {= "5.2.1"}
6168
"ppx_deriving_yojson" {= "3.6.1"}
@@ -68,9 +75,11 @@ depends: [
6875
"sexplib0" {= "v0.14.0"}
6976
"sha" {= "1.15.1"}
7077
"stdlib-shims" {= "0.3.0"}
78+
"stringext" {= "1.6.0"}
7179
"topkg" {= "1.0.3" & with-doc}
7280
"tyxml" {= "4.4.0" & with-doc}
7381
"uchar" {= "0.0.2" & with-doc}
82+
"uri" {= "4.2.0"}
7483
"uutf" {= "1.0.2" & with-doc}
7584
"yojson" {= "1.7.0"}
7685
"zarith" {= "1.12"}

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nav:
1818
- Home: index.md
1919
- 'User guide':
2020
- user-guide/running.md
21+
- user-guide/configuring.md
2122
- user-guide/inspecting.md
2223
- user-guide/annotating.md
2324
- 'Developer guide':

src/dune

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(public_name goblint.lib)
99
(wrapped false)
1010
(modules :standard \ goblint mainarinc maindomaintest mainspec privPrecCompare apronPrecCompare)
11-
(libraries goblint.sites goblint-cil.all-features batteries.unthreaded qcheck-core.runner sha
11+
(libraries goblint.sites goblint-cil.all-features batteries.unthreaded qcheck-core.runner sha json-data-encoding
1212
; Conditionally compile based on whether apron optional dependency is installed or not.
1313
; Alternative dependencies seem like the only way to optionally depend on optional dependencies.
1414
; See: https://dune.readthedocs.io/en/stable/concepts.html#alternative-dependencies.
@@ -35,7 +35,8 @@
3535
)
3636
(preprocess
3737
(staged_pps ppx_deriving.std ppx_deriving_yojson
38-
ppx_distr_guards ocaml-monadic))
38+
ppx_distr_guards ocaml-monadic ppx_blob))
39+
(preprocessor_deps (file util/options.schema.json))
3940
)
4041

4142
; Workaround for alternative dependencies with unqualified subdirs.

src/maindomaintest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open! Defaults (* Enums / ... need initialized conf *)
1+
(* open! Defaults (* Enums / ... need initialized conf *) *)
22

33
module type FiniteSetElems =
44
sig

src/maingoblint.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
open Prelude
44
open GobConfig
5-
open Defaults
65
open Printf
76
open Goblintutil
87

@@ -83,10 +82,10 @@ let option_spec_list =
8382
set_bool "dbg.print_dead_code" true;
8483
set_string "result" "sarif"
8584
in
86-
let defaults_spec_list = List.map (fun (_, (name, (_, _))) ->
85+
let defaults_spec_list = List.map (fun path ->
8786
(* allow "--option value" as shorthand for "--set option value" *)
88-
("--" ^ name, Arg.String (set_auto name), "")
89-
) !Defaults.registrar
87+
("--" ^ path, Arg.String (set_auto path), "")
88+
) Options.paths
9089
in
9190
let tmp_arg = ref "" in
9291
[ "-o" , Arg.String (set_string "outfile"), ""
@@ -100,8 +99,8 @@ let option_spec_list =
10099
; "--conf" , Arg.String merge_file, ""
101100
; "--writeconf" , Arg.String (fun fn -> writeconffile := fn), ""
102101
; "--version" , Arg.Unit print_version, ""
103-
; "--print_options" , Arg.Unit (fun _ -> printCategory stdout Std; exit 0), ""
104-
; "--print_all_options" , Arg.Unit (fun _ -> printAllCategories stdout; exit 0), ""
102+
; "--print_options" , Arg.Unit (fun () -> Options.print_options (); exit 0), ""
103+
; "--print_all_options" , Arg.Unit (fun () -> Options.print_all_options (); exit 0), ""
105104
; "--trace" , Arg.String set_trace, ""
106105
; "--tracevars" , add_string Tracing.tracevars, ""
107106
; "--tracelocs" , add_int Tracing.tracelocs, ""
@@ -362,13 +361,12 @@ let do_analyze change_info merged_AST =
362361
Printexc.raise_with_backtrace e backtrace (* re-raise with captured inner backtrace *)
363362
(* Cilfacade.current_file := ast'; *)
364363
in
365-
(* old style is ana.activated = [phase_1, ...] with phase_i = [ana_1, ...]
366-
new style (Goblintutil.phase_config = true) is phases[i].ana.activated = [ana_1, ...]
364+
(* new style is phases[i].ana.activated = [ana_1, ...]
367365
phases[i].ana.x overwrites setting ana.x *)
368366
let num_phases =
369367
let np,na,nt = Tuple3.mapn (List.length % get_list) ("phases", "ana.activated", "trans.activated") in
370-
phase_config := np > 0; (* TODO what about wrong usage like { phases = [...], ana.activated = [...] }? should child-lists add to parent-lists? *)
371-
if get_bool "dbg.verbose" then print_endline @@ "Using " ^ if !phase_config then "new" else "old" ^ " format for phases!";
368+
(* TODO what about wrong usage like { phases = [...], ana.activated = [...] }? should child-lists add to parent-lists? *)
369+
if get_bool "dbg.verbose" then print_endline @@ "Using new format for phases!";
372370
if np = 0 && na = 0 && nt = 0 then failwith "No phases and no activated analyses or transformations!";
373371
max np 1
374372
in

0 commit comments

Comments
 (0)