Skip to content

Commit

Permalink
Merge pull request #3975 from bobot/rename_generate_module_stanza
Browse files Browse the repository at this point in the history
Rename `generate_module` into `generate_sites_module`
  • Loading branch information
bobot authored Nov 25, 2020
2 parents d336ddd + 25cce6e commit 51fc74e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
12 changes: 6 additions & 6 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1811,23 +1811,23 @@ present, and which libraries it will load.
- ``(optional)`` will not declare the plugin if the libraries are not available

The loading of the plugin is done using the facilities generated by
:ref:`generate_module`
:ref:`generate_sites_module`

.. _generate_module:
.. _generate_sites_module:

generate_module (since 2.8)
---------------------------
generate_sites_module (since 2.8)
---------------------------------

Dune proposes some facilities for dealing with :ref:`sites` in a program. The
``generate_module`` stanza will generate code for looking up the correct locations
``generate_sites_module`` stanza will generate code for looking up the correct locations
of the sites directories and for loading plugins. It works after installation
with or without the relocation mode, inside dune rules, when using dune exec.
For promotion it works only if the generated modules are only in the executable (or
library statically linked) promoted; generated modules in plugins will not work.

.. code:: lisp
(generate_module
(generate_sites_module
(module <name>)
<facilities>)
Expand Down
6 changes: 3 additions & 3 deletions doc/sites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Getting the locations of a site at runtime
------------------------------------------

The executable ``mygui`` will be able to get the locations of the ``themes``
site using the :ref:`generate module stanza<generate_module>`
site using the :ref:`generate sites module stanza<generate_sites_module>`

.. code:: scheme
Expand All @@ -82,7 +82,7 @@ site using the :ref:`generate module stanza<generate_module>`
(modules mygui mysites)
(libraries dune-site))
(generate_module
(generate_sites_module
(name mysites)
(sites mygui))
Expand Down Expand Up @@ -227,7 +227,7 @@ Main executable (C)
(name c_register)
(modules c_register))
(generate_module
(generate_sites_module
(module sites)
(plugins (c plugins)))
Expand Down
2 changes: 1 addition & 1 deletion otherlibs/site/src/plugins/plugins.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module type S = sig
(** The signature of the modules present in the module generated by the stanza
generate_module *)
generate_sites_module *)

val paths : string list

Expand Down
8 changes: 4 additions & 4 deletions otherlibs/site/test/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Test embedding of sites locations information
> (library
> (public_name a)
> (libraries dune-site))
> (generate_module (module sites) (sites a))
> (generate_sites_module (module sites) (sites a))
> EOF

$ cat >a/a.ml <<EOF
Expand All @@ -40,7 +40,7 @@ Test embedding of sites locations information
> (library
> (public_name b)
> (libraries c.register dune-site))
> (generate_module (module sites) (sites b))
> (generate_sites_module (module sites) (sites b))
> (plugin (name c-plugins-b) (libraries b) (site (c plugins)))
> (install (section (site (b data))) (files info.txt))
> EOF
Expand All @@ -65,7 +65,7 @@ Test embedding of sites locations information
> (public_name d)
> (libraries c.register dune-site non-existent-library)
> (optional))
> (generate_module (module sites) (sites d))
> (generate_sites_module (module sites) (sites d))
> (plugin (name c-plugins-d) (libraries d) (site (c plugins)) (optional))
> (install (section (site (d data))) (files info.txt))
> EOF
Expand Down Expand Up @@ -96,7 +96,7 @@ Test embedding of sites locations information
> (public_name c.register)
> (name c_register)
> (modules c_register))
> (generate_module (module sites) (sourceroot) (plugins (c plugins)))
> (generate_sites_module (module sites) (sourceroot) (plugins (c plugins)))
> (rule
> (targets out.log)
> (deps (package c))
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/dir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ end = struct
| Copy_files def ->
Simple_rules.copy_files sctx def ~src_dir ~dir ~expander
|> Path.Set.to_list |> List.map ~f:Path.basename
| Generate_module def ->
[ Generate_module_rules.setup_rules sctx ~dir def ]
| Generate_sites_module def ->
[ Generate_sites_module_rules.setup_rules sctx ~dir def ]
| Library { buildable; _ }
| Executables { buildable; _ } ->
(* Manually add files generated by the (select ...) dependencies *)
Expand Down
10 changes: 5 additions & 5 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ module Deprecated_library_name = struct
{ Library_redirect.loc; project; old_name; new_public_name })
end

module Generate_module = struct
module Generate_sites_module = struct
type t =
{ loc : Loc.t
; module_ : Module_name.t
Expand Down Expand Up @@ -2076,7 +2076,7 @@ type Stanza.t +=
| Library_redirect of Library_redirect.Local.t
| Deprecated_library_name of Deprecated_library_name.t
| Cram of Cram_stanza.t
| Generate_module of Generate_module.t
| Generate_sites_module of Generate_sites_module.t
| Plugin of Plugin.t

module Stanzas = struct
Expand Down Expand Up @@ -2179,10 +2179,10 @@ module Stanzas = struct
, let+ () = Dune_lang.Syntax.since Stanza.syntax (2, 7)
and+ t = Cram_stanza.decode in
[ Cram t ] )
; ( "generate_module"
; ( "generate_sites_module"
, let+ () = Dune_lang.Syntax.since Section.dune_site_syntax (0, 1)
and+ t = Generate_module.decode in
[ Generate_module t ] )
and+ t = Generate_sites_module.decode in
[ Generate_sites_module t ] )
; ( "plugin"
, let+ () = Dune_lang.Syntax.since Section.dune_site_syntax (0, 1)
and+ t = Plugin.decode in
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ module Deprecated_library_name : sig
end

(** Stanza which generate a module for getting information from dune *)
module Generate_module : sig
module Generate_sites_module : sig
type t =
{ loc : Loc.t
; module_ : Module_name.t (** name of the module to generate *)
Expand Down Expand Up @@ -419,7 +419,7 @@ type Stanza.t +=
| Library_redirect of Library_redirect.Local.t
| Deprecated_library_name of Deprecated_library_name.t
| Cram of Cram_stanza.t
| Generate_module of Generate_module.t
| Generate_sites_module of Generate_sites_module.t
| Plugin of Plugin.t

val stanza_package : Stanza.t -> Package.t option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let plugins_code sctx 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_module.t) =
let setup_rules sctx ~dir (def : Dune_file.Generate_sites_module.t) =
let buf = Buffer.create 1024 in
if def.sourceroot then sourceroot_code buf;
if def.relocatable then relocatable_code buf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ open! Stdune

(** create the rule and return the produced file *)
val setup_rules :
Super_context.t -> dir:Path.Build.t -> Dune_file.Generate_module.t -> string
Super_context.t
-> dir:Path.Build.t
-> Dune_file.Generate_sites_module.t
-> string

0 comments on commit 51fc74e

Please sign in to comment.