[SourceFile] Move append_crc_cutoff to DB module

Reviewed By: jberdine

Differential Revision: D4843882

fbshipit-source-id: 9bca5f6
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent da0e0305f0
commit 3cdb0e04f5

@ -224,7 +224,7 @@ struct
(** Print an html link to the given line number of the current source file *)
let pp_line_link ?(with_name = false) ?(text = None) source path_to_root fmt linenum =
let fname = SourceFile.encoding source in
let fname = DB.source_file_encoding source in
let linenum_str = string_of_int linenum in
let name = "LINE" ^ linenum_str in
pp_link

@ -927,13 +927,13 @@ let module Procname = {
get_qual_name_str pname ^ "#" ^ c_method_kind_verbose_str objc_cpp.kind
| _ => to_unique_id pname
};
Escape.escape_filename @@ SourceFile.append_crc_cutoff proc_id
Escape.escape_filename @@ DB.append_crc_cutoff proc_id
};
let to_generic_filename pname => {
let proc_id =
get_qualifiers pname |> QualifiedCppName.strip_template_args |> QualifiedCppName.to_rev_list |>
String.concat sep::"#";
Escape.escape_filename @@ SourceFile.append_crc_cutoff proc_id
Escape.escape_filename @@ DB.append_crc_cutoff proc_id
};
let to_filename pname =>
switch pname {

@ -144,7 +144,7 @@ let skip_anonymous_class_renamings (diff: Differential.t) : Differential.t =
* 2) their weak hashes match
* 3) their anonymous procedure ids match
*)
let string_of_procedure_id issue = SourceFile.strip_crc issue.Jsonbug_t.procedure_id in
let string_of_procedure_id issue = DB.strip_crc issue.Jsonbug_t.procedure_id in
let extension fname = snd (Filename.split_extension fname) in
let cmp (i1:Jsonbug_t.jsonbug) (i2:Jsonbug_t.jsonbug) =
[%compare :

@ -152,7 +152,7 @@ let main makefile => {
Config.results_dir;
let is_java () =>
List.exists
f::(fun cl => SourceFile.string_crc_has_extension ext::"java" (DB.source_dir_to_string cl))
f::(fun cl => DB.string_crc_has_extension ext::"java" (DB.source_dir_to_string cl))
all_clusters;
if (Config.per_procedure_parallelism && not (is_java ())) {
/* Java uses ZipLib which is incompatible with forking */

@ -555,7 +555,7 @@ let pp_custom_of_report fmt report fields => {
| `Issue_field_line_offset =>
Format.fprintf fmt "%s%d" (comma_separator index) (issue.line - issue.procedure_start_line)
| `Issue_field_procedure_id_without_crc =>
Format.fprintf fmt "%s%s" (comma_separator index) (SourceFile.strip_crc issue.procedure_id)
Format.fprintf fmt "%s%s" (comma_separator index) (DB.strip_crc issue.procedure_id)
};
List.iteri f::pp_field fields;
Format.fprintf fmt "@."

@ -502,7 +502,7 @@ let write_html_proc source proof_cover table_nodes_at_linenum global_err_log pro
(** Create filename.ext.html. *)
let write_html_file linereader filename procs =
let fname_encoding = SourceFile.encoding filename in
let fname_encoding = DB.source_file_encoding filename in
let (fd, fmt) =
Io_infer.Html.create
(DB.Results_dir.Abs_source_dir filename)

@ -16,6 +16,49 @@ open! PVariant
module F = Format
module L = Logging
let cutoff_length = 100
let crc_token = '.'
let append_crc_cutoff ?(key="") name =
let name_up_to_cutoff =
if String.length name <= cutoff_length
then name
else String.sub name ~pos:0 ~len:cutoff_length in
let crc_str =
let name_for_crc = name ^ key in
Utils.string_crc_hex32 name_for_crc in
name_up_to_cutoff ^ Char.to_string crc_token ^ crc_str
(* Lengh of .crc part: 32 characters of digest, plus 1 character of crc_token *)
let dot_crc_len = 1 + 32
let strip_crc str =
Core.Std.String.slice str 0 (- dot_crc_len)
let string_crc_has_extension ~ext name_crc =
let name = strip_crc name_crc in
match Filename.split_extension name with
| (_, Some ext') -> String.equal ext ext'
| (_, None) -> false
let curr_source_file_encoding = `Enc_crc
(** string encoding of a source file (including path) as a single filename *)
let source_file_encoding source_file =
let source_file_s = SourceFile.to_string source_file in
match curr_source_file_encoding with
| `Enc_base ->
Filename.basename source_file_s
| `Enc_path_with_underscores ->
Escape.escape_path source_file_s
| `Enc_crc ->
let base = Filename.basename source_file_s in
let dir = Filename.dirname source_file_s in
append_crc_cutoff ~key:dir base
(** {2 Source Dirs} *)
(** source directory: the directory inside the results dir corresponding to a source file *)
@ -27,13 +70,13 @@ let source_dir_to_string source_dir = source_dir
(** get the path to an internal file with the given extention (.cfg, .cg, .tenv) *)
let source_dir_get_internal_file source_dir extension =
let source_dir_name =
SourceFile.append_crc_cutoff (Filename.chop_extension (Filename.basename source_dir)) in
append_crc_cutoff (Filename.chop_extension (Filename.basename source_dir)) in
let fname = source_dir_name ^ extension in
Filename.concat source_dir fname
(** get the source directory corresponding to a source file *)
let source_dir_from_source_file source_file =
Filename.concat Config.captured_dir (SourceFile.encoding source_file)
Filename.concat Config.captured_dir (source_file_encoding source_file)
(** Find the source directories in the results dir *)
let find_source_dirs () =

@ -71,6 +71,20 @@ module Results_dir : sig
val create_file : path_kind -> path -> Unix.File_descr.t
end
(** Append a crc to the string, using string_crc_hex32.
Cut the string if it exceeds the cutoff limit.
Use an optional key to compute the crc. *)
val append_crc_cutoff : ?key:string -> string -> string
(** Remove the crc from the string, and check if it has the given extension *)
val string_crc_has_extension : ext:string -> string -> bool
(** Strip any crc attached to any string generated by string_append_crc_cutoff *)
val strip_crc : string -> string
(** string encoding of a source file (including path) as a single filename *)
val source_file_encoding : SourceFile.t -> string
(** {2 Source Dirs} *)
(** source directory: the directory inside the results dir corresponding to a source file *)

@ -50,7 +50,6 @@ let from_abs_path fname =
| None -> Absolute fname_real (* fname_real is absolute already *)
)
let curr_encoding = `Enc_crc
let to_string fname =
match fname with
@ -76,49 +75,6 @@ let to_rel_path fname =
match fname with
| RelativeProjectRoot path -> path
| _ -> to_abs_path fname
let cutoff_length = 100
let crc_token = '.'
let append_crc_cutoff ?(key="") name =
let name_up_to_cutoff =
if String.length name <= cutoff_length
then name
else String.sub name ~pos:0 ~len:cutoff_length in
let crc_str =
let name_for_crc = name ^ key in
Utils.string_crc_hex32 name_for_crc in
name_up_to_cutoff ^ Char.to_string crc_token ^ crc_str
(* Lengh of .crc part: 32 characters of digest, plus 1 character of crc_token *)
let dot_crc_len = 1 + 32
let strip_crc str =
Core.Std.String.slice str 0 (- dot_crc_len)
let string_crc_has_extension ~ext name_crc =
let name = strip_crc name_crc in
match Filename.split_extension name with
| (_, Some ext') -> String.equal ext ext'
| (_, None) -> false
(** string encoding of a source file (including path) as a single filename *)
let encoding source_file =
let prefix = match source_file with
| RelativeProjectRoot _ -> "P"
| RelativeInferModel _ -> "MOD"
| Absolute _ -> "ABS" in
let source_file_s = to_string source_file in
match curr_encoding with
| `Enc_base ->
Filename.basename source_file_s
| `Enc_path_with_underscores ->
prefix ^ Escape.escape_path source_file_s
| `Enc_crc ->
let base = Filename.basename source_file_s in
let dir = prefix ^ Filename.dirname source_file_s in
append_crc_cutoff ~key:dir base
let empty = Absolute ""
let is_infer_model source_file = match source_file with

@ -22,11 +22,6 @@ module UNSAFE : sig
val from_string : string -> t
end
(** Append a crc to the string, using string_crc_hex32.
Cut the string if it exceeds the cutoff limit.
Use an optional key to compute the crc. *)
val append_crc_cutoff : ?key:string -> string -> string
(** Set of files read from --changed-files-index file, None if option not specified
NOTE: it may include extra source_files if --changed-files-index contains paths to
header files *)
@ -45,9 +40,6 @@ val from_abs_path : string -> t
project root *)
val create : string -> t
(** string encoding of a source file (including path) as a single filename *)
val encoding : t -> string
(** Returns true if the file is a C++ model *)
val is_cpp_model : t -> bool
@ -66,12 +58,6 @@ val of_header : t -> t option
(** pretty print t *)
val pp : Format.formatter -> t -> unit
(** Remove the crc from the string, and check if it has the given extension *)
val string_crc_has_extension : ext:string -> string -> bool
(** Strip any crc attached to any string generated by string_append_crc_cutoff *)
val strip_crc : string -> string
(** get the full path of a source file *)
val to_abs_path : t -> string

@ -35,7 +35,7 @@ let validate_decl_from_channel chan =>
let register_perf_stats_report source_file => {
let stats_dir = Filename.concat Config.results_dir Config.frontend_stats_dir_name;
let abbrev_source_file = SourceFile.encoding source_file;
let abbrev_source_file = DB.source_file_encoding source_file;
let stats_file = Config.perf_stats_prefix ^ "_" ^ abbrev_source_file ^ ".json";
Utils.create_dir Config.results_dir;
Utils.create_dir stats_dir;

@ -243,7 +243,7 @@ let context_with_ck_set context decl_list =
context
let store_issues source_file =
let abbrev_source_file = SourceFile.encoding source_file in
let abbrev_source_file = DB.source_file_encoding source_file in
let lint_issues_dir = Config.results_dir ^/ Config.lint_issues_dir_name in
Utils.create_dir lint_issues_dir;
let lint_issues_file =

@ -18,7 +18,7 @@ module L = Logging
let register_perf_stats_report source_file =
let stats_dir = Filename.concat Config.results_dir Config.frontend_stats_dir_name in
let abbrev_source_file = SourceFile.encoding source_file in
let abbrev_source_file = DB.source_file_encoding source_file in
let stats_file = Config.perf_stats_prefix ^ "_" ^ abbrev_source_file ^ ".json" in
Utils.create_dir Config.results_dir ;
Utils.create_dir stats_dir ;

Loading…
Cancel
Save