From d2ff52e17cb8a8ca36d83bcc37981ce0b7364e72 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 1 Apr 2016 07:43:53 -0700 Subject: [PATCH] Fix some issues with merging the capture from several buck targets. Reviewed By: jberdine Differential Revision: D3125949 fb-gh-sync-id: dd9e263 fbshipit-source-id: dd9e263 --- infer/src/backend/inferanalyze.ml | 4 ++-- infer/src/backend/mergeCapture.ml | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/infer/src/backend/inferanalyze.ml b/infer/src/backend/inferanalyze.ml index 6c1baea75..bd2949abe 100644 --- a/infer/src/backend/inferanalyze.ml +++ b/infer/src/backend/inferanalyze.ml @@ -240,8 +240,7 @@ let () = (* parse command-line arguments *) begin L.err "ERROR: results directory %s does not exist@.@." !Config.results_dir; print_usage_exit () - end ; - if !Config.merge then MergeCapture.merge_captured_targets () + end let analyze_exe_env exe_env = let init_time = Unix.gettimeofday () in @@ -374,6 +373,7 @@ let () = process_cluster_cmdline fname; finish_logging () | None -> + if !Config.merge then MergeCapture.merge_captured_targets (); let clusters = DB.find_source_dirs () in L.err "Found %d source files in %s@." (IList.length clusters) !Config.results_dir; diff --git a/infer/src/backend/mergeCapture.ml b/infer/src/backend/mergeCapture.ml index c8a987c99..612141a8e 100644 --- a/infer/src/backend/mergeCapture.ml +++ b/infer/src/backend/mergeCapture.ml @@ -16,7 +16,12 @@ module F = Format is used to determine whether a captured directory needs to be merged. *) let check_timestamp_of_symlinks = true -let buck_out () = Filename.concat (Filename.dirname !Config.results_dir) "buck-out" +let buck_out () = + match !Config.project_root with + | Some root -> + Filename.concat root "buck-out" + | None -> + Filename.concat (Filename.dirname !Config.results_dir) "buck-out" let infer_deps () = Filename.concat !Config.results_dir "infer-deps.txt" @@ -43,6 +48,12 @@ let empty_stats () = targets_merged = 0; } +let link_exists s = + try + let _ = Unix.lstat s in + true + with Unix.Unix_error _ -> false + (** Create symbolic links recursively from the destination to the source. Replicate the structure of the source directory in the destination, with files replaced by links to the source. *) @@ -61,14 +72,14 @@ let rec slink ~stats src dst = end else begin - if Sys.file_exists dst then Sys.remove dst; + if link_exists dst then Unix.unlink dst; Unix.symlink src dst; - (* Set the accessed and modified time of the new symlink to be slightly in the future. Due to + (* Set the accessed and modified time of the original file slightly in the past. Due to the coarse precision of the timestamps, it is possible for the source and destination of a link to have the same modification time. When this happens, the files will be considered to need re-analysis every time, indefinitely. *) - let near_future = Unix.gettimeofday () +. 1. in - Unix.utimes dst near_future near_future ; + let near_past = Unix.gettimeofday () -. 1. in + Unix.utimes src near_past near_past; stats.files_linked <- stats.files_linked + 1; end