diff options
| author | Lasse Blaauwbroek | 2020-03-17 22:59:23 +0100 |
|---|---|---|
| committer | Lasse Blaauwbroek | 2020-03-21 14:31:20 +0100 |
| commit | 3e98d9bd37d629f90e0a5702f6deb5b835815b5a (patch) | |
| tree | 8f5547edeba39bd3a47a9dfea72038da41c90ec3 /toplevel/ccompile.ml | |
| parent | 4d025d4161599ea20cd1dbf489a6412f019a7a7e (diff) | |
Reorder the load/require cmd-options and set/unset cmd-options
Make sure that all initial load vernaculars that were specified on the command line are executed before processing the options set through -set on the command line.
The reason for this is that the load vernacular options can load plugins that define new Goptions. If these plugins are not loaded before the -set flags are processed,
then Goptions will emit a warning that the options of that plugin don't exist and ignore the flag.
Diffstat (limited to 'toplevel/ccompile.ml')
| -rw-r--r-- | toplevel/ccompile.ml | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/toplevel/ccompile.ml b/toplevel/ccompile.ml index d0d6b8b0a3..a7a9b77b56 100644 --- a/toplevel/ccompile.ml +++ b/toplevel/ccompile.ml @@ -92,6 +92,41 @@ let create_empty_file filename = let f = open_out filename in close_out f +let interp_set_option opt v old = + let open Goptions in + let err expect = + let opt = String.concat " " opt in + let got = v in (* avoid colliding with Pp.v *) + CErrors.user_err + Pp.(str "-set: " ++ str opt ++ + str" expects " ++ str expect ++ + str" but got " ++ str got) + in + match old with + | BoolValue _ -> + let v = match String.trim v with + | "true" -> true + | "false" | "" -> false + | _ -> err "a boolean" + in + BoolValue v + | IntValue _ -> + let v = String.trim v in + let v = match int_of_string_opt v with + | Some _ as v -> v + | None -> if v = "" then None else err "an int" + in + IntValue v + | StringValue _ -> StringValue v + | StringOptValue _ -> StringOptValue (Some v) + +let set_option = let open Goptions in function + | opt, OptionUnset -> unset_option_value_gen ~locality:OptLocal opt + | opt, OptionSet None -> set_bool_option_value_gen ~locality:OptLocal opt true + | opt, OptionSet (Some v) -> set_option_value ~locality:OptLocal (interp_set_option opt) opt v + +let set_options = List.iter set_option + (* Compile a vernac file *) let compile opts copts ~echo ~f_in ~f_out = let open Vernac.State in @@ -134,6 +169,7 @@ let compile opts copts ~echo ~f_in ~f_out = } in let state = { doc; sid; proof = None; time = opts.config.time } in let state = load_init_vernaculars opts ~state in + set_options opts.config.set_options; let ldir = Stm.get_ldir ~doc:state.doc in Aux_file.(start_aux_file ~aux_file:(aux_file_name_for long_f_dot_out) @@ -187,6 +223,7 @@ let compile opts copts ~echo ~f_in ~f_out = let state = { doc; sid; proof = None; time = opts.config.time } in let state = load_init_vernaculars opts ~state in + set_options opts.config.set_options; let ldir = Stm.get_ldir ~doc:state.doc in let state = Vernac.load_vernac ~echo ~check:false ~interactive:false ~state long_f_dot_in in let doc = Stm.finish ~doc:state.doc in |
