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

Add (:include <file>) terms to include_dir field #6058

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

gridbugs
Copy link
Collaborator

@gridbugs gridbugs commented Aug 9, 2022

Addresses #3993

Still need to add a version number check but opening this now to get preliminary feedback while I work out the best way to do that.

@gridbugs gridbugs force-pushed the include-in-include_dirs branch 2 times, most recently from 3fe0853 to 3cacf7f Compare August 9, 2022 14:23
@rgrinberg rgrinberg added this to the 3.5.0 milestone Aug 9, 2022
@@ -103,7 +104,12 @@ module Stubs = struct
let+ loc, lib_name = sum [ ("lib", located Lib_name.decode) ] in
Lib (loc, lib_name)
in
parse_lib <|> parse_dir
let include_ =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is introduced in 3.5, therefore it should only be available when 3.5 is enabled. See some example in dune_file.ml on how to do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct that if an older version is enabled, dune should behave as it did prior to this feature being added, and not explicitly raise an error indicating the minimum version supporting this feature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct. However, if previous versions would reject (:include ..) as an unexpected list, here we should hint to the user that this feature is available starting from 3.5.

@rgrinberg
Copy link
Member

Looks good in general. Design wise, one thing that bothers me is that we're enabling :include but not the whole ordered set language in this field. That is inconsistent with how dune works elsewhere. Can we try and support the full ordered set language here instead?

@gridbugs
Copy link
Collaborator Author

I totally agree with your point about inconsistency. I don't think there's a way to treat the entire (include_dirs ...) field as an ordered set because it currently allows terms of the form (lib <libname>) which isn't valid OSL syntax. An alternative would be to allow terms that introduce OSL expressions, e.g.:

(include_dirs (osl (:include foo)))

@gridbugs
Copy link
Collaborator Author

Also, my current implementation makes it an error if the file referred to by (:include ...) contains an OSL with 0 or >1 elements. It wouldn't be hard to support multiple directories referred to by a single (include ...)-ed file, but I'm not sure if that's ever something that will be useful in practice. @rgrinberg any thoughts on this?

@gridbugs gridbugs force-pushed the include-in-include_dirs branch from 3cacf7f to d885e22 Compare August 10, 2022 07:13
@rgrinberg
Copy link
Member

I totally agree with your point about inconsistency. I don't think there's a way to treat the entire (include_dirs ...) field as an ordered set because it currently allows terms of the form (lib ) which isn't valid OSL syntax. An alternative would be to allow terms that introduce OSL expressions, e.g.:

It should still be possible to support. We can instantiate ordered set lang with other ast elements. In this case, it would be with this type:

    type t =
      | Dir of String_with_vars.t
      | Lib of Loc.t * Lib_name.t

You might need to duplicate some stuff from Ordered_set_lang.Unexpanded.t because our stuff isn't well factored, but it should still be doable.

@rgrinberg
Copy link
Member

Also, my current implementation makes it an error if the file referred to by (:include ...) contains an OSL with 0 or >1 elements. It wouldn't be hard to support multiple directories referred to by a single (include ...)-ed file, but I'm not sure if that's ever something that will be useful in practice. @rgrinberg any thoughts on this?

It's not particularly useful, but it does make it consistent with other uses of (:include ..) so I think it's worth doing.

@gridbugs gridbugs force-pushed the include-in-include_dirs branch from e15d157 to 2e81e33 Compare August 11, 2022 07:44
@gridbugs
Copy link
Collaborator Author

@rgrinberg based on our discussion I've redesigned this change so that the include_dirs field can contain an arbitrary ordered set of Include_dir.ts. I factored out the common logic in Ordered_set_lang.Unexpanded into a functor. I still need to make behaviour fall back to pre-3.5 when the version is <3.5 but updating the PR for early feedback.

@@ -213,23 +215,99 @@ let field ?check name =
in
Dune_lang.Decoder.field name decode ~default:standard

module Unexpanded = struct
type ast = (String_with_vars.t, Ast.unexpanded) Ast.t
module type Element_intf = sig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our convention, the _intf suffix is reserved for .ml only modules that contain module singatures (whenever we don't want to duplicate the signature in the mli). Module types never have this suffix so this should be called Element.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Therefore, if if you prefer, you can move Ordered_set_lang.Element to Ordered_set_lang_intf.Element to avoid writing the module signature twice.

val eval : t -> Include_dir.t list

module Unexpanded : sig
type expanded = t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be type expanded := t and you can remove the destructive substitution in the end.

@@ -92,5 +92,33 @@ module Unexpanded : sig
end
with type expanded := t

module Include_dirs : sig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion is more subjective so feel free to ignore/delay it:

It's a little weird that a general purpose thing such as Ordered_set_lang should depend on Include_dir. Therefore, I would expect Include_dirs to live in a separate module, or at least as a submodule of Include_dir.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in principle, but making that change would require exposing more of the inner working of Ordered_set_lang to the outside world, and that feels like a bigger change.

@rgrinberg
Copy link
Member

The PR looks good. I left some minor comments that should be trivial to address. Before we merge this PR, you should also:

  • Update the change log at CHANGES.md
  • Update the manual.

@gridbugs gridbugs force-pushed the include-in-include_dirs branch 2 times, most recently from 639c011 to 72d79ac Compare August 15, 2022 06:04
@gridbugs gridbugs force-pushed the include-in-include_dirs branch from 2f6b193 to 4eac985 Compare August 16, 2022 01:00
@@ -92,6 +92,7 @@ module Stubs = struct
type t =
| Dir of String_with_vars.t
| Lib of Loc.t * Lib_name.t
| Include of Loc.t * Ordered_set_lang.Unexpanded.t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, (include ..) is allowed to expanded into OSL, right? That seems counterintuitive to me because OSL isn't accepted in the field when it is statically interpreted. Furthermore, the following isn't allowed either:

$ cat foo
  (baz (lib foo))
$ cat >dune << EOF
> ..
> (include_dirs (include foo))
> EOF

Which I would expect to be allowed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think it was a mistake to use OSL for this feature. I'll change so that the file specified to (include ...) can contain a sexp in the same notation as the (include_dirs ...) field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed. It was a nice idea, but it doesn't seem to work out in practice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this PR such that now the contents of the included file is parsed using the (include_dir ...) parser

@gridbugs gridbugs force-pushed the include-in-include_dirs branch 2 times, most recently from 1bb093e to a720095 Compare August 18, 2022 01:08
Comment on lines 125 to 127
Warning: (include ...) in include_dirs field is only available since version
3.5 of the dune language. Please update your dune-project file to have (lang
dune 3.5).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Warning: (include ...) in include_dirs field is only available since version
3.5 of the dune language. Please update your dune-project file to have (lang
dune 3.5).
Warning: (include ...) in ``include_dirs`` field is only available since version
3.5 of the Dune language. Please update your ``dune-project`` file to have (lang
dune 3.5).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've quoted "include_dirs". The rest of the suggested changes here are in text generated by Syntax.Error_msg.since.

@gridbugs gridbugs force-pushed the include-in-include_dirs branch from a720095 to 3ebe7da Compare August 22, 2022 07:03
@gridbugs gridbugs force-pushed the include-in-include_dirs branch from 3ebe7da to 390c373 Compare August 22, 2022 07:05
@rgrinberg
Copy link
Member

CI says we need a promotion here.

@gridbugs gridbugs force-pushed the include-in-include_dirs branch from 390c373 to 1132662 Compare August 23, 2022 07:47
@gridbugs
Copy link
Collaborator Author

I forgot to update a test when I changed an error message. That's fixed now, and I've also split the tests into multiple files with one file per test case.

@rgrinberg rgrinberg linked an issue Aug 23, 2022 that may be closed by this pull request
extract [args_of_include_dir]

Signed-off-by: Stephen Sherratt <[email protected]>
Add [(include <file>)] terms to [include_dirs] field

Signed-off-by: Stephen Sherratt <[email protected]>
@rgrinberg rgrinberg force-pushed the include-in-include_dirs branch from 1132662 to 3754214 Compare August 23, 2022 15:06
@rgrinberg
Copy link
Member

Looks good. I merged with a few tweaks.

@rgrinberg rgrinberg merged commit 48793f2 into ocaml:main Aug 23, 2022
emillon added a commit to emillon/opam-repository that referenced this pull request Oct 11, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.5.0~alpha1)

CHANGES:

- Sandbox running cinaps actions starting from cinaps 1.1 (ocaml/dune#6176, @rgrinberg)

- Add a `runtime_deps` field in the `cinaps` stanza to specify runtime
  dependencies for running the cinaps preprocessing action (ocaml/dune#6175, @rgrinberg)

- Shadow alias module `Foo__` when building a library `Foo` (ocaml/dune#6126, @rgrinberg)

- Extend dune describe to include the root path of the workspace and the
  relative path to the build directory. (ocaml/dune#6136, @reubenrowe)

- Allow dune describe workspace to accept directories as arguments.
  The provided directories restrict the worskpace description to those
  directories. (ocaml/dune#6107, fixes ocaml/dune#3893, @esope)

- Add a terminal persistence mode that attempts to clear the terminal history.
  It is enabled by setting terminal persistence to
  `clear-on-rebuild-and-flush-history` (ocaml/dune#6065, @rgrinberg)

- Disallow generating targets in sub direcories in inferred rules. The check to
  forbid this was accidentally done only for manually specified targets (ocaml/dune#6031,
  @rgrinberg)

- Do not ignore rules marked `(promote (until-clean))` when
  `--ignore-promoted-rules` (or `-p`) is passed. (ocaml/dune#6010, fixes ocaml/dune#4401, @emillon)

- Dune no longer considers .aux files as targets during Coq compilation. This
  means that .aux files are no longer cached. (ocaml/dune#6024, fixes ocaml/dune#6004, @Alizter)

- Cinaps actions are now sandboxed by default (ocaml/dune#6062, @rgrinberg)

- Allow rules producing directory targets to be not sandboxed (ocaml/dune#6056,
  @rgrinberg)

- Introduce a `dirs` field in the `install` stanza to install entire
  directories (ocaml/dune#5097, fixes ocaml/dune#5059, @rgrinberg)

- Menhir rules are now sandboxed by default (ocaml/dune#6076, @rgrinberg)

- Allow rules producing directory targets to create symlinks (ocaml/dune#6077, fixes
  ocaml/dune#5945, @rgrinberg)

- Inline tests are now sandboxed by default (ocaml/dune#6079, @rgrinberg)

- Fix build-info version when used with flambda (ocaml/dune#6089, fixes ocaml/dune#6075, @jberdine)

- Add an `(include <file>)` term to the `include_dirs` field for adding
  directories to the include paths sourced from a file. (ocaml/dune#6058, fixes ocaml/dune#3993,
  @gridbugs)

- Support `(extra_objects ...)` field in `(executable ...)` and `(library
  ...)` stanzas (ocaml/dune#6084, fixes ocaml/dune#4129, @gridbugs)

- Fix compilation of Dune under esy on Windows (ocaml/dune#6109, fixes ocaml/dune#6098, @nojb)

- Improve error message when parsing several licenses in `(license)` (ocaml/dune#6114,
  fixes ocaml/dune#6103, @emillon)

- odoc rules now about `ODOC_SYNTAX` and will rerun accordingly (ocaml/dune#6010, fixes
  ocaml/dune#1117, @emillon)

- dune install: copy files in an atomic way (ocaml/dune#6150, @emillon)

- Add `%{coq:...}` macro for accessing data about the configuration about Coq.
  For instance `%{coq:version}` (ocaml/dune#6049, @Alizter)

- update vendored copy of cmdliner to 1.1.1. This improves the built-in
  documentation for command groups such as `dune ocaml`. (ocaml/dune#6038, @emillon,
  ocaml/dune#6169, @shonfeder)

- The test suite for Coq now requires Coq >= 8.16 due to changes in the
  plugin loading mechanism upstream (which now uses findlib).

- Starting with Coq build language 0.6, theories can be built without importing
  Coq's standard library by including `(stdlib no)`.
  (ocaml/dune#6165 ocaml/dune#6164, fixes ocaml/dune#6163, @ejgallego @Alizter @LasseBlaauwbroek)

- on macOS, sign executables produced by artifact substitution (ocaml/dune#6137, fixes
  ocaml/dune#5650, @emillon)

- Added an (aliases ...) field to the (rules ...) stanza which allows the
  specification of multiple aliases per rule (ocaml/dune#6194, @Alizter)
emillon added a commit to emillon/opam-repository that referenced this pull request Oct 19, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.5.0)

CHANGES:

- macOS: Handle unknown fsevents without crashing (ocaml/dune#6217, @rgrinberg)

- Enable file watching on MacOS SDK < 10.13. (ocaml/dune#6218, @rgrinberg)

- Sandbox running cinaps actions starting from cinaps 1.1 (ocaml/dune#6176, @rgrinberg)

- Add a `runtime_deps` field in the `cinaps` stanza to specify runtime
  dependencies for running the cinaps preprocessing action (ocaml/dune#6175, @rgrinberg)

- Shadow alias module `Foo__` when building a library `Foo` (ocaml/dune#6126, @rgrinberg)

- Extend dune describe to include the root path of the workspace and the
  relative path to the build directory. (ocaml/dune#6136, @reubenrowe)

- Allow dune describe workspace to accept directories as arguments.
  The provided directories restrict the worskpace description to those
  directories. (ocaml/dune#6107, fixes ocaml/dune#3893, @esope)

- Add a terminal persistence mode that attempts to clear the terminal history.
  It is enabled by setting terminal persistence to
  `clear-on-rebuild-and-flush-history` (ocaml/dune#6065, @rgrinberg)

- Disallow generating targets in sub direcories in inferred rules. The check to
  forbid this was accidentally done only for manually specified targets (ocaml/dune#6031,
  @rgrinberg)

- Do not ignore rules marked `(promote (until-clean))` when
  `--ignore-promoted-rules` (or `-p`) is passed. (ocaml/dune#6010, fixes ocaml/dune#4401, @emillon)

- Dune no longer considers .aux files as targets during Coq compilation. This
  means that .aux files are no longer cached. (ocaml/dune#6024, fixes ocaml/dune#6004, @Alizter)

- Cinaps actions are now sandboxed by default (ocaml/dune#6062, @rgrinberg)

- Allow rules producing directory targets to be not sandboxed (ocaml/dune#6056,
  @rgrinberg)

- Introduce a `dirs` field in the `install` stanza to install entire
  directories (ocaml/dune#5097, fixes ocaml/dune#5059, @rgrinberg)

- Menhir rules are now sandboxed by default (ocaml/dune#6076, @rgrinberg)

- Allow rules producing directory targets to create symlinks (ocaml/dune#6077, fixes
  ocaml/dune#5945, @rgrinberg)

- Inline tests are now sandboxed by default (ocaml/dune#6079, @rgrinberg)

- Fix build-info version when used with flambda (ocaml/dune#6089, fixes ocaml/dune#6075, @jberdine)

- Add an `(include <file>)` term to the `include_dirs` field for adding
  directories to the include paths sourced from a file. (ocaml/dune#6058, fixes ocaml/dune#3993,
  @gridbugs)

- Support `(extra_objects ...)` field in `(executable ...)` and `(library
  ...)` stanzas (ocaml/dune#6084, fixes ocaml/dune#4129, @gridbugs)

- Fix compilation of Dune under esy on Windows (ocaml/dune#6109, fixes ocaml/dune#6098, @nojb)

- Improve error message when parsing several licenses in `(license)` (ocaml/dune#6114,
  fixes ocaml/dune#6103, @emillon)

- odoc rules now about `ODOC_SYNTAX` and will rerun accordingly (ocaml/dune#6010, fixes
  ocaml/dune#1117, @emillon)

- dune install: copy files in an atomic way (ocaml/dune#6150, @emillon)

- Add `%{coq:...}` macro for accessing data about the configuration about Coq.
  For instance `%{coq:version}` (ocaml/dune#6049, @Alizter)

- update vendored copy of cmdliner to 1.1.1. This improves the built-in
  documentation for command groups such as `dune ocaml`. (ocaml/dune#6038, @emillon,
  ocaml/dune#6169, @shonfeder)

- The test suite for Coq now requires Coq >= 8.16 due to changes in the
  plugin loading mechanism upstream (which now uses `Findlib`).

- Starting with Coq build language 0.6, theories can be built without importing
  Coq's standard library by including `(stdlib no)`.
  (ocaml/dune#6165 ocaml/dune#6164, fixes ocaml/dune#6163, @ejgallego @Alizter @LasseBlaauwbroek)

- on macOS, sign executables produced by artifact substitution (ocaml/dune#6137, ocaml/dune#6231,
  fixes ocaml/dune#5650, fixes ocaml/dune#6226, @emillon)

- Added an (aliases ...) field to the (rules ...) stanza which allows the
  specification of multiple aliases per rule (ocaml/dune#6194, @Alizter)

- The `(coq.theory ...)` stanza will now ensure that for each declared `(plugin
 ...)`, the `META` file for it is built before calling `coqdep`. This enables
 the use of the new `Findlib`-based loading method in Coq 8.16; however as of
 Coq 8.16.0, Coq itself has some bugs preventing this to work yet. (ocaml/dune#6167 ,
 workarounds ocaml/dune#5767, @ejgallego)

- Allow include statement in install stanza (ocaml/dune#6139, fixes ocaml/dune#256, @gridbugs)

- Handle CSI n K code in ANSI escape codes from commands. (ocaml/dune#6214, fixes ocaml/dune#5528,
  @emillon)

- Add a new experimental feature `mode_specific_stubs` that allows the
  specification of different flags and sources for foreign stubs depending on
  the build mode (ocaml/dune#5649, @voodoos)
@gridbugs gridbugs deleted the include-in-include_dirs branch October 11, 2023 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow :include in include_dirs field
3 participants