Permalink
Browse files

Add the ability to point the typechecker at additional directories

Summary:
The intent here is to point at dependencies that should not be
modified. As such:
- they are not watched for changes
- if there is a duplicate definition, the one from `extra_paths` takes
  precedence as 'correct', in the same way that builtin HHIs take
  precedence over both 'extra' and ones  in the root.

There are two primary use cases:
- allow fbcode projects such as opensource/shipit/ to use the HSL and other libraries (probably via third-party2) without copying into the tree
- docs.hhvm.com: to reduce the amount of out-of-date documentation, all examples are unit tests - both for the typechecker, and the runtime.
  When typechecked, they need to be copied into a separate directory with nothing else (to make sure they're self-contained examples) - however,
  they need something like this to have access to the HSL.

Reviewed By: kmeht

Differential Revision: D8106266
  • Loading branch information...
fredemmott committed May 24, 2018
1 parent e2d10a1 commit 1574fa14e907399c9d3085686533c3eb7109dcfc
Showing with 31 additions and 5 deletions.
  1. +11 −1 hphp/hack/src/server/serverConfig.ml
  2. +1 −0 hphp/hack/src/server/serverConfig.mli
  3. +19 −4 hphp/hack/src/server/serverInit.ml
@@ -39,6 +39,8 @@ type t = {
config_hash : string option;
(* A list of regexps for paths to ignore *)
ignored_paths : string list;
(* A list of extra paths to search for declarations *)
extra_paths : Path.t list;
}
let filename = Relative_path.from_root ".hhconfig"
@@ -155,7 +157,6 @@ let process_ignored_paths config =
SMap.get config "ignored_paths"
|> Option.value_map ~f:convert_ignored_paths ~default:[]
let maybe_relative_path fn =
(* Note: this is not the same as calling realpath; the cwd is not
* necessarily the same as hh_server's root!!! *)
@@ -165,6 +166,11 @@ let maybe_relative_path fn =
else fn
end
let process_extra_paths config =
match SMap.get config "extra_paths" with
| Some s -> Str.split config_list_regexp s |> List.map ~f:maybe_relative_path
| _ -> []
let extract_auto_namespace_element ns_map element =
match element with
| (source, Hh_json.JSON_String target) ->
@@ -195,6 +201,7 @@ let load config_filename options =
let local_config = ServerLocalConfig.load ~silent:false in
let version = SMap.get config "version" in
let ignored_paths = process_ignored_paths config in
let extra_paths = process_extra_paths config in
let load_script =
Option.map (SMap.get config "load_script") maybe_relative_path in
(* Since we use the unix alarm() for our timeouts, a timeout value of 0 means
@@ -236,6 +243,7 @@ let load config_filename options =
formatter_override = formatter_override;
config_hash = config_hash;
ignored_paths = ignored_paths;
extra_paths = extra_paths;
}, local_config
(* useful in testing code *)
@@ -251,6 +259,7 @@ let default_config = {
formatter_override = None;
config_hash = None;
ignored_paths = [];
extra_paths = [];
}
let set_parser_options config popt = { config with parser_options = popt }
@@ -263,3 +272,4 @@ let parser_options config = config.parser_options
let formatter_override config = config.formatter_override
let config_hash config = config.config_hash
let ignored_paths config = config.ignored_paths
let extra_paths config = config.extra_paths;
@@ -18,6 +18,7 @@ val is_compatible : t -> t -> bool
val default_config : t
val ignored_paths : t -> string list
val extra_paths : t -> Path.t list
val gc_control : t -> Gc.control
val sharedmem_config : t -> SharedMem.config
val state_prefetcher_script : t -> Path.t option
@@ -72,11 +72,26 @@ module ServerInitCommon = struct
(List.map ~f:(Relative_path.(create Hhi)))
(Find.make_next_files
~name:"hhi" ~filter:hhi_filter hhi_root) in
let rec concat_next_files l () =
begin match l with
| [] -> []
| hd::tl -> begin match hd () with
| [] -> concat_next_files tl ()
| x -> x
end
end
in
let extra_roots = ServerConfig.extra_paths genv.config in
let next_files_extra = List.map extra_roots
(fun root -> compose
(List.map ~f:Relative_path.create_detect_prefix)
(Find.make_next_files
~filter:ServerEnv.file_filter
root)
) |> concat_next_files
in
fun () ->
let next = match next_files_hhi () with
| [] -> next_files_root ()
| x -> x
in
let next = concat_next_files [next_files_hhi; next_files_extra; next_files_root] () in
Bucket.of_list next
let with_loader_timeout timeout stage f =

0 comments on commit 1574fa1

Please sign in to comment.