Skip to content

Commit

Permalink
[sys_unix] map out migration work
Browse files Browse the repository at this point in the history
Summary: Translate as much as possible `Sys` calls to `Stdlib.Sys` and failing that to explicit `Sys_unix` calls. This will make it easier to implement missing functionality in later diffs.

Reviewed By: martintrojer

Differential Revision:
D70619872

Privacy Context Container: L1208441

fbshipit-source-id: d2893265af7b86a2fe0871f39df8da84e6660664
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Mar 5, 2025
1 parent 360dbe1 commit b7078d2
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 38 deletions.
4 changes: 2 additions & 2 deletions infer/src/base/CommandLineOption.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let init_work_dir, is_originator =
| Some dir ->
(dir, false)
| None ->
let real_cwd = Utils.realpath (Sys.getcwd ()) in
let real_cwd = Utils.realpath (Stdlib.Sys.getcwd ()) in
IUnix.putenv ~key:infer_cwd_env_var ~data:real_cwd ;
(real_cwd, true)

Expand Down Expand Up @@ -1023,7 +1023,7 @@ let extra_env_args = ref []
let extend_env_args args = extra_env_args := List.rev_append args !extra_env_args
let parse_args ~usage initial_action ?initial_command args =
let exe_name = Sys.executable_name in
let exe_name = Stdlib.Sys.executable_name in
args_to_parse := Array.of_list (exe_name :: args) ;
arg_being_parsed := 0 ;
let curr_usage = select_parse_mode ~usage initial_action in
Expand Down
6 changes: 3 additions & 3 deletions infer/src/base/Config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ let clang_exe_aliases =


let exe_basename =
(* Sys.executable_name tries to do clever things which we must avoid, use argv[0] instead *)
(* Stdlib.Sys.executable_name tries to do clever things which we must avoid, use argv[0] instead *)
Filename.basename (Sys.get_argv ()).(0)


Expand All @@ -357,7 +357,7 @@ let initial_command =

let infer_binary =
(* Resolve symlinks to get to the real executable, which is located in [bin_dir]. *)
Utils.realpath Sys.executable_name
Utils.realpath Stdlib.Sys.executable_name


let bin_dir = Filename.dirname infer_binary
Expand Down Expand Up @@ -3748,7 +3748,7 @@ let inferconfig_dir =
let is_root = String.equal dir parent in
if is_root then None else find parent
in
find (Sys.getcwd ())
find (Stdlib.Sys.getcwd ())


let parse_inferconfig_path_arg () =
Expand Down
2 changes: 1 addition & 1 deletion infer/src/base/DBWriterProcess.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module ServerSocket = struct
function. *)
let in_results_dir ~f = Utils.do_in_dir ~dir:Config.toplevel_results_dir ~f

let socket_exists () = Sys.file_exists_exn socket_path
let socket_exists () = Sys_unix.file_exists_exn socket_path

(* Error recuperation is done by attempting this function at module initialization time, and
not using DbWriter at all in case it fails. See {!can_use_socket} below. *)
Expand Down
2 changes: 1 addition & 1 deletion infer/src/base/Database.ml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ let create_db location id =
(* load biabduction models *)
load_model_specs db id ;
SqliteUtils.db_close db ;
try Sys.rename temp_db_path final_db_path
try Stdlib.Sys.rename temp_db_path final_db_path
with Sys_error _ -> (* lost the race, doesn't matter *) ()


Expand Down
8 changes: 4 additions & 4 deletions infer/src/base/ResultsDir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end

let is_results_dir () =
let results_db_path = get_path CaptureDB in
let has_all_markers = Sys.is_file results_db_path = `Yes in
let has_all_markers = Sys_unix.is_file results_db_path = `Yes in
Result.ok_if_true has_all_markers ~error:(Printf.sprintf "'%s' not found" results_db_path)


Expand All @@ -82,7 +82,7 @@ let non_empty_directory_exists results_dir =
alone. This allows users to create a temporary directory for the infer results without infer
removing it to recreate it, which could be racy. *)
let safe_entries = ResultsDirEntryName.to_keep_before_new_capture ~results_dir in
Sys.is_directory results_dir = `Yes
Sys_unix.is_directory results_dir = `Yes
&& Iter.exists
(fun entry -> not (List.mem ~equal:String.equal safe_entries entry))
(Utils.iter_dir results_dir |> Iter.from_labelled_iter)
Expand All @@ -103,8 +103,8 @@ let remove_results_dir () =
let prepare_logging_and_db () =
L.setup_log_file () ;
PerfEvent.init () ;
if Sys.is_file (get_path AnalysisDB) <> `Yes then Database.create_db Primary AnalysisDatabase ;
if Sys.is_file (get_path CaptureDB) <> `Yes then Database.create_db Primary CaptureDatabase ;
if Sys_unix.is_file (get_path AnalysisDB) <> `Yes then Database.create_db Primary AnalysisDatabase ;
if Sys_unix.is_file (get_path CaptureDB) <> `Yes then Database.create_db Primary CaptureDatabase ;
Database.new_database_connections Primary


Expand Down
2 changes: 1 addition & 1 deletion infer/src/base/SourceFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ let recreate_hashed_buck_out_path_abs =
let buck_out_gen_abs = project_root_real ^/ Config.buck_out_gen in
let find_file path =
try
Sys.readdir buck_out_gen_abs
Stdlib.Sys.readdir buck_out_gen_abs
|> Array.find_map ~f:(fun entry ->
let root = buck_out_gen_abs ^/ entry in
let full_path = root ^/ path in
Expand Down
10 changes: 6 additions & 4 deletions infer/src/base/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let fold_file_tree ~init ~f_dir ~f_reg ~path =
| exception Caml_unix.Unix_error (ENOENT, _, _) ->
acc'
in
Sys.fold_dir ~init:acc ~f:(aux dir_path) dir_path
Sys_unix.fold_dir ~init:acc ~f:(aux dir_path) dir_path
in
traverse_dir_aux init path

Expand Down Expand Up @@ -169,7 +169,7 @@ let filename_to_relative ?(force_full_backtrack = false) ?(backtrack = 0) ~root
let directory_fold f init path =
let collect current_dir (accu, dirs) path =
let full_path = current_dir ^/ path in
match Sys.is_directory full_path with
match Sys_unix.is_directory full_path with
| `Yes ->
(accu, full_path :: dirs)
| _ ->
Expand All @@ -182,10 +182,12 @@ let directory_fold f init path =
| [] ->
accu
| d :: tl ->
let new_accu, new_dirs = Array.fold ~f:(collect d) ~init:(accu, tl) (Sys.readdir d) in
let new_accu, new_dirs =
Array.fold ~f:(collect d) ~init:(accu, tl) (Stdlib.Sys.readdir d)
in
loop new_accu new_dirs
in
match Sys.is_directory path with `Yes -> loop init [path] | _ -> f init path
match Sys_unix.is_directory path with `Yes -> loop init [path] | _ -> f init path


let directory_iter f path = directory_fold (fun () path -> f path) () path
Expand Down
2 changes: 1 addition & 1 deletion infer/src/infer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let print_scheduler () =
let print_cores_used () = L.environment_info "Cores used: %d@\n" Config.jobs

let log_environment_info () =
L.environment_info "CWD = %s@\n" (Sys.getcwd ()) ;
L.environment_info "CWD = %s@\n" (Stdlib.Sys.getcwd ()) ;
( match Config.inferconfig_file with
| Some file ->
L.environment_info "Read configuration in %s@\n" file
Expand Down
2 changes: 1 addition & 1 deletion infer/src/integration/BuckBuildReport.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ let expand_target ~root acc (target, target_path) =
acc )
in
let target_path = if Filename.is_absolute target_path then target_path else root ^/ target_path in
match Sys.is_directory target_path with
match Sys_unix.is_directory target_path with
| `Yes ->
expand_dir acc (target, target_path)
| _ when String.is_suffix target_path ~suffix:ResultsDirEntryName.infer_deps_file_name ->
Expand Down
4 changes: 2 additions & 2 deletions infer/src/integration/BxlCapture.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let traverse ~root visited acc target_path =
if Visited.mem visited real_path then acc
else (
Visited.add real_path visited ;
match Sys.is_directory target_path with
match Sys_unix.is_directory target_path with
| `Yes when ISys.file_exists (ResultsDirEntryName.get_path ~results_dir:target_path CaptureDB)
->
(* we found a capture DB so add this as a target line *)
Expand All @@ -39,7 +39,7 @@ let get_buck2_root_relative_changed_files () =
SourceFile.Set.fold
(fun file acc ->
let abs_file_path = SourceFile.to_abs_path file in
match Sys.file_exists abs_file_path with `Yes -> abs_file_path :: acc | _ -> acc )
match Sys_unix.file_exists abs_file_path with `Yes -> abs_file_path :: acc | _ -> acc )
files []
in
List.fold existing_absolute_paths ~init:[] ~f:(fun acc abs_file_path ->
Expand Down
8 changes: 4 additions & 4 deletions infer/src/integration/Erlang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ let save_beams_from_report ~project_root ~report beam_list_path =
in
let get_beams beams dir =
let ebin_dir = project_root ^/ dir ^/ "ebin" in
match Sys.is_directory ebin_dir with
match Sys_unix.is_directory ebin_dir with
| `Yes ->
let new_beams = Utils.find_files ~path:ebin_dir ~extension:".beam" in
Set.union beams (String.Set.of_list new_beams)
Expand All @@ -147,10 +147,10 @@ let save_beams_from_report ~project_root ~report beam_list_path =


let run_in_dir ~dir ~prog ~args =
let here = Sys.getcwd () in
Sys.chdir dir ;
let here = Stdlib.Sys.getcwd () in
Stdlib.Sys.chdir dir ;
let _ignore_err = Process.create_process_and_wait_with_output ~prog ~args ReadStderr in
Sys.chdir here
Stdlib.Sys.chdir here


let process_beams ~project_root beam_list_path =
Expand Down
2 changes: 1 addition & 1 deletion infer/src/integration/Javac.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let compile compiler build_prog build_args =
in
let cli_file_args = cli_args @ ["@" ^ args_file] in
let args = prog_args @ cli_file_args in
L.(debug Capture Quiet) "Current working directory: '%s'@." (Sys.getcwd ()) ;
L.(debug Capture Quiet) "Current working directory: '%s'@." (Stdlib.Sys.getcwd ()) ;
let verbose_out_file =
Filename.temp_file ~in_dir:(ResultsDir.get_path Temporary) "javac" ".out"
in
Expand Down
2 changes: 1 addition & 1 deletion infer/src/integration/Kotlinc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let compile prog args =
file
in
let args = cli_args @ ["@" ^ args_file] in
L.debug Capture Quiet "Current working directory: '%s'@." (Sys.getcwd ()) ;
L.debug Capture Quiet "Current working directory: '%s'@." (Stdlib.Sys.getcwd ()) ;
let run cmd =
let shell_cmd = List.map ~f:Escape.escape_shell cmd |> String.concat ~sep:" " in
L.debug Capture Quiet "Trying to execute: %s@." shell_cmd ;
Expand Down
2 changes: 1 addition & 1 deletion infer/src/integration/TextReport.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ let pp_source_context ~indent fmt
let source_name =
if Filename.is_absolute source_name then source_name else Config.project_root ^/ source_name
in
match Sys.is_file source_name with
match Sys_unix.is_file source_name with
| `No | `Unknown ->
()
| `Yes ->
Expand Down
6 changes: 0 additions & 6 deletions infer/src/istd/IStd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ module Filename = struct
include Filename_unix
end

(* we don't care about the _unix distinction *)
module Sys = struct
include Sys
include Sys_unix
end

(* easy access to sub-module *)
module DLS = struct
include Domain.DLS
Expand Down
2 changes: 1 addition & 1 deletion infer/src/istd/ISys.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
open! IStd

let file_exists ?follow_symlinks path =
match Sys.file_exists ?follow_symlinks path with `Yes -> true | `No | `Unknown -> false
match Sys_unix.file_exists ?follow_symlinks path with `Yes -> true | `No | `Unknown -> false
6 changes: 3 additions & 3 deletions infer/src/java/jClasspath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let read_package_declaration source_file =


let add_source_file =
let cwd = lazy (Sys.getcwd ()) in
let cwd = lazy (Stdlib.Sys.getcwd ()) in
let convert_to_absolute p =
if Filename.is_relative p then Filename.concat (Lazy.force cwd) p else p
in
Expand Down Expand Up @@ -95,7 +95,7 @@ let read_modules_1 path =
|> List.map ~f:Escape.escape_shell |> String.concat ~sep:" "
in
L.debug Capture Medium "reading Java modules with: %s@\n" jimage_cmd ;
let jimage_ret = Sys.command jimage_cmd in
let jimage_ret = Stdlib.Sys.command jimage_cmd in
let root_paths = ref [] in
if Int.equal jimage_ret 0 then
Utils.iter_dir temp_dir ~f:(fun path -> root_paths := path :: !root_paths)
Expand Down Expand Up @@ -202,7 +202,7 @@ let search_classes path =
let is_valid_source_file path =
( Filename.check_suffix path ".java"
|| (Config.kotlin_capture && Filename.check_suffix path Config.kotlin_source_extension) )
&& PolyVariantEqual.(Sys.is_file path <> `No)
&& PolyVariantEqual.(Sys_unix.is_file path <> `No)


let search_sources sources =
Expand Down
2 changes: 1 addition & 1 deletion infer/src/pulse/PulseDiagnostic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ let make_autofix {Location.file; line; col} candidates =
let open IOption.Let_syntax in
let* line_str =
let file_path = SourceFile.to_abs_path file in
match Sys.is_file file_path with
match Sys_unix.is_file file_path with
| `No | `Unknown ->
None
| `Yes ->
Expand Down

0 comments on commit b7078d2

Please sign in to comment.