This commit is contained in:
Jeremie Dimino 2018-03-15 19:56:03 +00:00 committed by Rudi Grinberg
parent 73873b31bc
commit a55cde2969
7 changed files with 35 additions and 32 deletions

View File

@ -192,11 +192,10 @@ module Rule = struct
; locks : Path.t list ; locks : Path.t list
; loc : Loc.t option ; loc : Loc.t option
; dir : Path.t ; dir : Path.t
; package : Package.Name.t option
} }
let make ?(sandbox=false) ?(mode=Jbuild.Rule.Mode.Not_a_rule_stanza) let make ?(sandbox=false) ?(mode=Jbuild.Rule.Mode.Not_a_rule_stanza)
~context ?(locks=[]) ?loc ?package build = ~context ?(locks=[]) ?loc build =
let targets = targets build in let targets = targets build in
let dir = let dir =
match targets with match targets with
@ -230,6 +229,5 @@ module Rule = struct
; locks ; locks
; loc ; loc
; dir ; dir
; package
} }
end end

View File

@ -20,7 +20,6 @@ module Rule : sig
; loc : Loc.t option ; loc : Loc.t option
; (** Directory where all the targets are produced *) ; (** Directory where all the targets are produced *)
dir : Path.t dir : Path.t
; package : Package.Name.t option
} }
val make val make
@ -29,7 +28,6 @@ module Rule : sig
-> context:Context.t option -> context:Context.t option
-> ?locks:Path.t list -> ?locks:Path.t list
-> ?loc:Loc.t -> ?loc:Loc.t
-> ?package:Package.Name.t
-> (unit, Action.t) Build.t -> (unit, Action.t) Build.t
-> t -> t
end end

View File

@ -161,7 +161,6 @@ module Internal_rule = struct
; loc : Loc.t option ; loc : Loc.t option
; dir : Path.t ; dir : Path.t
; mutable exec : Exec_status.t ; mutable exec : Exec_status.t
; package : Package.Name.t option
} }
let compare a b = Id.compare a.id b.id let compare a b = Id.compare a.id b.id
@ -354,6 +353,8 @@ type t =
; files_of : (Path.t, Files_of.t) Hashtbl.t ; files_of : (Path.t, Files_of.t) Hashtbl.t
; mutable prefix : (unit, unit) Build.t option ; mutable prefix : (unit, unit) Build.t option
; hook : hook -> unit ; hook : hook -> unit
; (* Package files are part of *)
packages : (Path.t, Package.Name.t) Hashtbl.t
} }
let string_of_paths set = let string_of_paths set =
@ -652,7 +653,6 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
; locks ; locks
; loc ; loc
; dir ; dir
; package
} = } =
pre_rule pre_rule
in in
@ -777,7 +777,6 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
; mode ; mode
; loc ; loc
; dir ; dir
; package
} }
in in
create_file_specs t target_specs rule ~copy_source create_file_specs t target_specs rule ~copy_source
@ -1150,6 +1149,7 @@ let create ~contexts ~file_tree ~hook =
let t = let t =
{ contexts { contexts
; files = Hashtbl.create 1024 ; files = Hashtbl.create 1024
; packages = Hashtbl.create 1024
; trace = Trace.load () ; trace = Trace.load ()
; local_mkdirs = Path.Local.Set.empty ; local_mkdirs = Path.Local.Set.empty
; dirs = Hashtbl.create 1024 ; dirs = Hashtbl.create 1024
@ -1390,30 +1390,33 @@ let build_rules ?recursive t ~request =
entry_point t ~f:(fun () -> entry_point t ~f:(fun () ->
build_rules_internal ?recursive t ~request) build_rules_internal ?recursive t ~request)
let set_package t file package =
Hashtbl.add t.packages file package
let package_deps t files = let package_deps t files =
let rules_seen = ref Id_set.empty in let rules_seen = ref Id_set.empty in
let packages = ref Package.Name.Set.empty in let packages = ref Package.Name.Set.empty in
let rec loop fn = let rec loop fn =
let dir = Path.parent fn in match Hashtbl.find t.packages fn with
if Path.is_in_build_dir dir then load_dir t ~dir; | Some p ->
match Hashtbl.find t.files fn with packages := Package.Name.Set.add !packages p
| None -> () | None ->
| Some (File_spec.T { rule = ir; _ }) -> let dir = Path.parent fn in
if not (Id_set.mem !rules_seen ir.id) then begin if Path.is_in_build_dir dir then load_dir t ~dir;
rules_seen := Id_set.add !rules_seen ir.id; match Hashtbl.find t.files fn with
let _, dyn_deps = | None -> ()
match ir.exec with | Some (File_spec.T { rule = ir; _ }) ->
| Running { rule_evaluation; _ } if not (Id_set.mem !rules_seen ir.id) then begin
| Evaluating_rule { rule_evaluation; _ } -> rules_seen := Id_set.add !rules_seen ir.id;
Option.value_exn (Fiber.Future.peek rule_evaluation) let _, dyn_deps =
| Not_started _ -> assert false match ir.exec with
in | Running { rule_evaluation; _ }
match ir.package with | Evaluating_rule { rule_evaluation; _ } ->
| None -> Option.value_exn (Fiber.Future.peek rule_evaluation)
| Not_started _ -> assert false
in
Pset.iter (Pset.union ir.static_deps dyn_deps) ~f:loop Pset.iter (Pset.union ir.static_deps dyn_deps) ~f:loop
| Some p -> end
packages := Package.Name.Set.add !packages p
end
in in
let open Build.O in let open Build.O in
Build.paths_for_rule files >>^ fun () -> Build.paths_for_rule files >>^ fun () ->

View File

@ -77,6 +77,9 @@ val on_load_dir : t -> dir:Path.t -> f:(unit -> unit) -> unit
(** Stamp file that depends on all files of [dir] with extension [ext]. *) (** Stamp file that depends on all files of [dir] with extension [ext]. *)
val stamp_file_for_files_of : t -> dir:Path.t -> ext:string -> Path.t val stamp_file_for_files_of : t -> dir:Path.t -> ext:string -> Path.t
(** Sets the package this file is part of *)
val set_package : t -> Path.t -> Package.Name.t -> unit
(** Scan the transitive dependencies of the following files and return (** Scan the transitive dependencies of the following files and return
set of packages these files are part of. Do not scan packages set of packages these files are part of. Do not scan packages
recursively. *) recursively. *)

View File

@ -203,9 +203,11 @@ module Gen(P : Install_params) = struct
let install_dir = Config.local_install_dir ~context:ctx.name in let install_dir = Config.local_install_dir ~context:ctx.name in
List.map entries ~f:(fun entry -> List.map entries ~f:(fun entry ->
let dst = let dst =
Path.append install_dir (Install.Entry.relative_installed_path entry ~package) Path.append install_dir
(Install.Entry.relative_installed_path entry ~package)
in in
SC.add_rule sctx (Build.symlink ~src:entry.src ~dst) ~package; Build_system.set_package (SC.build_system sctx) entry.src package;
SC.add_rule sctx (Build.symlink ~src:entry.src ~dst);
Install.Entry.set_src entry dst) Install.Entry.set_src entry dst)
let promote_install_file = let promote_install_file =

View File

@ -219,10 +219,10 @@ let create
let prefix_rules t prefix ~f = let prefix_rules t prefix ~f =
Build_system.prefix_rules t.build_system prefix ~f Build_system.prefix_rules t.build_system prefix ~f
let add_rule t ?sandbox ?mode ?locks ?loc ?package build = let add_rule t ?sandbox ?mode ?locks ?loc build =
let build = Build.O.(>>>) build t.chdir in let build = Build.O.(>>>) build t.chdir in
Build_system.add_rule t.build_system Build_system.add_rule t.build_system
(Build_interpret.Rule.make ?sandbox ?mode ?locks ?loc ?package (Build_interpret.Rule.make ?sandbox ?mode ?locks ?loc
~context:(Some t.context) build) ~context:(Some t.context) build)
let add_rule_get_targets t ?sandbox ?mode ?locks ?loc build = let add_rule_get_targets t ?sandbox ?mode ?locks ?loc build =

View File

@ -80,7 +80,6 @@ val add_rule
-> ?mode:Jbuild.Rule.Mode.t -> ?mode:Jbuild.Rule.Mode.t
-> ?locks:Path.t list -> ?locks:Path.t list
-> ?loc:Loc.t -> ?loc:Loc.t
-> ?package:Package.Name.t
-> (unit, Action.t) Build.t -> (unit, Action.t) Build.t
-> unit -> unit
val add_rule_get_targets val add_rule_get_targets