From: Richard W.M. Jones Date: Sat, 10 Mar 2012 12:08:07 +0000 (+0000) Subject: Allow get_dependencies to check dependencies of multiple variables. X-Git-Tag: 0.6~12 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=57d21a4a716b513d93790262db4a663c169814bd;p=whenjobs.git Allow get_dependencies to check dependencies of multiple variables. --- diff --git a/daemon/daemon.ml b/daemon/daemon.ml index 6e6a5fd..ed5e067 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -107,7 +107,7 @@ and proc_set_variable (name, value) = state := Whenstate.set_variable !state name value; (* Which jobs need to be re-evaluated? *) - let jobs = Whenstate.get_dependencies !state name in + let jobs = Whenstate.get_dependencies !state [name] in reevaluate_whenjobs jobs; `ok diff --git a/lib/whenstate.ml b/lib/whenstate.ml index e3aad07..2bb030d 100644 --- a/lib/whenstate.ml +++ b/lib/whenstate.ml @@ -123,8 +123,21 @@ let get_variable_names t = let nr_jobs t = List.length t.jobs -let get_dependencies t name = - let jobnames = try StringMap.find name t.dependencies with Not_found -> [] in +let get_dependencies t names = + (* Get all job names that depend on these variables. *) + let jobnames = + List.map ( + fun name -> + try StringMap.find name t.dependencies with Not_found -> [] + ) names in + + (* Flatten the list and remove duplicates. *) + let set = List.fold_left ( + fun set jn -> StringSet.add jn set + ) StringSet.empty (List.flatten jobnames) in + let jobnames = StringSet.elements set in + + (* Convert job names to jobs. *) List.map (fun jn -> try let j = StringMap.find jn t.jobmap in diff --git a/lib/whenstate.mli b/lib/whenstate.mli index 15df0c1..d9df5a9 100644 --- a/lib/whenstate.mli +++ b/lib/whenstate.mli @@ -73,8 +73,8 @@ val get_variable_names : t -> string list val nr_jobs : t -> int (** Returns the number of jobs in the state. *) -val get_dependencies : t -> string -> Whenexpr.job list -(** Return the jobs which depend on the named variable. *) +val get_dependencies : t -> string list -> Whenexpr.job list +(** Return the jobs which depend on the named variables. *) val get_whenjobs : t -> Whenexpr.job list val get_everyjobs : t -> Whenexpr.job list