From 1abc5ae33c51acb8c5323283dcdac6429bce6017 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Wed, 29 Apr 2020 12:19:12 +0100 Subject: [PATCH 1/2] Insert a constraint on the version of dune Even if the dependency is explicitly listed in the dune-project file Fixes #3427 Signed-off-by: Jeremie Dimino --- CHANGES.md | 7 +++ doc/dune-files.rst | 6 +-- doc/opam.rst | 2 +- src/dune/opam_create.ml | 49 ++++++++++++------ src/dune/stanza.ml | 2 +- .../test-cases/dune-project-meta/run.t | 51 +++++++++++++++++++ 6 files changed, 97 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 74c000c304c..2dba3f63167 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +next +---- + +- Insert a constraint one the version of dune when the user explicitly + specify the dependency on dune in the `dune-project` file (#...., + fixes #3427, @diml) + 2.5.1 (17/04/2020) ------------------ diff --git a/doc/dune-files.rst b/doc/dune-files.rst index 51c1a36e3ea..03031e12818 100644 --- a/doc/dune-files.rst +++ b/doc/dune-files.rst @@ -12,7 +12,7 @@ like: .. code:: scheme - (lang dune 2.5) + (lang dune 2.6) Additionally, they can contains the following stanzas. @@ -1748,7 +1748,7 @@ a typical ``dune-workspace`` file looks like: .. code:: scheme - (lang dune 2.5) + (lang dune 2.6) (context (opam (switch 4.02.3))) (context (opam (switch 4.03.0))) (context (opam (switch 4.04.0))) @@ -1760,7 +1760,7 @@ containing exactly: .. code:: scheme - (lang dune 2.5) + (lang dune 2.6) (context default) This allows you to use an empty ``dune-workspace`` file to mark the root of your diff --git a/doc/opam.rst b/doc/opam.rst index c226d608961..50b8ec22f7d 100644 --- a/doc/opam.rst +++ b/doc/opam.rst @@ -94,7 +94,7 @@ configuration will tell ``dune`` to generate two opam files: ``cohttp.opam`` and .. code:: scheme - (lang dune 2.5) + (lang dune 2.6) (name cohttp) ; version field is optional (version 1.0.0) diff --git a/src/dune/opam_create.ml b/src/dune/opam_create.ml index a0883936a83..4512f7e9ccd 100644 --- a/src/dune/opam_create.ml +++ b/src/dune/opam_create.ml @@ -81,27 +81,46 @@ let package_fields in List.concat fields +let dune_name = Package.Name.of_string "dune" + +let insert_dune_dep depends dune_version = + let constraint_ : Package.Dependency.Constraint.t = + let dune_version = Dune_lang.Syntax.Version.to_string dune_version in + Uop (Gte, QVar dune_version) + in + let rec loop acc = function + | [] -> + let dune_dep = + { Package.Dependency.name = dune_name; constraint_ = Some constraint_ } + in + dune_dep :: List.rev acc + | (dep : Package.Dependency.t) :: rest -> + if Package.Name.equal dep.name dune_name then + let dep = + if dune_version < (2, 6) then + dep + else + { dep with + constraint_ = + Some + ( match dep.constraint_ with + | None -> constraint_ + | Some c -> And [ constraint_; c ] ) + } + in + List.rev_append acc (dep :: rest) + else + loop (dep :: acc) rest + in + loop [] depends + let opam_fields project (package : Package.t) = let dune_version = Dune_project.dune_version project in - let dune_name = Package.Name.of_string "dune" in let package = if dune_version < (1, 11) || Package.Name.equal package.name dune_name then package else - let dune_dep = - let dune_version = Dune_lang.Syntax.Version.to_string dune_version in - let constraint_ : Package.Dependency.Constraint.t = - Uop (Gte, QVar dune_version) - in - { Package.Dependency.name = dune_name; constraint_ = Some constraint_ } - in - let is_dune_depend (pkg : Package.Dependency.t) = - Package.Name.equal pkg.name dune_dep.name - in - if List.exists package.depends ~f:is_dune_depend then - package - else - { package with depends = dune_dep :: package.depends } + { package with depends = insert_dune_dep package.depends dune_version } in let package_fields = package_fields package ~project in let open Opam_file.Create in diff --git a/src/dune/stanza.ml b/src/dune/stanza.ml index e15020757e0..31ad7c09020 100644 --- a/src/dune/stanza.ml +++ b/src/dune/stanza.ml @@ -6,7 +6,7 @@ module Parser = struct type nonrec t = string * t list Dune_lang.Decoder.t end -let latest_version = (2, 5) +let latest_version = (2, 6) let since v = (v, `Since v) diff --git a/test/blackbox-tests/test-cases/dune-project-meta/run.t b/test/blackbox-tests/test-cases/dune-project-meta/run.t index 73f54ddc6a0..d5c65a219ba 100644 --- a/test/blackbox-tests/test-cases/dune-project-meta/run.t +++ b/test/blackbox-tests/test-cases/dune-project-meta/run.t @@ -346,3 +346,54 @@ Supported since 2.1: Entering directory 'binops' $ grep conf-libX11 binops/foo.opam "conf-libX11" {os != "win32"} + +Version constraint on dune deps +------------------------------- + + $ mkdir dune-dep + $ cd dune-dep + +Without the dune dependency declared in the dune-project file, we +generate a dune dependency with a constraint: + + $ cat > dune-project < (lang dune 2.1) + > (name foo) + > (generate_opam_files true) + > (package (name foo)) + > EOF + + $ dune build foo.opam + $ grep -A2 ^depends: foo.opam + depends: [ + "dune" {>= "2.1"} + ] + +With the dune dependency declared in the dune-project file and version +of the langauge < 2.6 we don't add the constraint: + + $ cat > dune-project < (lang dune 2.5) + > (name foo) + > (generate_opam_files true) + > (package (name foo) (depends dune)) + > EOF + + $ dune build foo.opam + $ grep ^depends: foo.opam + depends: ["dune"] + +Same with version of the langauge >= 2.6, we now add the constraint: + + $ cat > dune-project < (lang dune 2.6) + > (name foo) + > (generate_opam_files true) + > (package (name foo) (depends dune)) + > EOF + + $ dune build foo.opam + $ grep -A2 ^depends: foo.opam + depends: [ + "dune" {>= "2.6"} + ] From 6c93937e88a7afa9b870f8baf22a8300172889b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Dimino?= Date: Tue, 5 May 2020 10:55:47 +0100 Subject: [PATCH 2/2] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2dba3f63167..52bd438162d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ next ---- - Insert a constraint one the version of dune when the user explicitly - specify the dependency on dune in the `dune-project` file (#...., + specify the dependency on dune in the `dune-project` file (#3434 , fixes #3427, @diml) 2.5.1 (17/04/2020)