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

Insert a constraint on the version of dune #3434

Merged
3 commits merged into from May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Unreleased
----------
next
----

- Insert a constraint one the version of dune when the user explicitly
specify the dependency on dune in the `dune-project` file (#3434 ,
fixes #3427, @diml)

- Generate correct META files for sub-libraries (of the form `lib.foo`) that
contain .js runtime files. (#3445, @hhugo)
Expand Down
6 changes: 3 additions & 3 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ like:

.. code:: scheme

(lang dune 2.5)
(lang dune 2.6)

Additionally, they can contains the following stanzas.

Expand Down Expand Up @@ -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)))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/opam.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
49 changes: 34 additions & 15 deletions src/dune/opam_create.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dune/stanza.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
51 changes: 51 additions & 0 deletions test/blackbox-tests/test-cases/dune-project-meta/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
> (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 <<EOF
> (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 <<EOF
> (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"}
]