diff --git a/infer/lib/python/infer.py b/infer/lib/python/infer.py index c65a7838e..27c31ba73 100755 --- a/infer/lib/python/infer.py +++ b/infer/lib/python/infer.py @@ -78,8 +78,23 @@ def split_args_to_parse(): return (sys_argv[1:dd_index], cmd_raw) +class FailSilentlyArgumentParser(argparse.ArgumentParser): + '''We want to leave the handling of printing usage messages to the + OCaml code. To do so, swallow error messages from ArgumentParser + and exit with a special error code (101) that infer.ml looks for. + ''' + + def error(self, message): + utils.stderr(message) + utils.stderr('') + exit(22) # in sync with infer.ml + + def print_help(self, file=None): + exit(22) # in sync with infer.ml + + def create_argparser(parents=[]): - parser = argparse.ArgumentParser( + parser = FailSilentlyArgumentParser( parents=[analyze.infer_parser] + parents, add_help=False, formatter_class=argparse.RawDescriptionHelpFormatter, diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 95011fad6..8d31a4395 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -104,6 +104,9 @@ let () = ) in let pid = Unix.create_process args_py.(0) args_py Unix.stdin Unix.stdout Unix.stderr in let _, status = Unix.waitpid [] pid in + if status = Unix.WEXITED 22 then + (* swallow infer.py argument parsing error *) + Config.print_usage_exit (); (* collect crashcontext summaries *) let analysis_is_crashcontext = match Config.analyzer with | Some Crashcontext -> true