Skip to content

Commit a1014a9

Browse files
vassilmladenovmeta-codesync[bot]
authored andcommitted
fix handling of multifile tests in the ocaml version of get_package_for_file
Summary: Aligns the ocaml implementation of `get_package_for_file` with the rust version in package_info_impl.rs. The option `support_multifile_tests` is used to strip the enclosing file prefix in multifile tests, eg `test.php--foo.php` -> `foo.php` (relied upon for package matching in the test suite). Reviewed By: DavidSnider Differential Revision: D94274344 fbshipit-source-id: 3bac932ebf6dc64893637a9349ffe86bc5364e52
1 parent 1e2fac3 commit a1014a9

7 files changed

Lines changed: 22 additions & 5 deletions

File tree

hphp/hack/src/naming/naming.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ let fun_def_of_stmts ctx stmts : Nast.fun_def option =
335335
let fd_package =
336336
let pos_suffix = Relative_path.suffix (Pos.filename pos) in
337337
Package_info.get_package_for_file
338+
~support_multifile_tests:
339+
popt.ParserOptions.package_support_multifile_tests
338340
popt.ParserOptions.package_info
339341
pos_suffix
340342
|> Option.map ~f:(fun pkg ->

hphp/hack/src/package/package_info.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ let from_packages (packages : Package.t list) : t =
5757
in
5858
{ existing_packages; include_path_to_package_map }
5959

60-
let get_package_for_file (info : t) (path : string) : Package.t option =
60+
let get_package_for_file ~support_multifile_tests (info : t) (path : string) :
61+
Package.t option =
62+
let path =
63+
if support_multifile_tests then
64+
let re = Str.regexp "[^/]*--" in
65+
Str.replace_first re "" path
66+
else
67+
path
68+
in
6169
Option.map
6270
~f:snd
6371
(List.find

hphp/hack/src/package/package_info.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ val get_package : t -> string -> Package.t option
1717

1818
val package_exists : t -> string -> bool
1919

20-
val get_package_for_file : t -> string -> Package.t option
20+
val get_package_for_file :
21+
support_multifile_tests:bool -> t -> string -> Package.t option

hphp/hack/src/typing/typing_packages.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ let can_access_by_package_rules
129129
Some (Aast_defs.PackageOverride _) )
130130
when package_includes current_pkg target_pkg ->
131131
let target_package_before_override =
132+
let tcopt = Env.get_tcopt env in
132133
Option.map
133134
(Package_info.get_package_for_file
134-
(Env.get_tcopt env |> TypecheckerOptions.package_info)
135+
~support_multifile_tests:
136+
(TypecheckerOptions.package_support_multifile_tests tcopt)
137+
(TypecheckerOptions.package_info tcopt)
135138
(Relative_path.suffix target_file))
136139
~f:Package.get_package_name
137140
in

hphp/hack/src/typing/write_symbol_info/package_utils.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ let get_package ctx path text =
2424
let package_name =
2525
match
2626
Package_info.get_package_for_file
27+
~support_multifile_tests:
28+
(Provider_context.get_tcopt ctx
29+
|> TypecheckerOptions.package_support_multifile_tests)
2730
(Provider_context.get_package_info ctx)
2831
path
2932
with

hphp/hack/test/package/package_access_lint/lint_into_override_02.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: Lint[5655] This is a cross-boundary edge. Although the callee is already in the caller package pkg1 via __PackageOverride('pkg1'), cross-boundary edges contribute to the bloating of pkg1 and SHOULD BE REMOVED. Either move the callee into the caller's package via hg mv, use __RequirePackage (if the whole function should only be invoked from pkg1) or gate this reference via a package check (if this portion of the function is meant to be gated by an environment check). [1]
1+
warning: Lint[5655] This is a cross-boundary edge. Although the callee is already in the caller package pkg1 via __PackageOverride('pkg1'), cross-boundary edges contribute to the bloating of pkg1 and SHOULD BE REMOVED. Either move the callee into the caller's package via hg mv, use __RequirePackage (if the whole function should only be invoked from pkg2) or gate this reference via a package check (if this portion of the function is meant to be gated by an environment check). [1]
22

33
lint_into_override_02.php--bar.php:6:10
44
4 | class D2 {

hphp/hack/test/package/package_access_lint/lint_into_override_03.php.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: Lint[5655] This is a cross-boundary edge. Although the callee is already in the caller package pkg2 via __PackageOverride('pkg1'), cross-boundary edges contribute to the bloating of pkg1 and SHOULD BE REMOVED. Either move the callee into the caller's package via hg mv, use __RequirePackage (if the whole function should only be invoked from pkg1) or gate this reference via a package check (if this portion of the function is meant to be gated by an environment check). [1]
1+
warning: Lint[5655] This is a cross-boundary edge. Although the callee is already in the caller package pkg2 via __PackageOverride('pkg1'), cross-boundary edges contribute to the bloating of pkg1 and SHOULD BE REMOVED. Either move the callee into the caller's package via hg mv, use __RequirePackage (if the whole function should only be invoked from pkg3) or gate this reference via a package check (if this portion of the function is meant to be gated by an environment check). [1]
22

33
lint_into_override_03.php--warning_03b.php:6:10
44
4 | class D3 {

0 commit comments

Comments
 (0)