Pre-parse inferconfig_home and project_root

Summary:
Parse the inferconfig_home and project_root options in a separate phase
before other options.  This enables using their values to e.g. find the
inferconfig file and process it prior to full option parsing.

Reviewed By: jvillard

Differential Revision: D3302143

fbshipit-source-id: a1f9175
master
Josh Berdine 9 years ago committed by Facebook Github Bot 4
parent 88a2da91fc
commit acb227ec30

@ -308,7 +308,7 @@ let prefix_before_rest args =
prefix_before_rest_ [] args prefix_before_rest_ [] args
let parse env_var exe_usage = let parse ?(incomplete=false) env_var exe_usage =
let curr_speclist = ref [] let curr_speclist = ref []
and full_speclist = ref [] and full_speclist = ref []
in in
@ -368,11 +368,17 @@ let parse env_var exe_usage =
let env_args = c_args @ env_args in let env_args = c_args @ env_args in
(* end transitional support for INFERCLANG_ARGS *) (* end transitional support for INFERCLANG_ARGS *)
let exe_name, env_cl_args = prepend_to_argv env_args in let exe_name, env_cl_args = prepend_to_argv env_args in
Unix.putenv env_var (encode_argv_to_env (prefix_before_rest env_cl_args)) ; let current = ref 0 in
(try let rec parse_loop () =
Arg.parse_argv (Array.of_list (exe_name :: env_cl_args)) !curr_speclist !anon_fun usage_msg try
Arg.parse_argv_dynamic ~current (Array.of_list (exe_name :: env_cl_args))
curr_speclist !anon_fun usage_msg
with with
| Arg.Bad _ when incomplete -> parse_loop ()
| Arg.Bad usage_msg -> Pervasives.prerr_string usage_msg; exit 2 | Arg.Bad usage_msg -> Pervasives.prerr_string usage_msg; exit 2
| Arg.Help usage_msg -> Pervasives.print_string usage_msg; exit 0 | Arg.Help usage_msg -> Pervasives.print_string usage_msg; exit 0
); in
parse_loop () ;
if not incomplete then
Unix.putenv env_var (encode_argv_to_env (prefix_before_rest env_cl_args)) ;
curr_usage curr_usage

@ -93,4 +93,4 @@ val mk_anon :
Therefore arguments passed on the command line supercede those specified in the environment Therefore arguments passed on the command line supercede those specified in the environment
variable. WARNING: If an argument appears both in the environment variable and on the command variable. WARNING: If an argument appears both in the environment variable and on the command
line, it will be interpreted twice. *) line, it will be interpreted twice. *)
val parse : string -> (exe -> Arg.usage_msg) -> (int -> 'a) val parse : ?incomplete:bool -> string -> (exe -> Arg.usage_msg) -> (int -> 'a)

@ -191,6 +191,34 @@ let os_type = match Sys.os_type with
(** Command Line options *) (** Command Line options *)
(* Declare the phase 1 options *)
let inferconfig_home =
CLOpt.mk_string_opt ~deprecated:["inferconfig_home"] ~long:"inferconfig-home"
~exes:CLOpt.[A] ~meta:"dir" "Path to the .inferconfig file"
and project_root =
CLOpt.mk_string_opt ~deprecated:["project_root"] ~long:"project-root" ~short:"pr"
?default:(if CLOpt.(current_exe = P) then Some (Sys.getcwd ()) else None)
~f:filename_to_absolute
~exes:CLOpt.[A;C;J;L;P] ~meta:"dir" "Specify the root directory of the project"
(* Parse the phase 1 options, ignoring the rest *)
let _ = CLOpt.parse ~incomplete:true "INFER_ARGS" (fun _ -> "")
(* Define the values that depend on phase 1 options *)
let inferconfig_home = !inferconfig_home
and project_root = !project_root
let inferconfig_path =
match inferconfig_home, project_root with
| Some dir, _ | _, Some dir -> Filename.concat dir inferconfig_file
| None, None -> inferconfig_file
(* Proceed to declare and parse the remaining options *)
(** The references representing the command line options are defined in a single (** The references representing the command line options are defined in a single
simultaneous let...and...and... binding in order to allow the type-checker to catch simultaneous let...and...and... binding in order to allow the type-checker to catch
uses of one reference in code for another. This avoids being sensitive to uses of one reference in code for another. This avoids being sensitive to
@ -391,10 +419,6 @@ and infer_cache =
~f:filename_to_absolute ~f:filename_to_absolute
~meta:"dir" "Select a directory to contain the infer cache" ~meta:"dir" "Select a directory to contain the infer cache"
and inferconfig_home =
CLOpt.mk_string_opt ~deprecated:["inferconfig_home"] ~long:"inferconfig-home"
~exes:CLOpt.[A] ~meta:"dir" "Path to the .inferconfig file"
(** Set the timeout values in seconds and symops, computed as a multiple of the integer (** Set the timeout values in seconds and symops, computed as a multiple of the integer
parameter *) parameter *)
and iterations = and iterations =
@ -529,12 +553,6 @@ and progress_bar =
CLOpt.mk_bool ~deprecated_no:["no_progress_bar"] ~long:"progress-bar" ~short:"pb" ~default:true CLOpt.mk_bool ~deprecated_no:["no_progress_bar"] ~long:"progress-bar" ~short:"pb" ~default:true
"Show a progress bar" "Show a progress bar"
and project_root =
CLOpt.mk_string_opt ~deprecated:["project_root"] ~long:"project-root" ~short:"pr"
?default:(if CLOpt.(current_exe = P) then Some (Sys.getcwd ()) else None)
~f:filename_to_absolute
~exes:CLOpt.[A;C;J;L;P] ~meta:"dir" "Specify the root directory of the project"
(** command line flag: if true, do not print the spec to standard output *) (** command line flag: if true, do not print the spec to standard output *)
and quiet = and quiet =
CLOpt.mk_bool ~long:"quiet" ~short:"q" CLOpt.mk_bool ~long:"quiet" ~short:"q"
@ -994,7 +1012,6 @@ and print_types = !print_types
and print_using_diff = !print_using_diff and print_using_diff = !print_using_diff
and procs_csv = !procs_csv and procs_csv = !procs_csv
and procs_xml = !procs_xml and procs_xml = !procs_xml
and project_root = !project_root
and quiet = !quiet and quiet = !quiet
and reactive_mode = !reactive and reactive_mode = !reactive
and report = !report and report = !report
@ -1029,10 +1046,6 @@ and xml_specs = !xml_specs
and zip_libraries = !zip_libraries and zip_libraries = !zip_libraries
let inferconfig_json = let inferconfig_json =
let inferconfig_path =
match !inferconfig_home, project_root with
| Some dir, _ | _, Some dir -> Filename.concat dir inferconfig_file
| None, None -> inferconfig_file in
lazy ( lazy (
match read_optional_json_file inferconfig_path with match read_optional_json_file inferconfig_path with
| Ok json -> json | Ok json -> json

Loading…
Cancel
Save