diff --git a/infer/src/base/CommandLineOption.ml b/infer/src/base/CommandLineOption.ml index 4eb79cde5..de5625917 100644 --- a/infer/src/base/CommandLineOption.ml +++ b/infer/src/base/CommandLineOption.ml @@ -282,7 +282,7 @@ let deprecate_desc parse_mode ~long ~short ~deprecated desc = spec = deprecated_spec; decode_json = deprecated_decode_json } let mk ?(deprecated=[]) ?(parse_mode=Infer []) - ~long ?(short="") ~default ~meta doc ~default_to_string ~decode_json ~mk_setter ~mk_spec = + ~long ?short:short0 ~default ~meta doc ~default_to_string ~decode_json ~mk_setter ~mk_spec = let variable = ref default in let closure = mk_setter variable in let setter str = @@ -295,7 +295,8 @@ let mk ?(deprecated=[]) ?(parse_mode=Infer []) let default_string = default_to_string default in if default_string = "" then doc else doc ^ " (default: " ^ default_string ^ ")" in - let desc = {long; short; meta; doc; spec; decode_json} in + let short = match short0 with Some c -> String.of_char c | None -> "" in + let desc = {long; short=short; meta; doc; spec; decode_json} in (* add desc for long option, with documentation (which includes any short option) for exes *) if long <> "" then add parse_mode desc ; (* add desc for short option only for parsing, without documentation *) @@ -306,7 +307,7 @@ let mk ?(deprecated=[]) ?(parse_mode=Infer []) add parse_mode_no_sections {desc with long = ""; meta = ""; doc = ""} ; (* add desc for deprecated options only for parsing, without documentation *) List.iter deprecated ~f:(fun deprecated -> - deprecate_desc parse_mode ~long ~short ~deprecated desc + deprecate_desc parse_mode ~long ~short:short ~deprecated desc |> add parse_mode_no_sections) ; variable @@ -338,7 +339,7 @@ let final_parse_action = ref (Infer Driver) (* end parsing state *) type 'a t = - ?deprecated:string list -> long:Arg.key -> ?short:Arg.key -> + ?deprecated:string list -> long:Arg.key -> ?short:char -> ?parse_mode:parse_mode -> ?meta:string -> Arg.doc -> 'a @@ -373,23 +374,20 @@ let mk_bool ?(deprecated_no=[]) ?(default=false) ?(f=fun b -> b) "no-" ^ long and noshort = Option.map ~f:(fun short -> - let len = String.length short in - if len > 1 && String.sub short ~pos:0 ~len:1 = "n" then - String.sub short ~pos:1 ~len:(len - 1) - else - "n" ^ short + if Char.is_lowercase short then Char.uppercase short + else Char.lowercase short ) short in - let doc nolong = - match noshort with - | Some noshort -> doc ^ " (Conversely: --" ^ nolong ^ " | -" ^ noshort ^ ")" - | None -> doc ^ " (Conversely: --" ^ nolong ^ ")" + let doc long short = + match short with + | Some short -> doc ^ " (Conversely: --" ^ long ^ " | -" ^ String.of_char short ^ ")" + | None -> doc ^ " (Conversely: --" ^ long ^ ")" in let doc, nodoc = if not default then - ("Activates: " ^ doc nolong, "") + ("Activates: " ^ doc nolong noshort, "") else - ("", "Deactivates: " ^ doc long) in + ("", "Deactivates: " ^ doc long short) in let default_to_string _ = "" in let mk_spec set = Unit (fun () -> set "") in let var = diff --git a/infer/src/base/CommandLineOption.mli b/infer/src/base/CommandLineOption.mli index 250722718..2040905c3 100644 --- a/infer/src/base/CommandLineOption.mli +++ b/infer/src/base/CommandLineOption.mli @@ -47,7 +47,7 @@ val init_work_dir : string - a documentation string *) type 'a t = - ?deprecated:string list -> long:string -> ?short:string -> + ?deprecated:string list -> long:string -> ?short:char -> ?parse_mode:parse_mode -> ?meta:string -> string -> 'a @@ -59,8 +59,8 @@ val mk_option : 'a option ref t (** [mk_bool long short doc] defines a [bool ref] set by the command line flag [--long] (and - [-short]), and cleared by the flag [--no-long] (and [-nshort]). If [long] already has a "no-", - or [short] nas an "n", prefix, then the existing prefixes will instead be removed. The default + [-s]), and cleared by the flag [--no-long] (and [-S]). If [long] already has a "no-" prefix, + or [s] is capital, then the existing prefixes will instead be removed. The default value is [false] unless overridden by [~default:true]. The [doc] string will be prefixed with either "Activates:" or "Deactivates:", so should be phrased accordingly. *) val mk_bool : ?deprecated_no:string list -> ?default:bool -> ?f:(bool -> bool) -> bool ref t diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index d3d6fa90d..604fce5cc 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -384,7 +384,7 @@ let inferconfig_home = ~parse_mode:CLOpt.(Infer all_sections) ~meta:"dir" "Path to the .inferconfig file" and project_root = - CLOpt.mk_path ~deprecated:["project_root"; "-project_root"] ~long:"project-root" ~short:"pr" + CLOpt.mk_path ~deprecated:["project_root"; "-project_root"; "pr"] ~long:"project-root" ~short:'C' ~default:CLOpt.init_work_dir ~parse_mode:CLOpt.(Infer [Analysis;Clang;Driver;Print]) ~meta:"dir" "Specify the root directory of the project" @@ -513,7 +513,7 @@ and analyzer = documentation of this option *) | Capture | Compile | Infer | Eradicate | Checkers | Tracing | Crashcontext | Linters | Quandary | Threadsafety | Bufferoverrun -> () in - CLOpt.mk_symbol_opt ~deprecated:["analyzer"] ~long:"analyzer" ~short:"a" + CLOpt.mk_symbol_opt ~deprecated:["analyzer"] ~long:"analyzer" ~short:'a' ~parse_mode:CLOpt.(Infer [Driver]) "Specify which analyzer to run (only one at a time is supported):\n\ - infer, eradicate, checkers, quandary, threadsafety, bufferoverrun: run the specified analysis\n\ @@ -546,7 +546,7 @@ and array_level = - 2 = assumes that all heap dereferences via array indexing and pointer \ arithmetic are correct" and ast_file = - CLOpt.mk_path_opt ~long:"ast-file" ~short:"ast" + CLOpt.mk_path_opt ~deprecated:["ast"] ~long:"ast-file" ~meta:"file" "AST file for the translation" and blacklist = @@ -752,7 +752,7 @@ and ( "Show internal exceptions" and filtering = - CLOpt.mk_bool ~long:"filtering" ~short:"f" ~default:true + CLOpt.mk_bool ~deprecated_no:["nf"] ~long:"filtering" ~short:'f' ~default:true ~parse_mode:CLOpt.(Infer [Driver]) "Do not show the results from experimental checks (note: some of them may contain many false \ alarms)" @@ -788,7 +788,7 @@ and ( "Produce dotty files for specs in the results directory" in let debug = - CLOpt.mk_bool_group ~deprecated:["debug"] ~long:"debug" ~short:"g" + CLOpt.mk_bool_group ~deprecated:["debug"] ~long:"debug" ~short:'g' ~parse_mode:CLOpt.(Infer [Driver]) "Debug mode (also sets --developer-mode, --no-filtering, --print-buckets, --print-types, \ --reports-include-ml-loc, --no-test, --trace-error, --write-dotty, --write-html)" @@ -938,12 +938,12 @@ and from_json_report = files generated by the analysis)." and frontend_debug = - CLOpt.mk_bool ~long:"frontend-debug" ~short:"fd" + CLOpt.mk_bool ~deprecated:["fd"] ~deprecated_no:["nfd"] ~long:"frontend-debug" "Emit debug info to *.o.astlog and a script *.o.sh that replays the command used to run clang \ with the plugin attached, piped to the InferClang frontend command (clang only)" and frontend_stats = - CLOpt.mk_bool ~long:"frontend-stats" ~short:"fs" + CLOpt.mk_bool ~deprecated:["fs"] ~deprecated_no:["nfs"] ~long:"frontend-stats" "Output statistics about the capture phase to *.o.astlog (clang only)" and frontend_tests = @@ -957,7 +957,7 @@ and generated_classes = "Specify where to load the generated class files" and headers = - CLOpt.mk_bool ~deprecated:["headers"] ~deprecated_no:["no_headers"] ~long:"headers" ~short:"hd" + CLOpt.mk_bool ~deprecated:["headers"; "hd"] ~deprecated_no:["no_headers"; "nhd"] ~long:"headers" ~parse_mode:CLOpt.(Infer [Clang]) "Analyze code in header files" @@ -999,7 +999,7 @@ and java_jar_compiler = ~meta:"path" "Specifify the Java compiler jar used to generate the bytecode" and jobs = - CLOpt.mk_int ~deprecated:["-multicore"] ~long:"jobs" ~short:"j" ~default:ncpu + CLOpt.mk_int ~deprecated:["-multicore"] ~long:"jobs" ~short:'j' ~default:ncpu ~parse_mode:CLOpt.(Infer [Driver]) ~meta:"int" "Run the specified number of analysis jobs simultaneously" @@ -1025,7 +1025,7 @@ and linters_developer_mode = default linters and also sets --print-logs, --debug and --no-allowed-failures." and load_average = - CLOpt.mk_float_opt ~long:"load-average" ~short:"l" + CLOpt.mk_float_opt ~long:"load-average" ~short:'l' ~parse_mode:CLOpt.(Infer [Driver]) ~meta:"float" "Do not start new parallel jobs if the load average is greater than that specified (Buck and \ make only)" @@ -1145,7 +1145,8 @@ and procs_xml = --results-dir)" and progress_bar = - CLOpt.mk_bool ~deprecated_no:["no_progress_bar"] ~long:"progress-bar" ~short:"pb" ~default:true + CLOpt.mk_bool ~deprecated:["pb"] ~deprecated_no:["no_progress_bar"; "npb"] ~short:'p' + ~long:"progress-bar" ~default:true ~parse_mode:CLOpt.(Infer [Driver]) "Show a progress bar" @@ -1160,12 +1161,12 @@ and quandary_sinks = "Specify custom sinks for Quandary" and quiet = - CLOpt.mk_bool ~long:"quiet" ~short:"q" ~default:(current_exe <> Print) + CLOpt.mk_bool ~long:"quiet" ~short:'q' ~default:(current_exe <> Print) ~parse_mode:CLOpt.(Infer [Print]) "Do not print specs on standard output" and reactive = - CLOpt.mk_bool ~deprecated:["reactive"] ~long:"reactive" ~short:"r" + CLOpt.mk_bool ~deprecated:["reactive"] ~long:"reactive" ~short:'r' "Reactive mode: the analysis starts from the files captured since the `infer` command started" and reactive_capture = @@ -1213,7 +1214,7 @@ and rest = ) and results_dir = - CLOpt.mk_path ~deprecated:["results_dir"; "-out"] ~long:"results-dir" ~short:"o" + CLOpt.mk_path ~deprecated:["results_dir"; "-out"] ~long:"results-dir" ~short:'o' ~default:(CLOpt.init_work_dir ^/ "infer-out") ~parse_mode:CLOpt.(Infer [Analysis;Clang;Driver;Print]) ~meta:"dir" "Write results and internal files in the specified directory" @@ -1264,7 +1265,7 @@ and spec_abs_level = and specs_library = let specs_library = - CLOpt.mk_path_list ~long:"specs-library" ~short:"lib" + CLOpt.mk_path_list ~deprecated:["lib"] ~long:"specs-library" ~short:'L' ~meta:"dir|jar" "Search for .spec files in given directory or jar file" in let _ = (* Given a filename with a list of paths, convert it into a list of string iff they are @@ -1290,7 +1291,7 @@ and specs_library = specs_library and stacktrace = - CLOpt.mk_path_opt ~long:"stacktrace" ~short:"st" ~parse_mode:CLOpt.(Infer [Crashcontext]) + CLOpt.mk_path_opt ~deprecated:["st"] ~long:"stacktrace" ~parse_mode:CLOpt.(Infer [Crashcontext]) ~meta:"file" "File path containing a json-encoded Java crash stacktrace. Used to guide the \ analysis (only with '-a crashcontext'). See \ tests/codetoanalyze/java/crashcontext/*.json for examples of the expected format." @@ -1321,7 +1322,8 @@ and test_filtering = "List all the files Infer can report on (should be called from the root of the project)" and testing_mode = - CLOpt.mk_bool ~deprecated:["testing_mode"; "-testing_mode"] ~long:"testing-mode" ~short:"tm" + CLOpt.mk_bool ~deprecated:["testing_mode"; "-testing_mode"; "tm"] ~deprecated_no:["ntm"] + ~long:"testing-mode" "Mode for testing, where no headers are translated, and dot files are created (clang only)" and threadsafe_aliases = @@ -1413,7 +1415,7 @@ and xml_specs = Infer.run_javac for a version that looks inside argfiles, and discussion in D4397716. *) let javac_classes_out = CLOpt.mk_string ~parse_mode:CLOpt.Javac - ~deprecated:["classes_out"] ~short:"d" ~long:"" ~default:CLOpt.init_work_dir + ~deprecated:["classes_out"] ~long:"" ~short:'d' ~default:CLOpt.init_work_dir ~f:(fun classes_out -> if !buck then ( let classes_out_infer = resolve classes_out ^/ buck_results_dir_name in @@ -1426,7 +1428,7 @@ let javac_classes_out = and java_classpath = CLOpt.mk_string_opt ~parse_mode:CLOpt.Javac - ~deprecated:["classpath"] ~short:"cp" ~long:"" + ~deprecated:["classpath";"cp"] ~long:"" ~f:(fun classpath -> if !buck then ( let paths = String.split classpath ~on:':' in diff --git a/infer/tests/codetoanalyze/c/bufferoverrun/Makefile b/infer/tests/codetoanalyze/c/bufferoverrun/Makefile index 1c1347076..0e1a95d5b 100644 --- a/infer/tests/codetoanalyze/c/bufferoverrun/Makefile +++ b/infer/tests/codetoanalyze/c/bufferoverrun/Makefile @@ -12,7 +12,7 @@ TESTS_DIR = ../../.. ANALYZER = bufferoverrun CLANG_OPTIONS = -c -INFER_OPTIONS = -nf --project-root $(TESTS_DIR) --no-failures-allowed +INFER_OPTIONS = -F --project-root $(TESTS_DIR) --no-failures-allowed INFERPRINT_OPTIONS = --issues-tests SOURCES = \