From cde25c50a6cf29a41c3fb865446c144eadc1038c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 20 Dec 2022 16:08:49 -0600 Subject: [PATCH] refactor: move generate_sites_module to own module This stanza is guarded behind an extension Signed-off-by: Rudi Grinberg --- src/dune_rules/dir_contents.ml | 2 +- src/dune_rules/dune_file.ml | 31 ++----------------- src/dune_rules/dune_file.mli | 16 ---------- src/dune_rules/generate_sites_module_rules.ml | 2 +- .../generate_sites_module_rules.mli | 2 +- .../generate_sites_module_stanza.ml | 28 +++++++++++++++++ .../generate_sites_module_stanza.mli | 19 ++++++++++++ 7 files changed, 52 insertions(+), 48 deletions(-) create mode 100644 src/dune_rules/generate_sites_module_stanza.ml create mode 100644 src/dune_rules/generate_sites_module_stanza.mli diff --git a/src/dune_rules/dir_contents.ml b/src/dune_rules/dir_contents.ml index 40ffd898eda..137bd5b57b2 100644 --- a/src/dune_rules/dir_contents.ml +++ b/src/dune_rules/dir_contents.ml @@ -160,7 +160,7 @@ end = struct Simple_rules.copy_files sctx def ~src_dir ~dir ~expander in Path.Set.to_list_map ps ~f:Path.basename - | Generate_sites_module def -> + | Generate_sites_module_stanza.T def -> let+ res = Generate_sites_module_rules.setup_rules sctx ~dir def in [ res ] | Library { buildable; _ } | Executables { buildable; _ } -> diff --git a/src/dune_rules/dune_file.ml b/src/dune_rules/dune_file.ml index 5d06876424d..d248d4fa05f 100644 --- a/src/dune_rules/dune_file.ml +++ b/src/dune_rules/dune_file.ml @@ -2231,32 +2231,6 @@ module Deprecated_library_name = struct { Library_redirect.loc; project; old_name; new_public_name }) end -module Generate_sites_module = struct - type t = - { loc : Loc.t - ; module_ : Module_name.t - ; sourceroot : bool - ; relocatable : bool - ; sites : (Loc.t * Package.Name.t) list - ; plugins : (Loc.t * (Package.Name.t * (Loc.t * Section.Site.t))) list - } - - let decode = - fields - (let+ loc = loc - and+ module_ = field "module" Module_name.decode - and+ sourceroot = field_b "sourceroot" - and+ relocatable = field_b "relocatable" - and+ sites = - field "sites" ~default:[] (repeat (located Package.Name.decode)) - and+ plugins = - field "plugins" ~default:[] - (repeat - (located (pair Package.Name.decode (located Section.Site.decode)))) - in - { loc; module_; sourceroot; relocatable; sites; plugins }) -end - type Stanza.t += | Library of Library.t | Foreign_library of Foreign.Library.t @@ -2272,7 +2246,6 @@ type Stanza.t += | Library_redirect of Library_redirect.Local.t | Deprecated_library_name of Deprecated_library_name.t | Cram of Cram_stanza.t - | Generate_sites_module of Generate_sites_module.t | Plugin of Plugin.t module Stanzas = struct @@ -2384,8 +2357,8 @@ module Stanzas = struct [ Cram t ] ) ; ( "generate_sites_module" , let+ () = Dune_lang.Syntax.since Section.dune_site_syntax (0, 1) - and+ t = Generate_sites_module.decode in - [ Generate_sites_module t ] ) + and+ t = Generate_sites_module_stanza.decode in + [ Generate_sites_module_stanza.T t ] ) ; ( "plugin" , let+ () = Dune_lang.Syntax.since Section.dune_site_syntax (0, 1) and+ t = Plugin.decode in diff --git a/src/dune_rules/dune_file.mli b/src/dune_rules/dune_file.mli index 9ed679282f1..ced8e4c095e 100644 --- a/src/dune_rules/dune_file.mli +++ b/src/dune_rules/dune_file.mli @@ -450,21 +450,6 @@ module Deprecated_library_name : sig val old_public_name : t -> Lib_name.t end -(** Stanza which generate a module for getting information from dune *) -module Generate_sites_module : sig - type t = - { loc : Loc.t - ; module_ : Module_name.t (** name of the module to generate *) - ; sourceroot : bool (** should the sourceroot of the project be provided *) - ; relocatable : bool - (** should the fact that the installation use the relocatable mode *) - ; sites : (Loc.t * Package.Name.t) list - (** list of the sites whose location should be given *) - ; plugins : (Loc.t * (Package.Name.t * (Loc.t * Section.Site.t))) list - (** list of the sites for which a plugin system must be provided *) - } -end - type Stanza.t += | Library of Library.t | Foreign_library of Foreign.Library.t @@ -480,7 +465,6 @@ type Stanza.t += | Library_redirect of Library_redirect.Local.t | Deprecated_library_name of Deprecated_library_name.t | Cram of Cram_stanza.t - | Generate_sites_module of Generate_sites_module.t | Plugin of Plugin.t val stanza_package : Stanza.t -> Package.t option diff --git a/src/dune_rules/generate_sites_module_rules.ml b/src/dune_rules/generate_sites_module_rules.ml index b85e9284946..ed3f26bd139 100644 --- a/src/dune_rules/generate_sites_module_rules.ml +++ b/src/dune_rules/generate_sites_module_rules.ml @@ -120,7 +120,7 @@ let plugins_code packages buf pkg sites = pr buf " module %s : %s.S = %s.Make(struct let paths = Sites.%s end)" (String.capitalize site) plugins plugins site) -let setup_rules sctx ~dir (def : Dune_file.Generate_sites_module.t) = +let setup_rules sctx ~dir (def : Generate_sites_module_stanza.t) = let open Memo.O in let* packages = Only_packages.get () in let impl () = diff --git a/src/dune_rules/generate_sites_module_rules.mli b/src/dune_rules/generate_sites_module_rules.mli index d2c2bd3217e..c8724589fc2 100644 --- a/src/dune_rules/generate_sites_module_rules.mli +++ b/src/dune_rules/generate_sites_module_rules.mli @@ -6,5 +6,5 @@ open! Stdune val setup_rules : Super_context.t -> dir:Path.Build.t - -> Dune_file.Generate_sites_module.t + -> Generate_sites_module_stanza.t -> string Memo.t diff --git a/src/dune_rules/generate_sites_module_stanza.ml b/src/dune_rules/generate_sites_module_stanza.ml new file mode 100644 index 00000000000..0619df111fb --- /dev/null +++ b/src/dune_rules/generate_sites_module_stanza.ml @@ -0,0 +1,28 @@ +open Import + +type t = + { loc : Loc.t + ; module_ : Module_name.t + ; sourceroot : bool + ; relocatable : bool + ; sites : (Loc.t * Package.Name.t) list + ; plugins : (Loc.t * (Package.Name.t * (Loc.t * Section.Site.t))) list + } + +let decode = + let open Dune_sexp.Decoder in + fields + (let+ loc = loc + and+ module_ = field "module" Module_name.decode + and+ sourceroot = field_b "sourceroot" + and+ relocatable = field_b "relocatable" + and+ sites = + field "sites" ~default:[] (repeat (located Package.Name.decode)) + and+ plugins = + field "plugins" ~default:[] + (repeat + (located (pair Package.Name.decode (located Section.Site.decode)))) + in + { loc; module_; sourceroot; relocatable; sites; plugins }) + +type Stanza.t += T of t diff --git a/src/dune_rules/generate_sites_module_stanza.mli b/src/dune_rules/generate_sites_module_stanza.mli new file mode 100644 index 00000000000..5659af4fcd3 --- /dev/null +++ b/src/dune_rules/generate_sites_module_stanza.mli @@ -0,0 +1,19 @@ +open Import + +(** Stanza which generate a module for getting information from dune *) + +type t = + { loc : Loc.t + ; module_ : Module_name.t (** name of the module to generate *) + ; sourceroot : bool (** should the sourceroot of the project be provided *) + ; relocatable : bool + (** should the fact that the installation use the relocatable mode *) + ; sites : (Loc.t * Package.Name.t) list + (** list of the sites whose location should be given *) + ; plugins : (Loc.t * (Package.Name.t * (Loc.t * Section.Site.t))) list + (** list of the sites for which a plugin system must be provided *) + } + +val decode : t Dune_sexp.Decoder.t + +type Stanza.t += T of t