[clang] Make capture with simple clang command be a method call

Reviewed By: jvillard

Differential Revision: D4795819

fbshipit-source-id: fdb68b7
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent 3ebf8c3277
commit f4bc0db2b4

@ -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

@ -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...@.";

@ -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])

@ -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

@ -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:_ = ()

@ -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

@ -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)

@ -9,4 +9,4 @@
open! IStd
let tests = OUnitTest.TestList []
let tests = [OUnitTest.TestList []]

Loading…
Cancel
Save