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

Dune upgrade V1 -> V2 #3174

Merged
merged 32 commits into from
Mar 24, 2020
Merged

Dune upgrade V1 -> V2 #3174

merged 32 commits into from
Mar 24, 2020

Conversation

voodoos
Copy link
Collaborator

@voodoos voodoos commented Feb 21, 2020

This PR aims to track the ongoing development of a new procedure that would help users to upgrade their projects to dune_lang >=2.0. The hope is that a vast majority of projects can be migrated in a mostly automated way. After the upgrade users will be prompted with a list of hard-to-migrate things that they should check manually.

Progression

Doc updates

  • self_build_stubs_archive does not exists since 2.0
  • c_names / c_flags / etc do not exist since 2.0

Breaking changes that should be automatically handled

  • Get rid of ad-hoc rules for guessing the version. Dune now only
    relies on the version written in the dune-project file and no
    longer read VERSION or similar files.
  • The action field in the alias stanza is not available starting lang dune 2.0. The alias field in the rule stanza is a replacement.
  • Set up formatting rules by default. They can be configured through a new
    (formatting) stanza in dune-project.

    💡 The upgrader adds (formatting disabled) when the project was not formatted. It adds (formatted (enabled_for ...)) when needed.
  • *Change the default modes field of executables to (mode exe). If
    one wants to build a bytecode program, it now needs to be explicitly
    requested via (modes byte exe). *
    💡 The upgrader adds (modes byte exe) to executables without explicit mode.
  • Error out when a preprocessor_deps field is present but not
    preprocess field is. It is a warning with Dune 1.x projects.

    💡 The upgrader removes preprocessor_deps field when there is no preprocess field or if the chosen preprocess is no_preprocessing
  • no_keep_locs is a no-op for projects that use lang dune older than 2.0. In
    projects where the language is at least 2.0, the field is now forbidden.
  • c_flags, c_names and cxx_names are now supported in executable and executables stanzas.
    Note: this feature has been subsequently extended into a separate foreign_stubs field.

    💡 In libraries and executables stanzas, the upgrader replaces the fields c(xx)_names and c(xx)_flags by an appropriate foreign_stubs field.

Breaking changes that the user should be aware of

  • Drop support for jbuild and jbuild-ignore files.
  • *mli only modules must now be explicitly declared. This was previously a
    warning and is now an error. *
  • self_build_stubs_archive was deleted in version 2.0 of the dune language
  • Stop installing the ocaml-syntax-shims binary. In order to use
    future_syntax, one now need to depend on the ocaml-syntax-shims
    package.
  • Actions which introduce targets where new targets are forbidden (e.g.
    preprocessing) are now an error instead of a warning.
  • Stop installing the ocaml-syntax-shims binary. In order to use
    future_syntax, one now need to depend on the ocaml-syntax-shims
    package.
  • Do not put the <package>.install files in the source tree unless -p or
    --promote-install-files is passed on the command line
  • Library names are now validated in a strict fashion. Previously, invalid names
    would be allowed for unwrapped libraries
  • Stricter validation of file names in select. The file names of conditional
    sources must match the prefix and the extension of the resultant filename.
  • Modules filtered out from the module list via the Ordered Set Language must
    now be actual modules.
  • Stub names are no longer allowed relative paths. This was previously a warning
    and is now an error.
  • In (diff? x y) action, require x to exist and register a
    dependency on that file.

Non-breaking changes

@ghost
Copy link

ghost commented Feb 26, 2020

Drop support for jbuild and jbuild-ignore files

I don't think we need to do anything about that. dune >= 2.0.0 binaries cannot read jbuild files at all, whether we are in a dune 1 or dune 2 project.

@voodoos
Copy link
Collaborator Author

voodoos commented Feb 26, 2020

I have updated the list of breaking changes that the upgrader should take into account (first post).
@diml, @nojb, @rgrinberg , @emillon do you see anything missing ?

@ghost
Copy link

ghost commented Feb 27, 2020

That looks all good to me! I can't think of anything else. Thanks!

@voodoos
Copy link
Collaborator Author

voodoos commented Feb 28, 2020

After performing some testing I encountered this change:

Error: 'c_names' was deleted in version 2.0 of the dune language.
Use the (foreign_stubs ...) field instead.

Which was not very clear in the changelog:

c_flags, c_names and cxx_names are now supported in executable and executables stanzas.
(#2562, @nojb) Note: this feature has been subsequently extended into a separate
foreign_stubs field. (#2659, RFC #2650, @snowleopard)

I will add that to the upgrader's work, and correct the doc/changelog.

@emillon
Copy link
Collaborator

emillon commented Feb 28, 2020

That's great! With (foreign_stubs) that'll cover most of the uses.

@voodoos voodoos force-pushed the dune-upgrade-2 branch 4 times, most recently from 0a6f52b to e09db92 Compare March 3, 2020 16:27
@voodoos voodoos changed the title [WIP] Dune upgrade V1 -> V2 Dune upgrade V1 -> V2 Mar 3, 2020
@voodoos voodoos marked this pull request as ready for review March 3, 2020 16:35
@voodoos
Copy link
Collaborator Author

voodoos commented Mar 3, 2020

Ok, I think this PR is ready for review.

All the logic is in upgrader.ml. I initially splitted the upgrader in three files, "common", "v1" and "v2", but decided to merge them back at the end.

  • module Common contains code which is common to both upgraders or that should be useful for a future v2 -> v3 upgrader.
  • module V1 contains the upgrader from jbuild to dune v1.
  • module V2 contains the novel upgrader from dune v1 to v2.
  • The toplevel upgrade function makes the list of folders to upgrade and to which version, then calls the corresponding upgraders. The project version "detection" is happening in the detect_project_version function and may still be a bit fragile.

To update an old jbuild project to v2, the upgrader should be run twice.

CHANGES.md Outdated Show resolved Hide resolved
@rgrinberg
Copy link
Member

To update an old jbuild project to v2, the upgrader should be run twice.

Is it difficult to make the tool sequence the upgrades automatically? it's not so important and I think that it probably makes sense for users to inspect each upgrade individually, but for some duniverse like use cases where you have a massive workspace of 3rd party packages, it would be annoying to run $ dune upgrade a few times.

@emillon
Copy link
Collaborator

emillon commented Mar 4, 2020

Yes I agree about this point, in particular that ensures that dune upgrade is idempotent (running it twice is equivalent to running it once).

@voodoos
Copy link
Collaborator Author

voodoos commented Mar 5, 2020

Is it difficult to make the tool sequence the upgrades automatically?

Ok so I tried to make the updater run twice in two ways:

  • Juste make it call itself recursively at the end of the first ugprade if v0-v1 upgrades where detected.
  • Schedule two upgrades at the bin/upgrade.ml level

In both cases it looks like the File_tree is not refreshed: the second upgrades tries to perform v0->v1 upgrades again but fails because the jbuild files have already been translated and deleted.

Any idea of how I could manage it ?

@rgrinberg
Copy link
Member

rgrinberg commented Mar 5, 2020 via email

@voodoos
Copy link
Collaborator Author

voodoos commented Mar 5, 2020

Thanks ! Memo has a reset function:
If I call this function before the new upgrading attempt it does work !

Is that a bad way to do it ?

@rgrinberg
Copy link
Member

rgrinberg commented Mar 5, 2020 via email

@aalekseyev
Copy link
Collaborator

I think calling reset is reasonable in this case. The incremental computation is not fully implemented yet and untested so we shouldn't try to make it work in this PR.

@emillon
Copy link
Collaborator

emillon commented Mar 16, 2020

Hello,

Just checking in: what's the status of this? If it's doing the upgrades in an idempotent way I think it's good to go after a final round of review.

@voodoos
Copy link
Collaborator Author

voodoos commented Mar 16, 2020

I added a test illustrating the idempotency of the upgrade procedure.
I also rebased on master. It should be ready for review.

src/dune/upgrader.mli Outdated Show resolved Hide resolved
src/dune/upgrader.ml Outdated Show resolved Hide resolved
src/dune/upgrader.ml Outdated Show resolved Hide resolved
src/dune/upgrader.ml Show resolved Hide resolved
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
Signed-off-by: Ulysse Gérard <[email protected]>
@rgrinberg rgrinberg merged commit 8c6c42c into ocaml:master Mar 24, 2020
voodoos added a commit to voodoos/dune that referenced this pull request Mar 25, 2020
voodoos added a commit that referenced this pull request Mar 25, 2020
stephanieyou pushed a commit to stephanieyou/dune that referenced this pull request Apr 7, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Apr 10, 2020
…lugin, dune-private-libs and dune-glob (2.5.0)

CHANGES:

- Add a `--release` option meaning the same as `-p` but without the
  package filtering. This is useful for custom `dune` invocation in opam
  files where we don't want `-p` (ocaml/dune#3260, @diml)

- Fix a bug introduced in 2.4.0 causing `.bc` programs to be built
  with `-custom` by default (ocaml/dune#3269, fixes ocaml/dune#3262, @diml)

- Allow contexts to be defined with local switches in workspace files (ocaml/dune#3265,
  fix ocaml/dune#3264, @rgrinberg)

- Delay expansion errors until the rule is used to build something (ocaml/dune#3261, fix
  ocaml/dune#3252, @rgrinberg, @diml)

- [coq] Support for theory dependencies and compositional builds using
  new field `(theories ...)` (ocaml/dune#2053, @ejgallego, @rgrinberg)

- From now on, each version of a syntax extension must be explicitely tied to a
  minimum version of the dune language. Inconsistent versions in a
  `dune-project` will trigger a warning for version <=2.4 and an error for
  versions >2.4 of the dune language. (ocaml/dune#3270, fixes ocaml/dune#2957, @voodoos)

- [coq] Bump coq lang version to 0.2. New coq features presented this release
  require this version of the coq lang. (ocaml/dune#3283, @ejgallego)

- Prevent installation of public executables disabled using the `enabled_if` field.
  Installation will now simply skip such executables instead of raising an
  error. (ocaml/dune#3195, @voodoos)

- `dune upgrade` will now try to upgrade projects using versions <2.0 to version
  2.0 of the dune language. (ocaml/dune#3174, @voodoos)

- Add a `top` command to integrate dune with any toplevel, not just
  utop. It is meant to be used with the new `#use_output` directive of
  OCaml 4.11 (ocaml/dune#2952, @mbernat, @diml)

- Allow per-package `version` in generated `opam` files (ocaml/dune#3287, @toots)

- [coq] Introduce the `coq.extraction` stanza. It can be used to extract OCaml
  sources (ocaml/dune#3299, fixes ocaml/dune#2178, @rgrinberg)

- Load ppx rewriters in dune utop and add pps field to toplevel stanza. Ppx
  extensions will now be usable in the toplevel
  (ocaml/dune#3266, fixes ocaml/dune#346, @stephanieyou)

- Add a `(subdir ..)` stanza to allow evaluating stanzas in sub directories.
  (ocaml/dune#3268, @rgrinberg)

- Fix a bug preventing one from running inline tests in multiple modes
  (ocaml/dune#3352, @diml)

- Allow the use of the `%{profile}` variable in the `enabled_if` field of the
  library stanza. (ocaml/dune#3344, @mrmr1993)

- Allow the use of `%{ocaml_version}` variable in `enabled_if` field of the
  library stanza. (ocaml/dune#3339, @voodoos)

- Fix dune build freezing on MacOS when cache is enabled. (ocaml/dune#3249, fixes #ocaml/dune#2973,
  @artempyanykh)
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.

4 participants