Move Resolved_forms to own module

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-11 17:24:48 +02:00
parent 266590452d
commit 6c6a5b7866
1 changed files with 40 additions and 37 deletions

View File

@ -569,27 +569,36 @@ module Action = struct
| Infer | Infer
| Alias | Alias
type resolved_forms = module Resolved_forms = struct
{ (* Failed resolutions *) type t =
mutable failures : fail list { (* Failed resolutions *)
; (* All "name" for %{lib:name:...}/%{lib-available:name} forms *) mutable failures : fail list
mutable lib_deps : Build.lib_deps ; (* All "name" for %{lib:name:...}/%{lib-available:name} forms *)
; (* Static deps from %{...} variables. For instance %{exe:...} *) mutable lib_deps : Build.lib_deps
mutable sdeps : Path.Set.t ; (* Static deps from %{...} variables. For instance %{exe:...} *)
; (* Dynamic deps from %{...} variables. For instance %{read:...} *) mutable sdeps : Path.Set.t
mutable ddeps : (unit, Value.t list) Build.t String.Map.t ; (* Dynamic deps from %{...} variables. For instance %{read:...} *)
} mutable ddeps : (unit, Value.t list) Build.t String.Map.t
}
let add_lib_dep acc lib kind = let empty () =
acc.lib_deps <- String.Map.add acc.lib_deps lib kind { failures = []
; lib_deps = String.Map.empty
; sdeps = Path.Set.empty
; ddeps = String.Map.empty
}
let add_fail acc fail = let add_lib_dep acc lib kind =
acc.failures <- fail :: acc.failures; acc.lib_deps <- String.Map.add acc.lib_deps lib kind
None
let add_ddep acc ~key dep = let add_fail acc fail =
acc.ddeps <- String.Map.add acc.ddeps key dep; acc.failures <- fail :: acc.failures;
None None
let add_ddep acc ~key dep =
acc.ddeps <- String.Map.add acc.ddeps key dep;
None
end
let path_exp path = [Value.Path path] let path_exp path = [Value.Path path]
let str_exp str = [Value.String str] let str_exp str = [Value.String str]
@ -612,13 +621,7 @@ module Action = struct
let expand_step1 sctx ~dir ~dep_kind ~scope ~targets_written_by_user let expand_step1 sctx ~dir ~dep_kind ~scope ~targets_written_by_user
~map_exe ~bindings t = ~map_exe ~bindings t =
let acc = let acc = Resolved_forms.empty () in
{ failures = []
; lib_deps = String.Map.empty
; sdeps = Path.Set.empty
; ddeps = String.Map.empty
}
in
let expand pform syntax_version = let expand pform syntax_version =
let loc = String_with_vars.Var.loc pform in let loc = String_with_vars.Var.loc pform in
let key = String_with_vars.Var.full_name pform in let key = String_with_vars.Var.full_name pform in
@ -647,26 +650,26 @@ module Action = struct
match Artifacts.binary (artifacts sctx) s with match Artifacts.binary (artifacts sctx) s with
| Ok path -> Some (path_exp path) | Ok path -> Some (path_exp path)
| Error e -> | Error e ->
add_fail acc Resolved_forms.add_fail acc
({ fail = fun () -> Action.Prog.Not_found.raise e }) ({ fail = fun () -> Action.Prog.Not_found.raise e })
end end
| Macro (Lib, s) -> begin | Macro (Lib, s) -> begin
let lib_dep, file = parse_lib_file ~loc s in let lib_dep, file = parse_lib_file ~loc s in
add_lib_dep acc lib_dep dep_kind; Resolved_forms.add_lib_dep acc lib_dep dep_kind;
match match
Artifacts.file_of_lib (artifacts sctx) ~loc ~lib:lib_dep ~file Artifacts.file_of_lib (artifacts sctx) ~loc ~lib:lib_dep ~file
with with
| Ok path -> Some (path_exp path) | Ok path -> Some (path_exp path)
| Error fail -> add_fail acc fail | Error fail -> Resolved_forms.add_fail acc fail
end end
| Macro (Libexec, s) -> begin | Macro (Libexec, s) -> begin
let sctx = host sctx in let sctx = host sctx in
let lib_dep, file = parse_lib_file ~loc s in let lib_dep, file = parse_lib_file ~loc s in
add_lib_dep acc lib_dep dep_kind; Resolved_forms.add_lib_dep acc lib_dep dep_kind;
match match
Artifacts.file_of_lib (artifacts sctx) ~loc ~lib:lib_dep ~file Artifacts.file_of_lib (artifacts sctx) ~loc ~lib:lib_dep ~file
with with
| Error fail -> add_fail acc fail | Error fail -> Resolved_forms.add_fail acc fail
| Ok path -> | Ok path ->
if not Sys.win32 || Filename.extension s = ".exe" then begin if not Sys.win32 || Filename.extension s = ".exe" then begin
Some (path_exp path) Some (path_exp path)
@ -679,12 +682,12 @@ module Action = struct
~else_:(Build.path path >>^ fun _ -> ~else_:(Build.path path >>^ fun _ ->
path_exp path) path_exp path)
in in
add_ddep acc ~key dep Resolved_forms.add_ddep acc ~key dep
end end
end end
| Macro (Lib_available, s) -> begin | Macro (Lib_available, s) -> begin
let lib = s in let lib = s in
add_lib_dep acc lib Optional; Resolved_forms.add_lib_dep acc lib Optional;
Some (str_exp (string_of_bool ( Some (str_exp (string_of_bool (
Lib.DB.available (Scope.libs scope) lib))) Lib.DB.available (Scope.libs scope) lib)))
end end
@ -697,9 +700,9 @@ module Action = struct
| None -> [Value.String ""] | None -> [Value.String ""]
| Some s -> [String s] | Some s -> [String s]
in in
add_ddep acc ~key x Resolved_forms.add_ddep acc ~key x
| None -> | None ->
add_fail acc { fail = fun () -> Resolved_forms.add_fail acc { fail = fun () ->
Loc.fail loc Loc.fail loc
"Package %S doesn't exist in the current project." s "Package %S doesn't exist in the current project." s
} }
@ -710,7 +713,7 @@ module Action = struct
Build.contents path Build.contents path
>>^ fun s -> [Value.String s] >>^ fun s -> [Value.String s]
in in
add_ddep acc ~key data Resolved_forms.add_ddep acc ~key data
end end
| Macro (Read_lines, s) -> begin | Macro (Read_lines, s) -> begin
let path = Path.relative dir s in let path = Path.relative dir s in
@ -718,7 +721,7 @@ module Action = struct
Build.lines_of path Build.lines_of path
>>^ Value.L.strings >>^ Value.L.strings
in in
add_ddep acc ~key data Resolved_forms.add_ddep acc ~key data
end end
| Macro (Read_strings, s) -> begin | Macro (Read_strings, s) -> begin
let path = Path.relative dir s in let path = Path.relative dir s in
@ -726,7 +729,7 @@ module Action = struct
Build.strings path Build.strings path
>>^ Value.L.strings >>^ Value.L.strings
in in
add_ddep acc ~key data Resolved_forms.add_ddep acc ~key data
end end
| Macro (Path_no_dep, s) -> Some [Value.Dir (Path.relative dir s)]) | Macro (Path_no_dep, s) -> Some [Value.Dir (Path.relative dir s)])
in in