Fix issue with timestamps leading to files not analyzed in -reactive mode when the capture takes less than 1 second

Summary:
Fix an issue where, when `-reactive` mode is used, files captured in the first second are not considered modified, and are not analyzed. This happens because file timestamps are used, and the resolution is one second.
Change the front-ends to change the timestamp of the directory where artifacts are created, so that the timestamps are 1 second in the future.

Small reactive commands such as the following now analyze correctly:
  rm -rf infer-out && infer --reactive -- clang -c test.c

Reviewed By: jberdine

Differential Revision: D4050689

fbshipit-source-id: 6271860
master
Cristiano Calcagno 8 years ago committed by Facebook Github Bot
parent d7a0e706df
commit 1327de0321

@ -342,6 +342,13 @@ let file_was_updated_after_start fname =
(* since file doesn't exist, it wasn't modified *) (* since file doesn't exist, it wasn't modified *)
false false
(** Mark a file as updated by changing its timestamps to be one second in the future.
This guarantees that it appears updated after start. *)
let mark_file_updated fname =
let near_future = Unix.gettimeofday () +. 1. in
Unix.utimes fname near_future near_future
(** Returns true if the file is a C++ model *) (** Returns true if the file is a C++ model *)
let file_is_in_cpp_model file = let file_is_in_cpp_model file =
let normalized_file_dir = filename_to_absolute (Filename.dirname file) in let normalized_file_dir = filename_to_absolute (Filename.dirname file) in

@ -32,6 +32,10 @@ val file_remove : filename -> unit
(** Return the time when a file was last modified. The file must exist. *) (** Return the time when a file was last modified. The file must exist. *)
val file_modified_time : ?symlink:bool -> filename -> float val file_modified_time : ?symlink:bool -> filename -> float
(** Mark a file as updated by changing its timestamps to be one second in the future.
This guarantees that it appears updated after start. *)
val mark_file_updated : string -> unit
(** Return whether filename was updated after analysis started. File doesn't have to exist *) (** Return whether filename was updated after analysis started. File doesn't have to exist *)
val file_was_updated_after_start : filename -> bool val file_was_updated_after_start : filename -> bool

@ -69,4 +69,6 @@ let do_source_file translation_unit_context ast =
|| Config.testing_mode || Config.testing_mode
|| Config.frontend_tests then || Config.frontend_tests then
(Dotty.print_icfg_dotty source_file cfg; (Dotty.print_icfg_dotty source_file cfg;
Cg.save_call_graph_dotty source_file Specs.get_specs call_graph) Cg.save_call_graph_dotty source_file Specs.get_specs call_graph);
(* NOTE: nothing should be written to source_dir after this *)
DB.mark_file_updated (DB.source_dir_to_string source_dir)

@ -43,18 +43,18 @@ let init_global_state source_file =
let store_icfg source_file tenv cg cfg = let store_icfg source_file tenv cg cfg =
let source_dir = DB.source_dir_from_source_file source_file in let source_dir = DB.source_dir_from_source_file source_file in
begin let cfg_file = DB.source_dir_get_internal_file source_dir ".cfg" in
let cfg_file = DB.source_dir_get_internal_file source_dir ".cfg" in let cg_file = DB.source_dir_get_internal_file source_dir ".cg" in
let cg_file = DB.source_dir_get_internal_file source_dir ".cg" in if Config.create_harness then Harness.create_harness cfg cg tenv;
if Config.create_harness then Harness.create_harness cfg cg tenv; Cg.store_to_file cg_file cg;
Cg.store_to_file cg_file cg; Cfg.store_cfg_to_file ~source_file cfg_file cfg;
Cfg.store_cfg_to_file ~source_file cfg_file cfg; if Config.debug_mode || Config.frontend_tests then
if Config.debug_mode || Config.frontend_tests then begin
begin Dotty.print_icfg_dotty source_file cfg;
Dotty.print_icfg_dotty source_file cfg; Cg.save_call_graph_dotty source_file Specs.get_specs cg
Cg.save_call_graph_dotty source_file Specs.get_specs cg end;
end (* NOTE: nothing should be written to source_dir after this *)
end DB.mark_file_updated (DB.source_dir_to_string source_dir)
(* Given a source file, its code is translated, and the call-graph, control-flow-graph and type *) (* Given a source file, its code is translated, and the call-graph, control-flow-graph and type *)

Loading…
Cancel
Save