From 1b279f30bf8ec43b629a0b9ddc858f58b03d0374 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Thu, 1 Mar 2018 23:26:14 +0000 Subject: [PATCH] Make Merlin.t abstract --- src/gen_rules.ml | 41 ++++++++++++++--------------------------- src/merlin.ml | 19 +++++++++++++++++++ src/merlin.mli | 21 +++++++++++++-------- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 6354b110..17bf1383 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -721,14 +721,12 @@ module Gen(P : Install_rules.Params) = struct ; compile_info }; - { Merlin. - requires = real_requires - ; flags - ; preprocess = Buildable.single_preprocess lib.buildable - ; libname = Some lib.name - ; source_dirs = Path.Set.empty - ; objs_dirs = Path.Set.singleton obj_dir - } + Merlin.make () + ~requires:real_requires + ~flags + ~preprocess:(Buildable.single_preprocess lib.buildable) + ~libname:lib.name + ~objs_dirs:(Path.Set.singleton obj_dir) (* +-----------------------------------------------------------------+ | Executables stuff | @@ -819,14 +817,11 @@ module Gen(P : Install_rules.Params) = struct ~link_flags ~js_of_ocaml:exes.buildable.js_of_ocaml; - { Merlin. - requires = real_requires - ; flags = Ocaml_flags.common flags - ; preprocess = Buildable.single_preprocess exes.buildable - ; libname = None - ; source_dirs = Path.Set.empty - ; objs_dirs = Path.Set.singleton obj_dir - } + Merlin.make () + ~requires:real_requires + ~flags:(Ocaml_flags.common flags) + ~preprocess:(Buildable.single_preprocess exes.buildable) + ~objs_dirs:(Path.Set.singleton obj_dir) (* +-----------------------------------------------------------------+ | Aliases | @@ -892,19 +887,11 @@ module Gen(P : Install_rules.Params) = struct Path.parent (Path.relative src_dir src_glob ~error_loc:loc) in Some - { Merlin.requires = Build.return [] - ; flags = Build.return [] - ; preprocess = Jbuild.Preprocess.No_preprocessing - ; libname = None - ; source_dirs = Path.Set.singleton src_dir - ; objs_dirs = Path.Set.empty - } + (Merlin.make () + ~source_dirs:(Path.Set.singleton src_dir)) | _ -> None) |> Merlin.merge_all - |> Option.map ~f:(fun (m : Merlin.t) -> - { m with source_dirs = - Path.Set.add m.source_dirs (Path.relative src_dir ".") - }) + |> Option.map ~f:(fun m -> Merlin.add_source_dir m src_dir) |> Option.iter ~f:(Merlin.add_rules sctx ~dir:ctx_dir ~scope); Utop.setup sctx ~dir:ctx_dir ~libs:( List.filter_map stanzas ~f:(function diff --git a/src/merlin.ml b/src/merlin.ml index 62a302ab..39fcd84e 100644 --- a/src/merlin.ml +++ b/src/merlin.ml @@ -13,6 +13,25 @@ type t = ; objs_dirs : Path.Set.t } +let make + ?(requires=Build.return []) + ?(flags=Build.return []) + ?(preprocess=Jbuild.Preprocess.No_preprocessing) + ?libname + ?(source_dirs=Path.Set.empty) + ?(objs_dirs=Path.Set.empty) + () = + { requires + ; flags + ; preprocess + ; libname + ; source_dirs + ; objs_dirs + } + +let add_source_dir t dir = + { t with source_dirs = Path.Set.add t.source_dirs dir } + let ppx_flags sctx ~dir:_ ~scope ~src_dir:_ { preprocess; libname; _ } = match preprocess with | Pps { pps; flags } -> diff --git a/src/merlin.mli b/src/merlin.mli index 3460816a..9b552e26 100644 --- a/src/merlin.mli +++ b/src/merlin.mli @@ -1,13 +1,18 @@ (** Merlin rules *) -type t = - { requires : (unit, Lib.t list) Build.t - ; flags : (unit, string list) Build.t - ; preprocess : Jbuild.Preprocess.t - ; libname : string option - ; source_dirs: Path.Set.t - ; objs_dirs : Path.Set.t - } +type t + +val make + : ?requires:(unit, Lib.t list) Build.t + -> ?flags:(unit, string list) Build.t + -> ?preprocess:Jbuild.Preprocess.t + -> ?libname:string + -> ?source_dirs: Path.Set.t + -> ?objs_dirs:Path.Set.t + -> unit + -> t + +val add_source_dir : t -> Path.t -> t val merge_all : t list -> t option