Refactor directory traversal into its own utility function

Reviewed By: mbouaziz

Differential Revision: D6533384

fbshipit-source-id: 4d05b16
master
Martino Luca 7 years ago committed by Facebook Github Bot
parent f283416fa1
commit cd49acc1cf

@ -16,6 +16,24 @@ module L = Die
(** initial process times *)
let initial_times = Unix.times ()
(** recursively traverse a path for files ending with a given extension *)
let find_files ~path ~extension =
let rec traverse_dir_aux init dir_path =
let aux base_path files rel_path =
let full_path = base_path ^/ rel_path in
match (Unix.stat full_path).Unix.st_kind with
| Unix.S_REG when String.is_suffix ~suffix:extension full_path ->
full_path :: files
| Unix.S_DIR ->
traverse_dir_aux files full_path
| _ ->
files
in
Sys.fold_dir ~init ~f:(aux dir_path) dir_path
in
traverse_dir_aux [] path
(** read a source file and return a list of lines, or None in case of error *)
let read_file fname =
let res = ref [] in

@ -13,6 +13,9 @@ open! IStd
val initial_times : Unix.process_times
(** initial process times *)
val find_files : path:string -> extension:string -> string list
(** recursively traverse a path for files ending with a given extension *)
val string_crc_hex32 : string -> string
(** Compute a 32-character hexadecimal crc using the Digest module *)

@ -355,20 +355,9 @@ let store_issues source_file =
let find_linters_files () =
let rec find_aux init dir_path =
let aux base_path files rel_path =
let full_path = Filename.concat base_path rel_path in
match (Unix.stat full_path).Unix.st_kind with
| Unix.S_REG when String.is_suffix ~suffix:".al" full_path ->
full_path :: files
| Unix.S_DIR ->
find_aux files full_path
| _ ->
files
in
Sys.fold_dir ~init ~f:(aux dir_path) dir_path
in
List.concat (List.map ~f:(fun folder -> find_aux [] folder) Config.linters_def_folder)
List.concat_map
~f:(fun folder -> Utils.find_files ~path:folder ~extension:".al")
Config.linters_def_folder
let linters_files =
@ -410,4 +399,3 @@ let do_frontend_checks (trans_unit_ctx: CFrontend_config.translation_unit_contex
Tableaux.print_global_valuation_map ()) *)
| _ (* NOTE: Assumes that an AST always starts with a TranslationUnitDecl *) ->
assert false

Loading…
Cancel
Save