Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move generate_sites_module to own module #6798

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dune_rules/dir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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; _ } ->
Expand Down
31 changes: 2 additions & 29 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions src/dune_rules/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/generate_sites_module_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/generate_sites_module_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions src/dune_rules/generate_sites_module_stanza.ml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions src/dune_rules/generate_sites_module_stanza.mli
Original file line number Diff line number Diff line change
@@ -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