Skip to content

Commit

Permalink
Remove SearchPath.normalize and SearchPath.create_normalized
Browse files Browse the repository at this point in the history
Reviewed By: stroxler

Differential Revision: D64569696

fbshipit-source-id: d15ea2c0d49ab89d076174c3111b18acd3712bc4
  • Loading branch information
grievejia authored and facebook-github-bot committed Oct 18, 2024
1 parent 4c10af6 commit 60b5c52
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 105 deletions.
2 changes: 1 addition & 1 deletion source/command/analyzeCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ module AnalyzeConfiguration = struct
?long_lived_workers
~local_root:(Option.value local_root ~default:global_root)
~project_root:global_root
~search_paths:(List.map search_paths ~f:SearchPath.normalize)
~search_paths
~taint_model_paths
~strict
~debug
Expand Down
2 changes: 1 addition & 1 deletion source/command/checkCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module CheckConfiguration = struct
?long_lived_workers
~local_root:(Option.value local_root ~default:global_root)
~project_root:global_root
~search_paths:(List.map search_paths ~f:SearchPath.normalize)
~search_paths
~strict
~debug
~show_error_traces
Expand Down
2 changes: 1 addition & 1 deletion source/command/codeNavigationCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module CodeNavigationConfiguration = struct
?long_lived_workers
~local_root:(Option.value local_root ~default:global_root)
~project_root:global_root
~search_paths:(List.map search_paths ~f:SearchPath.normalize)
~search_paths
~debug
~excludes
~extensions
Expand Down
2 changes: 1 addition & 1 deletion source/command/inferCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module InferConfiguration = struct
?long_lived_workers
~local_root:(Option.value local_root ~default:global_root)
~project_root:global_root
~search_paths:(List.map search_paths ~f:SearchPath.normalize)
~search_paths
~strict:false
~debug
~show_error_traces:false
Expand Down
2 changes: 1 addition & 1 deletion source/command/noDaemonQueryCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module QueryConfiguration = struct
?long_lived_workers
~local_root:(Option.value local_root ~default:global_root)
~project_root:global_root
~search_paths:(List.map search_paths ~f:SearchPath.normalize)
~search_paths
~debug
~excludes
~extensions
Expand Down
2 changes: 1 addition & 1 deletion source/command/serverCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ module ServerConfiguration = struct
?long_lived_workers
~local_root:(Option.value local_root ~default:global_root)
~project_root:global_root
~search_paths:(List.map search_paths ~f:SearchPath.normalize)
~search_paths
~taint_model_paths
~strict
~debug
Expand Down
19 changes: 0 additions & 19 deletions source/searchPath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,6 @@ let create serialized =
| _ -> failwith (Format.asprintf "Unable to create search path from %s" serialized)


let normalize = function
| Root root ->
Root (PyrePath.create_absolute ~follow_symbolic_links:false (PyrePath.absolute root))
| Subdirectory { root; subdirectory } ->
Subdirectory
{
root = PyrePath.create_absolute ~follow_symbolic_links:false (PyrePath.absolute root);
subdirectory;
}
| Submodule { root; submodule } ->
Submodule
{
root = PyrePath.create_absolute ~follow_symbolic_links:false (PyrePath.absolute root);
submodule;
}


let create_normalized serialized = create serialized |> normalize

let search_for_path ~search_paths analysis_path =
let raw_path = ArtifactPath.raw analysis_path in
let under_root search_path =
Expand Down
9 changes: 0 additions & 9 deletions source/searchPath.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,4 @@ val to_path : t -> PyrePath.t
side-effect. *)
val create : string -> t

(* Create a normalized search path from its string representation. Normalizing a path means to
expand its relativized root and follow symlinks. This operation DOES have filesystem
side-effect. *)
val create_normalized : string -> t

(* Turn a potentially un-normalized search path into a normalized one. This operation DOES have
filesystem side-effect.*)
val normalize : t -> t

val search_for_path : search_paths:t list -> ArtifactPath.t -> search_result option
71 changes: 0 additions & 71 deletions source/test/searchPathTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,76 +47,6 @@ let test_show_search_path _ =
()


let test_normalize context =
let good_root = bracket_tmpdir context in
let good_root_path = PyrePath.create_absolute good_root in
let bad_root_path =
PyrePath.create_relative ~root:good_root_path ~relative:"nonexist/directory"
in
let bad_root = PyrePath.absolute bad_root_path in
let good_subroot_path = PyrePath.create_relative ~root:good_root_path ~relative:"subroot" in
PyrePath.create_directory_recursively good_subroot_path |> Base.Result.ok_or_failwith;
let good_subroot = PyrePath.absolute good_subroot_path in
let create_input ?subdirectory ?submodule root =
let search_path =
match subdirectory, submodule with
| Some subdirectory, _ -> SearchPath.Subdirectory { root = !root; subdirectory }
| _, Some submodule -> SearchPath.Submodule { root = !root; submodule }
| _ -> SearchPath.Root !root
in
SearchPath.show search_path
in
let assert_success ~normalize ~expected input =
let create_search_path, create_type =
if normalize then
SearchPath.create_normalized, "normalized"
else
SearchPath.create, "non-normalized"
in
try
let _ = create_search_path input in
if not expected then
let message =
Format.sprintf
"Expect %s search path creation to succeed but it failed on input %s"
create_type
input
in
assert_failure message
with
| _ ->
if expected then
let message =
Format.sprintf
"Expect %s search path creation to fail but it succeeded on input %s"
create_type
input
in
assert_failure message
in

(* Non-normalized creation succeeds all the time. *)
assert_success ~normalize:false ~expected:true (create_input good_root);
assert_success ~normalize:false ~expected:true (create_input good_subroot);
assert_success ~normalize:false ~expected:true (create_input bad_root);
assert_success ~normalize:false ~expected:true (create_input ~subdirectory:"subroot" good_root);
assert_success ~normalize:false ~expected:true (create_input ~subdirectory:"nosubroot" good_root);
assert_success ~normalize:false ~expected:true (create_input ~subdirectory:"subroot" bad_root);
assert_success ~normalize:false ~expected:true (create_input ~submodule:"subroot" bad_root);

(* Normalized creation depends on filesystem state. *)
assert_success ~normalize:true ~expected:true (create_input good_root);
assert_success ~normalize:true ~expected:true (create_input good_subroot);
assert_success ~normalize:true ~expected:false (create_input bad_root);
assert_success ~normalize:true ~expected:true (create_input ~subdirectory:"subroot" good_root);
assert_success ~normalize:true ~expected:false (create_input ~subdirectory:"nosubroot" good_root);
assert_success ~normalize:true ~expected:false (create_input ~subdirectory:"subroot" bad_root);
assert_success ~normalize:true ~expected:true (create_input ~submodule:"subroot" good_root);
assert_success ~normalize:true ~expected:false (create_input ~submodule:"subroot" bad_root);

()


let test_search_for_path context =
let root = bracket_tmpdir context |> PyrePath.create_absolute in
let assert_path ~search_paths ~path ~expected =
Expand Down Expand Up @@ -157,7 +87,6 @@ let () =
>::: [
"create_search_path" >:: test_create_search_path;
"show_search_path" >:: test_show_search_path;
"normalize" >:: test_normalize;
"search_for_path" >:: test_search_for_path;
]
|> Test.run

0 comments on commit 60b5c52

Please sign in to comment.