Fix static dependencies

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-07 15:04:44 +07:00
parent 2a71439c3e
commit 972406a0dc
3 changed files with 103 additions and 93 deletions

View File

@ -845,94 +845,81 @@ module Action = struct
match targets_written_by_user with match targets_written_by_user with
| Infer -> Loc.fail loc "You cannot use %s with inferred rules." var | Infer -> Loc.fail loc "You cannot use %s with inferred rules." var
| Alias -> Loc.fail loc "You cannot use %s in aliases." var | Alias -> Loc.fail loc "You cannot use %s in aliases." var
| Static l -> Some (Value.L.paths l) | Static l -> Some (Value.L.dirs l) (* XXX hack to signal no dep *)
in in
let expand var syntax_version = let expand_form s var syntax_version =
let loc = String_with_vars.Var.loc var in let loc = String_with_vars.Var.loc var in
let key = String_with_vars.Var.full_name var in let key = String_with_vars.Var.full_name var in
match String_with_vars.Var.destruct var with begin match expand_form sctx ~syntax_version ~var with
| Single var_name -> | Some Var.Form.Exe -> Some (path_exp (map_exe (Path.relative dir s)))
begin match expand_var_no_root sctx ~syntax_version ~var with | Some Dep -> Some (path_exp (Path.relative dir s))
| None -> String.Map.find extra_vars key | Some Bin -> begin
| Some Targets -> targets loc var_name let sctx = host sctx in
| Some v -> match Artifacts.binary (artifacts sctx) s with
let exp = Var.Kind.to_value_no_deps_or_targets ~scope v in | Ok path -> Some (path_exp path)
Option.iter exp ~f:(fun v -> | Error e ->
acc.sdeps <- Path.Set.union add_fail acc ({ fail = fun () -> Action.Prog.Not_found.raise e })
(Path.Set.of_list (Value.L.deps_only v)) acc.sdeps);
exp
end end
| Pair (_, s)-> | Some Lib -> begin
begin match expand_form sctx ~syntax_version ~var with let lib_dep, file = parse_lib_file ~loc s in
| Some Var.Form.Exe -> Some (path_exp (map_exe (Path.relative dir s))) add_lib_dep acc lib_dep dep_kind;
| Some Dep -> Some (path_exp (Path.relative dir s)) match
| Some Bin -> begin Artifacts.file_of_lib (artifacts sctx) ~loc ~lib:lib_dep ~file
let sctx = host sctx in with
match Artifacts.binary (artifacts sctx) s with | Ok path -> Some (path_exp path)
| Ok path -> Some (path_exp path) | Error fail -> add_fail acc fail
| Error e -> end
add_fail acc ({ fail = fun () -> Action.Prog.Not_found.raise e }) | Some Libexec -> begin
end let sctx = host sctx in
| Some Lib -> 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;
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
| Ok path -> Some (path_exp path) | Ok path ->
| Error fail -> add_fail acc fail if not Sys.win32 || Filename.extension s = ".exe" then begin
end Some (path_exp path)
| Some Libexec -> begin end else begin
let sctx = host sctx in let path_exe = Path.extend_basename path ~suffix:".exe" in
let lib_dep, file = parse_lib_file ~loc s in let dep =
add_lib_dep acc lib_dep dep_kind; Build.if_file_exists path_exe
match ~then_:(Build.path path_exe >>^ fun _ -> path_exp path_exe)
Artifacts.file_of_lib (artifacts sctx) ~loc ~lib:lib_dep ~file ~else_:(Build.path path >>^ fun _ -> path_exp path)
with
| Error fail -> add_fail acc fail
| Ok path ->
if not Sys.win32 || Filename.extension s = ".exe" then begin
Some (path_exp path)
end else begin
let path_exe = Path.extend_basename path ~suffix:".exe" in
let dep =
Build.if_file_exists path_exe
~then_:(Build.path path_exe >>^ fun _ -> path_exp path_exe)
~else_:(Build.path path >>^ fun _ -> path_exp path)
in
add_ddep acc ~key dep
end
end
| Some Lib_available -> begin
let lib = s in
add_lib_dep acc lib Optional;
Some (str_exp (string_of_bool (
Lib.DB.available (Scope.libs scope) lib)))
end
| Some Version -> begin
match Package.Name.Map.find (Scope.project scope).packages
(Package.Name.of_string s) with
| Some p ->
let x =
Pkg_version.read sctx p >>^ function
| None -> [Value.String ""]
| Some s -> [String s]
in in
add_ddep acc ~key x add_ddep acc ~key dep
| None -> end
add_fail acc { fail = fun () -> end
Loc.fail loc "Package %S doesn't exist in the current project." s | Some Lib_available -> begin
} let lib = s in
end add_lib_dep acc lib Optional;
| Some Read -> begin Some (str_exp (string_of_bool (
let path = Path.relative dir s in Lib.DB.available (Scope.libs scope) lib)))
let data = end
Build.contents path | Some Version -> begin
>>^ fun s -> [Value.String s] match Package.Name.Map.find (Scope.project scope).packages
(Package.Name.of_string s) with
| Some p ->
let x =
Pkg_version.read sctx p >>^ function
| None -> [Value.String ""]
| Some s -> [String s]
in in
add_ddep acc ~key data add_ddep acc ~key x
end | None ->
| Some Read_lines -> begin add_fail acc { fail = fun () ->
Loc.fail loc "Package %S doesn't exist in the current project." s
}
end
| Some Read -> begin
let path = Path.relative dir s in
let data =
Build.contents path
>>^ fun s -> [Value.String s]
in
add_ddep acc ~key data
end
| Some Read_lines -> begin
let path = Path.relative dir s in let path = Path.relative dir s in
let data = let data =
Build.lines_of path Build.lines_of path
@ -940,18 +927,37 @@ module Action = struct
in in
add_ddep acc ~key data add_ddep acc ~key data
end end
| Some Read_strings -> begin | Some Read_strings -> begin
let path = Path.relative dir s in let path = Path.relative dir s in
let data = let data =
Build.strings path Build.strings path
>>^ Value.L.strings >>^ Value.L.strings
in in
add_ddep acc ~key data add_ddep acc ~key data
end
| Some Path_no_dep -> Some [Value.Dir (Path.relative dir s)]
| None ->
String_with_vars.Var.fail var ~f:(sprintf "Unknown form: %s")
end end
| Some Path_no_dep -> Some [Value.Dir (Path.relative dir s)]
| None ->
String_with_vars.Var.fail var ~f:(sprintf "Unknown form: %s")
end
in
let expand var syntax_version =
let loc = String_with_vars.Var.loc var in
let key = String_with_vars.Var.full_name var in
let res =
match String_with_vars.Var.destruct var with
| Single var_name ->
begin match expand_var_no_root sctx ~syntax_version ~var with
| None -> String.Map.find extra_vars key
| Some Targets -> targets loc var_name
| Some v -> Var.Kind.to_value_no_deps_or_targets v ~scope
end
| Pair (_, s) -> expand_form s var syntax_version
in
Option.iter res ~f:(fun v ->
acc.sdeps <- Path.Set.union
(Path.Set.of_list (Value.L.deps_only v)) acc.sdeps
);
res
in in
let t = U.partial_expand t ~dir ~map_exe ~f:expand in let t = U.partial_expand t ~dir ~map_exe ~f:expand in
(t, acc) (t, acc)

View File

@ -35,4 +35,6 @@ module L = struct
let strings = List.map ~f:(fun x -> String x) let strings = List.map ~f:(fun x -> String x)
let paths = List.map ~f:(fun x -> Path x) let paths = List.map ~f:(fun x -> Path x)
let dirs = List.map ~f:(fun x -> Dir x)
end end

View File

@ -16,6 +16,8 @@ module L : sig
val deps_only : t list -> Path.t list val deps_only : t list -> Path.t list
val dirs : Path.t list -> t list
val concat : t list -> dir:Path.t -> string val concat : t list -> dir:Path.t -> string
val to_strings : t list -> dir:Path.t -> string list val to_strings : t list -> dir:Path.t -> string list