From a6f54b9cefc5f36a0f7408fd895bb570aaf6fe77 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 10 Jan 2017 09:24:01 -0800 Subject: [PATCH] [cli] do not complain about "arguments must be .specs file" from non-toplevel invocations Summary: This error message is confusing when the user is not actually running InferPrint, eg `infer foo`: `Load Error: file foo: arguments must be .specs files`. With this diff, we don't get any error for `infer foo`, which is not great either and will need to be addressed (do we support all the python arguments in OCaml now too and are able to turn on argument parsing errors in OCaml land?). Reviewed By: jberdine Differential Revision: D4397765 fbshipit-source-id: e7ca48f --- infer/src/backend/InferPrint.re | 45 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/infer/src/backend/InferPrint.re b/infer/src/backend/InferPrint.re index 9369f4675..ae669f570 100644 --- a/infer/src/backend/InferPrint.re +++ b/infer/src/backend/InferPrint.re @@ -9,6 +9,8 @@ */ open! IStd; +let module CLOpt = CommandLineOption; + let module Hashtbl = Caml.Hashtbl; let module L = Logging; @@ -1190,27 +1192,30 @@ let process_summary filters formats_by_report_kind linereader stats top_proc_set let module AnalysisResults = { type t = list (string, Specs.summary); - let spec_files_from_cmdline () => { - /* Find spec files specified by command-line arguments. Not run at init time since the specs - files may be generated between init and report time. */ - IList.iter - ( - fun arg => - if (not (Filename.check_suffix arg Config.specs_files_suffix) && arg != ".") { - print_usage_exit ("file " ^ arg ^ ": arguments must be .specs files") - } - ) - Config.anon_args; - if Config.test_filtering { - Inferconfig.test (); - exit 0 - }; - if (Config.anon_args == []) { - load_specfiles () + let spec_files_from_cmdline () => + if (Config.current_exe == CLOpt.Print) { + /* Find spec files specified by command-line arguments. Not run at init time since the specs + files may be generated between init and report time. */ + IList.iter + ( + fun arg => + if (not (Filename.check_suffix arg Config.specs_files_suffix) && arg != ".") { + print_usage_exit ("file " ^ arg ^ ": arguments must be .specs files") + } + ) + Config.anon_args; + if Config.test_filtering { + Inferconfig.test (); + exit 0 + }; + if (Config.anon_args == []) { + load_specfiles () + } else { + List.rev Config.anon_args + } } else { - List.rev Config.anon_args - } - }; + load_specfiles () + }; /** apply [f] to [arg] with the gc compaction disabled during the execution */ let apply_without_gc f arg => {