From 6b4e7b31d88db48ee278f2f2de7304550c809e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Dimino?= Date: Sun, 26 Feb 2017 21:49:41 +0000 Subject: [PATCH] cleanup --- src/build_system.ml | 19 ++++++++++--------- src/build_system.mli | 6 +++++- src/context.ml | 10 +--------- src/context.mli | 3 --- src/main.ml | 2 +- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/build_system.ml b/src/build_system.ml index cf497e09..52866e70 100644 --- a/src/build_system.ml +++ b/src/build_system.ml @@ -56,7 +56,8 @@ end type t = { (* File specification by targets *) - files : (Path.t, File_spec.packed) Hashtbl.t + files : (Path.t, File_spec.packed) Hashtbl.t + ; contexts : Context.t list } let find_file_exn t file = @@ -257,7 +258,7 @@ let compile_rule t ~all_targets_by_dir ?(allow_override=false) pre_rule = create_file_specs t target_specs rule ~allow_override let setup_copy_rules t ~all_non_target_source_files ~all_targets_by_dir = - String_map.iter (Context.all ()) ~f:(fun ~key:_ ~data:(ctx : Context.t) -> + List.iter t.contexts ~f:(fun (ctx : Context.t) -> let ctx_dir = ctx.build_dir in Pset.iter all_non_target_source_files ~f:(fun path -> let ctx_path = Path.append ctx_dir path in @@ -277,7 +278,7 @@ let setup_copy_rules t ~all_non_target_source_files ~all_targets_by_dir = ~all_targets_by_dir ~allow_override:true)) -let create ~file_tree ~rules = +let create ~contexts ~file_tree ~rules = let all_source_files = File_tree.fold file_tree ~init:Pset.empty ~f:(fun dir acc -> let path = File_tree.Dir.path dir in @@ -288,10 +289,10 @@ let create ~file_tree ~rules = |> Pset.of_list)) in let all_copy_targets = - String_map.fold (Context.all ()) ~init:Pset.empty ~f:(fun ~key:_ ~data:(ctx : Context.t) acc -> - Pset.union acc (Pset.elements all_source_files - |> List.map ~f:(Path.append ctx.build_dir) - |> Pset.of_list)) + List.fold_left contexts ~init:Pset.empty ~f:(fun acc (ctx : Context.t) -> + Pset.union acc (Pset.elements all_source_files + |> List.map ~f:(Path.append ctx.build_dir) + |> Pset.of_list)) in let all_other_targets = List.fold_left rules ~init:Pset.empty ~f:(fun acc { Pre_rule.targets; _ } -> @@ -308,7 +309,7 @@ let create ~file_tree ~rules = |> Pmap.of_alist_multi |> Pmap.map ~f:Pset.of_list ) in - let t = { files = Hashtbl.create 1024 } in + let t = { files = Hashtbl.create 1024; contexts } in List.iter rules ~f:(compile_rule t ~all_targets_by_dir ~allow_override:false); setup_copy_rules t ~all_targets_by_dir ~all_non_target_source_files: @@ -335,7 +336,7 @@ let remove_old_artifacts t = if not keep then Path.rmdir dir; keep in - String_map.iter (Context.all ()) ~f:(fun ~key:_ ~data:(ctx : Context.t) -> + List.iter t.contexts ~f:(fun (ctx : Context.t) -> if Path.exists ctx.build_dir then ignore (walk ctx.build_dir : bool)) diff --git a/src/build_system.mli b/src/build_system.mli index 1728d7f2..b0d3bf4d 100644 --- a/src/build_system.mli +++ b/src/build_system.mli @@ -4,7 +4,11 @@ open! Import type t -val create : file_tree:File_tree.t -> rules:Build_interpret.Rule.t list -> t +val create + : contexts:Context.t list + -> file_tree:File_tree.t + -> rules:Build_interpret.Rule.t list + -> t val is_target : t -> Path.t -> bool diff --git a/src/context.ml b/src/context.ml index 40cbc94a..b2808b13 100644 --- a/src/context.ml +++ b/src/context.ml @@ -66,9 +66,6 @@ type t = let compare a b = compare a.name b.name -let all_known = ref String_map.empty -let all () = !all_known - let get_arch_sixtyfour stdlib_dir = let config_h = Path.relative stdlib_dir "caml/config.h" in List.exists (lines_of_file (Path.to_string config_h)) ~f:(fun line -> @@ -176,7 +173,7 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin = in let get_path var = Path.absolute (get var) in let stdlib_dir = get_path "standard_library" in - let t = + return { name ; kind ; merlin @@ -232,11 +229,6 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin = ; cmxs_magic_number = get "cmxs_magic_number" ; cmt_magic_number = get "cmt_magic_number" } - in - if String_map.mem name !all_known then - die "context %s already exists" name; - all_known := String_map.add !all_known ~key:name ~data:t; - return t let opam_config_var t var = opam_config_var ~env:t.env ~cache:t.opam_var_cache var diff --git a/src/context.mli b/src/context.mli index 7c2bd5fd..eb6e28c8 100644 --- a/src/context.mli +++ b/src/context.mli @@ -116,9 +116,6 @@ val create_for_opam val default : ?merlin:bool -> unit -> t Future.t -(** All contexts in use, by name *) -val all : unit -> t String_map.t - val which : t -> string -> Path.t option val extend_env : vars:string String_map.t -> env:string array -> string array diff --git a/src/main.ml b/src/main.ml index fa273b0a..1b83d5d4 100644 --- a/src/main.ml +++ b/src/main.ml @@ -34,7 +34,7 @@ let setup ?filter_out_optional_stanzas_with_missing_deps ?workspace () = Gen_rules.gen conf ~contexts ?filter_out_optional_stanzas_with_missing_deps >>= fun rules -> - let build_system = Build_system.create ~file_tree:conf.file_tree ~rules in + let build_system = Build_system.create ~contexts ~file_tree:conf.file_tree ~rules in return { build_system ; jbuilds = conf.jbuilds ; contexts