diff --git a/infer/src/Makefile b/infer/src/Makefile index ea76ece7b..d2ae966a0 100644 --- a/infer/src/Makefile +++ b/infer/src/Makefile @@ -168,7 +168,7 @@ ifeq ($(BUILD_C_ANALYZERS),yes) INFER_CONFIG_TARGETS += $(INFERCLANG_MAIN).native DEPENDENCIES += clang unit/clang else -DEPENDENCIES += unit/clang_stubs +DEPENDENCIES += clang_stubs unit/clang_stubs endif ifeq ($(TEST),1) INFER_CONFIG_TARGETS += $(INFERUNIT_MAIN).native diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 304f2a630..bbb3ead74 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -220,10 +220,10 @@ let capture = function L.stdout "Capturing for Buck genrule compatibility...@\n"; JMain.from_arguments path | Clang (compiler, prog, args) -> - L.stdout "Capturing in make/cc mode...@\n"; + L.stdout "Capturing in make/cc mode...@."; Clang.capture compiler ~prog ~args | ClangCompilationDB db_files -> - L.stdout "Capturing using compilation database...@\n"; + L.stdout "Capturing using compilation database...@."; capture_with_compilation_database db_files | Javac (compiler, prog, args) -> L.stdout "Capturing in javac mode...@."; diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 4e3a0f95b..5d7d12106 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -732,6 +732,7 @@ and ( debug, debug_exceptions, filtering, + frontend_tests, print_buckets, print_types, reports_include_ml_loc, @@ -756,8 +757,7 @@ and ( "Show the internal bucket of Infer reports in their textual description" and print_types = - CLOpt.mk_bool ~long:"print-types" - ~default:(equal_exe current_exe Clang) + CLOpt.mk_bool ~long:"print-types" ~default:false "Print types in symbolic heaps" and reports_include_ml_loc = @@ -797,11 +797,19 @@ and ( --reports-include-ml-loc)" [developer_mode; print_buckets; reports_include_ml_loc] [filtering] + + and frontend_tests = + CLOpt.mk_bool_group ~long:"frontend-tests" + ~parse_mode:CLOpt.(Infer [Clang]) + "Save filename.ext.test.dot with the cfg in dotty format for frontend tests (also sets \ + --print-types)" + [print_types] [] in ( developer_mode, debug, debug_exceptions, filtering, + frontend_tests, print_buckets, print_types, reports_include_ml_loc, @@ -939,11 +947,6 @@ and frontend_stats = 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 = - CLOpt.mk_bool ~long:"frontend-tests" - ~parse_mode:CLOpt.(Infer [Clang]) - "Save filename.ext.test.dot with the cfg in dotty format for frontend tests" - and generated_classes = CLOpt.mk_path_opt ~long:"generated-classes" ~parse_mode:CLOpt.(Infer [Java]) diff --git a/infer/src/clang/cFrontend_checkers_main.ml b/infer/src/clang/cFrontend_checkers_main.ml index df0c09da3..8a071823c 100644 --- a/infer/src/clang/cFrontend_checkers_main.ml +++ b/infer/src/clang/cFrontend_checkers_main.ml @@ -14,19 +14,19 @@ open Ctl_lexer let parse_al_file fname channel : CTL.al_file option = let print_position _ lexbuf = let pos = lexbuf.lex_curr_p in - Logging.err "%s:%d:%d" pos.pos_fname + Logging.stderr "%s:%d:%d" pos.pos_fname pos.pos_lnum (pos.pos_cnum - pos.pos_bol + 1) in let parse_with_error lexbuf = try Some (Ctl_parser.al_file token lexbuf) with | SyntaxError msg -> Logging.err "%a: %s\n" print_position lexbuf msg; None - | Ctl_parser.Error -> - Logging.err "\n#######################################################\ - \n\n%a: SYNTAX ERROR\n\ - \n########################################################\n@." + | Ctl_parser.Error as e -> + Logging.stderr "\n#######################################################\ + \n\n%a: SYNTAX ERROR\n\ + \n########################################################\n@." print_position lexbuf; - exit (-1) in + raise e in let lexbuf = Lexing.from_channel channel in lexbuf.lex_curr_p <- { lexbuf.lex_curr_p with pos_fname = fname }; parse_with_error lexbuf diff --git a/infer/src/clang_stubs/ClangWrapper.ml b/infer/src/clang_stubs/ClangWrapper.ml new file mode 100644 index 000000000..61a8714bb --- /dev/null +++ b/infer/src/clang_stubs/ClangWrapper.ml @@ -0,0 +1,9 @@ +(* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + *) +let exe ~prog:_ ~args:_ = () diff --git a/infer/src/clang_stubs/ClangWrapper.mli b/infer/src/clang_stubs/ClangWrapper.mli new file mode 100644 index 000000000..f2bad39d8 --- /dev/null +++ b/infer/src/clang_stubs/ClangWrapper.mli @@ -0,0 +1,11 @@ +(* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + *) +open! IStd + +val exe : prog:string -> args:string list -> unit diff --git a/infer/src/integration/Clang.ml b/infer/src/integration/Clang.ml index 8a08b141e..e12203eb6 100644 --- a/infer/src/integration/Clang.ml +++ b/infer/src/integration/Clang.ml @@ -29,21 +29,22 @@ let env_to_string ?exclude_var env = String.concat [elt; acc] ~sep:"\n" in Array.fold_right ~init:"" ~f:env_element_to_string env - -(* TODO(t16929015): make the clang/clang++ integration just a function call. *) -let capture _ ~prog ~args = - let path_var = "PATH" in - let new_path = Config.wrappers_dir ^ ":" ^ (Sys.getenv_exn path_var) in - let extended_env = `Extend [path_var, new_path] in - Logging.out "Running command %s with env:\n%s %s\n@." - prog - (env_to_string ~exclude_var:path_var (Unix.environment ())) - (extended_env_to_string extended_env); - Unix.fork_exec ~prog:prog ~args:(prog::args) ~env:extended_env () - |> Unix.waitpid - |> function - | Ok () -> () - | Error _ as status -> - failwithf "*** ERROR: capture command failed:@*** %s@*** %s@" - (String.concat ~sep:" " (prog::args)) - (Unix.Exit_or_signal.to_string_hum status) +let capture compiler ~prog ~args = + match compiler with + | Clang -> ClangWrapper.exe ~prog ~args + | Make -> + let path_var = "PATH" in + let new_path = Config.wrappers_dir ^ ":" ^ (Sys.getenv_exn path_var) in + let extended_env = `Extend [path_var, new_path] in + Logging.out "Running command %s with env:\n%s %s\n@." + prog + (env_to_string ~exclude_var:path_var (Unix.environment ())) + (extended_env_to_string extended_env); + Unix.fork_exec ~prog:prog ~args:(prog::args) ~env:extended_env () + |> Unix.waitpid + |> function + | Ok () -> () + | Error _ as status -> + failwithf "*** ERROR: capture command failed:@*** %s@*** %s@" + (String.concat ~sep:" " (prog::args)) + (Unix.Exit_or_signal.to_string_hum status) diff --git a/infer/src/unit/clang_stubs/ClangTests.ml b/infer/src/unit/clang_stubs/ClangTests.ml index bb0d878b5..26f1d6a2b 100644 --- a/infer/src/unit/clang_stubs/ClangTests.ml +++ b/infer/src/unit/clang_stubs/ClangTests.ml @@ -9,4 +9,4 @@ open! IStd -let tests = OUnitTest.TestList [] +let tests = [OUnitTest.TestList []]