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

Allow (subdir ...) in dune files used via (include ...) #3676

Merged
merged 8 commits into from
Aug 12, 2020

Conversation

nojb
Copy link
Collaborator

@nojb nojb commented Aug 4, 2020

Currently, the (include ...) stanza is processed after the (subdir ...) stanzas have been removed from the input. This makes it impossible to support (subdir ...) in a file used via (include ...). The PR adjusts things so that the (include ...) stanza is processed simultaneously with (subdir ...), so that this is allowed.

I found the code that handles (subdir ...) a bit tricky, so would appreciate a review by someone familiar with it. Thanks!

Fixes #3419

@nojb nojb requested a review from rgrinberg as a code owner August 4, 2020 20:04
@rgrinberg
Copy link
Member

Doesn't this break generating include in ocaml syntax dune files?

@nojb
Copy link
Collaborator Author

nojb commented Aug 4, 2020

Doesn't this break generating include in ocaml syntax dune files?

Good catch, it does :)

Will look into it.

@rgrinberg
Copy link
Member

We'll probably need to evaluate include in both stages (file_tree and dune_file).

@rgrinberg
Copy link
Member

I found the code that handles (subdir ...) a bit tricky, so would appreciate a review by someone familiar with it. Thanks!

Sorry about that. I can try to add some comments to the parts you found tricky.

@nojb
Copy link
Collaborator Author

nojb commented Aug 4, 2020

I found the code that handles (subdir ...) a bit tricky, so would appreciate a review by someone familiar with it. Thanks!

Sorry about that. I can try to add some comments to the parts you found tricky.

No need! I meant that it took me some time to figure out how the logic for (subtree ...) worked, but the code itself is very clear :)

@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

We'll probably need to evaluate include in both stages (file_tree and dune_file).

I pushed a commit doing this.

@rgrinberg
Copy link
Member

There seems to be a failure in CI:

File "test/blackbox-tests/test-cases/dialects.t/bad1/dune-project", line 9, characters 1-74:
395 9 |  (name d)
39610 |  (implementation (extension foo2))
39711 |  (interface (extension bar2)))
398Error: dialect "d" is already defined

@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

There seems to be a failure in CI:

Ya, I'm looking into it, thanks.

@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

There seems to be a failure in CI:

File "test/blackbox-tests/test-cases/dialects.t/bad1/dune-project", line 9, characters 1-74:
395 9 |  (name d)
39610 |  (implementation (extension foo2))
39711 |  (interface (extension bar2)))
398Error: dialect "d" is already defined

It is strange: this is the expected output of the test. On the other hand, I can only reproduce the problem in this branch, not in master...

@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

I think I understand what is happening: with this patch, (include ...) is evaluated more eagerly. In particular, it seem that the include in test/blackbox-tests/dune is being loaded too eagerly, which causes the error above as soon as dune is being built.

@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

OK, I think I found the bug: I am not correctly merging the data_only_dir stanzas from the included files.

@nojb nojb force-pushed the subdir_in_include branch from cf1ae98 to b3b27ce Compare August 5, 2020 12:20
@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

OK, I reworked the patch to fix the problem. I modified the approach a bit: now I process (include ...) in a separate pass before processing (subdir ...) and the rest of the stanzas. The first pass removes any (include ...) node and replaces it by the contents of the included file in the AST, which is then passed onwards and processed as usual.

@nojb nojb force-pushed the subdir_in_include branch 4 times, most recently from cc976e8 to b7da698 Compare August 5, 2020 16:26
@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

I rebased and cleaned up the history. This is ready for review. Thanks!

Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

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

Looks good. I'm surprised how simple this turned out to be.

@jeremiedimino do you think this feature should require 2.7? I'm leaning towards making it available since subdir was introduced and just treating this as a bugfix.

This needs a CHANGES entry.

@nojb
Copy link
Collaborator Author

nojb commented Aug 5, 2020

Looks good. I'm surprised how simple this turned out to be.

Thanks for the quick review!

This needs a CHANGES entry.

Done!

@nojb
Copy link
Collaborator Author

nojb commented Aug 6, 2020

I realised that there may be a small adjustment to make. Suppose that we have:

(subdir a (include dune.inc))

Is the file dune.inc supposed to be found inside a or in the current directory? At the moment, the PR looks for it within the current directory, not within a. It should be easy to adjust, but wanted to confirm first.

@rgrinberg
Copy link
Member

rgrinberg commented Aug 6, 2020 via email

@nojb
Copy link
Collaborator Author

nojb commented Aug 6, 2020

It should be relative to directory “a" I think Rudi.

Indeed, it's that. I pushed a commit (and a corresponding test) for this. It should be good to go now.

@nojb nojb force-pushed the subdir_in_include branch from dd7db2a to 1405faf Compare August 6, 2020 06:35
@rgrinberg
Copy link
Member

@nojb I just talked to Jeremie and we decided that it's best to gate this feature behind 2.7. If users end up relying on this feature without putting the appropriate constraint in their opam file, it will lead to some issues down the road.

If it's not too hard, could you add the version check?

src/dune/sub_dirs.ml Outdated Show resolved Hide resolved
@nojb nojb force-pushed the subdir_in_include branch from 1d562b0 to f238483 Compare August 6, 2020 18:23
@nojb
Copy link
Collaborator Author

nojb commented Aug 6, 2020

Version check (+ test) added.

@nojb nojb force-pushed the subdir_in_include branch from f238483 to 4df0aad Compare August 6, 2020 18:27
@rgrinberg rgrinberg added this to the 2.7 milestone Aug 7, 2020
nojb added 8 commits August 7, 2020 12:51
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
@nojb nojb force-pushed the subdir_in_include branch from 4df0aad to 37f6af9 Compare August 7, 2020 10:51
@rgrinberg
Copy link
Member

@nojb are you still working on this PR?

@nojb
Copy link
Collaborator Author

nojb commented Aug 11, 2020

@nojb are you still working on this PR?

No, the PR is ready to go as far as I am concerned.

@rgrinberg
Copy link
Member

Okay. Then I will merge it today unless you'll do the honors and do it before me.

@nojb
Copy link
Collaborator Author

nojb commented Aug 11, 2020

Okay. Then I will merge it today unless you'll do the honors and do it before me.

Thanks. I'll let you do it; I am away from home with horrible internet service :)

@rgrinberg rgrinberg merged commit 057fa87 into ocaml:master Aug 12, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Aug 14, 2020
…lugin, dune-private-libs and dune-glob (2.7.0)

CHANGES:

- Write intermediate files in a `.mdx` folder for each `mdx` stanza
  to prevent the corresponding actions to be executed as part of the `@all`
  alias (ocaml/dune#3659, @NathanReb)

- Read Coq flags from `env` (ocaml/dune#3547 , fixes ocaml/dune#3486, @gares)

- Allow bisect_ppx to be enabled/disabled via dune-workspace. (ocaml/dune#3404,
  @stephanieyou)

- Formatting of dune files is now done in the executing dune process instead of
  in a separate process. (ocaml/dune#3536, @nojb)

- Add a `--debug-artifact-substution` flag to help debug problem with
  version not being captured by `dune-build-info` (ocaml/dune#3589,
  @jeremiedimino)

- Allow the use of the `context_name` variable in the `enabled_if` fields of
  executable(s) and install stanzas. (ocaml/dune#3568, fixes ocaml/dune#3566, @voodoos)

- Fix compatibility with OCaml 4.12.0 when compiling empty archives; no .a file
  is generated. (ocaml/dune#3576, @dra27)

- `$ dune utop` no longer tries to load optional libraries that are unavailable
  (ocaml/dune#3612, fixes ocaml/dune#3188, @anuragsoni)

- Fix dune-build-info on 4.10.0+flambda (ocaml/dune#3599, @emillon, @jeremiedimino).

- Allow multiple libraries with `inline_tests` to be defined in the same
  directory (ocaml/dune#3621, @rgrinberg)

- Run exit hooks in jsoo separate compilation mode (ocaml/dune#3626, fixes ocaml/dune#3622,
  @rgrinberg)

- Add (alias ...), (mode ...) fields to (copy_fields ...) stanza (ocaml/dune#3631, @nojb)

- (copy_files ...) now supports copying files from outside the workspace using
  absolute file names (ocaml/dune#3639, @nojb)

- Dune does not use `ocamlc` as an intermediary to call C compiler anymore.
  Configuration flags `ocamlc_cflags` and `ocamlc_cppflags` are always prepended
  to the compiler arguments. (ocaml/dune#3565, fixes ocaml/dune#3346, @voodoos)

- Revert the build optimization in ocaml/dune#2268. This optimization slows down building
  individual executables when they're part of an `executables` stanza group
  (ocaml/dune#3644, @rgrinberg)

- Use `{dev}` rather than `{pinned}` in the generated `.opam` file. (ocaml/dune#3647,
  @kit-ty-kate)

- Insert correct extension name when editing `dune-project` files. Previously,
  dune would just insert the stanza name. (ocaml/dune#3649, fixes ocaml/dune#3624, @rgrinberg)

- Fix crash when evaluating an `mdx` stanza that depends on unavailable
  packages. (ocaml/dune#3650, @craigfe)

- Fix typo in `cache-check-probablity` field in dune config files. This field
  now requires 2.7 as it wasn't usable before this version. (ocaml/dune#3652, @edwintorok)

- Add `"odoc" {with-doc}` to the dependencies in the generated `.opam` files.
  (ocaml/dune#3667, @kit-ty-kate)

- Do not allow user actions to capture dune's stdin (ocaml/dune#3677, fixes ocaml/dune#3672,
  @rgrinberg)

- `(subdir ...)` stanzas can now appear in dune files used via `(include ...)`.
  (ocaml/dune#3676, @nojb)
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Aug 14, 2020
…lugin, dune-private-libs and dune-glob (2.7.0)

CHANGES:

- Write intermediate files in a `.mdx` folder for each `mdx` stanza
  to prevent the corresponding actions to be executed as part of the `@all`
  alias (ocaml/dune#3659, @NathanReb)

- Read Coq flags from `env` (ocaml/dune#3547 , fixes ocaml/dune#3486, @gares)

- Add instrumentation framework to toggle instrumentation by `bisect_ppx`,
  `landmarks`, etc, via dune-workspace and/or the command-line. (ocaml/dune#3404, ocaml/dune#3526
  @stephanieyou, @nojb)

- Formatting of dune files is now done in the executing dune process instead of
  in a separate process. (ocaml/dune#3536, @nojb)

- Add a `--debug-artifact-substution` flag to help debug problem with
  version not being captured by `dune-build-info` (ocaml/dune#3589,
  @jeremiedimino)

- Allow the use of the `context_name` variable in the `enabled_if` fields of
  executable(s) and install stanzas. (ocaml/dune#3568, fixes ocaml/dune#3566, @voodoos)

- Fix compatibility with OCaml 4.12.0 when compiling empty archives; no .a file
  is generated. (ocaml/dune#3576, @dra27)

- `$ dune utop` no longer tries to load optional libraries that are unavailable
  (ocaml/dune#3612, fixes ocaml/dune#3188, @anuragsoni)

- Fix dune-build-info on 4.10.0+flambda (ocaml/dune#3599, @emillon, @jeremiedimino).

- Allow multiple libraries with `inline_tests` to be defined in the same
  directory (ocaml/dune#3621, @rgrinberg)

- Run exit hooks in jsoo separate compilation mode (ocaml/dune#3626, fixes ocaml/dune#3622,
  @rgrinberg)

- Add (alias ...), (mode ...) fields to (copy_fields ...) stanza (ocaml/dune#3631, @nojb)

- (copy_files ...) now supports copying files from outside the workspace using
  absolute file names (ocaml/dune#3639, @nojb)

- Dune does not use `ocamlc` as an intermediary to call C compiler anymore.
  Configuration flags `ocamlc_cflags` and `ocamlc_cppflags` are always prepended
  to the compiler arguments. (ocaml/dune#3565, fixes ocaml/dune#3346, @voodoos)

- Revert the build optimization in ocaml/dune#2268. This optimization slows down building
  individual executables when they're part of an `executables` stanza group
  (ocaml/dune#3644, @rgrinberg)

- Use `{dev}` rather than `{pinned}` in the generated `.opam` file. (ocaml/dune#3647,
  @kit-ty-kate)

- Insert correct extension name when editing `dune-project` files. Previously,
  dune would just insert the stanza name. (ocaml/dune#3649, fixes ocaml/dune#3624, @rgrinberg)

- Fix crash when evaluating an `mdx` stanza that depends on unavailable
  packages. (ocaml/dune#3650, @craigfe)

- Fix typo in `cache-check-probablity` field in dune config files. This field
  now requires 2.7 as it wasn't usable before this version. (ocaml/dune#3652, @edwintorok)

- Add `"odoc" {with-doc}` to the dependencies in the generated `.opam` files.
  (ocaml/dune#3667, @kit-ty-kate)

- Do not allow user actions to capture dune's stdin (ocaml/dune#3677, fixes ocaml/dune#3672,
  @rgrinberg)

- `(subdir ...)` stanzas can now appear in dune files used via `(include ...)`.
  (ocaml/dune#3676, @nojb)
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.

subdir doesn't work in included files
2 participants