From f35a2c433f99943c7c4414a65c6bbd8299be7185 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 28 Oct 2021 19:31:26 +0200 Subject: [PATCH 1/3] Update examples --- examples/binary/.ocamlformat | 2 +- examples/binary/CONTRIBUTING.md | 2 +- examples/binary/dune-project | 2 +- examples/binary/lib/dune | 1 + examples/executable/dune-project | 2 +- examples/library/.ocamlformat | 2 +- examples/library/CONTRIBUTING.md | 2 +- examples/library/dune-project | 2 +- examples/library/src/dune | 1 + 9 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/binary/.ocamlformat b/examples/binary/.ocamlformat index 0eac260..bc9c6ce 100644 --- a/examples/binary/.ocamlformat +++ b/examples/binary/.ocamlformat @@ -1 +1 @@ -version = 0.12 +version = 0.19.0 diff --git a/examples/binary/CONTRIBUTING.md b/examples/binary/CONTRIBUTING.md index 0ee9ff6..ef9f5e8 100644 --- a/examples/binary/CONTRIBUTING.md +++ b/examples/binary/CONTRIBUTING.md @@ -1,6 +1,6 @@ ## Setting up your working environment -binary requires OCaml 4.09.0 or higher so you will need a corresponding opam +binary requires OCaml 4.14.0 or higher so you will need a corresponding opam switch. You can install a switch with the latest OCaml version by running: ``` diff --git a/examples/binary/dune-project b/examples/binary/dune-project index 09129c7..42fd4f2 100644 --- a/examples/binary/dune-project +++ b/examples/binary/dune-project @@ -1,4 +1,4 @@ -(lang dune 2.0) +(lang dune 2.9.1) (name binary) (implicit_transitive_deps false) diff --git a/examples/binary/lib/dune b/examples/binary/lib/dune index 24976ea..b542398 100644 --- a/examples/binary/lib/dune +++ b/examples/binary/lib/dune @@ -1,3 +1,4 @@ (library (name binary) + (public_name binary) (libraries logs)) diff --git a/examples/executable/dune-project b/examples/executable/dune-project index 929c696..3aad160 100644 --- a/examples/executable/dune-project +++ b/examples/executable/dune-project @@ -1 +1 @@ -(lang dune 2.0) +(lang dune 2.9.1) diff --git a/examples/library/.ocamlformat b/examples/library/.ocamlformat index 0eac260..bc9c6ce 100644 --- a/examples/library/.ocamlformat +++ b/examples/library/.ocamlformat @@ -1 +1 @@ -version = 0.12 +version = 0.19.0 diff --git a/examples/library/CONTRIBUTING.md b/examples/library/CONTRIBUTING.md index f5c8493..21ab694 100644 --- a/examples/library/CONTRIBUTING.md +++ b/examples/library/CONTRIBUTING.md @@ -1,6 +1,6 @@ ## Setting up your working environment -library requires OCaml 4.09.0 or higher so you will need a corresponding opam +library requires OCaml 4.14.0 or higher so you will need a corresponding opam switch. You can install a switch with the latest OCaml version by running: ``` diff --git a/examples/library/dune-project b/examples/library/dune-project index 8c32354..9b7e3e4 100644 --- a/examples/library/dune-project +++ b/examples/library/dune-project @@ -1,4 +1,4 @@ -(lang dune 2.0) +(lang dune 2.9.1) (name library) (implicit_transitive_deps false) diff --git a/examples/library/src/dune b/examples/library/src/dune index 15c6ac2..02893e0 100644 --- a/examples/library/src/dune +++ b/examples/library/src/dune @@ -1,3 +1,4 @@ (library (name library) + (public_name library) (libraries logs)) From 36b9e41165b2733f55fa2f8c09e950feefdfc07e Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 28 Oct 2021 19:18:34 +0200 Subject: [PATCH 2/3] dune-project: Add the :with-test filter on alcotest --- examples/binary/dune-project | 2 +- examples/library/dune-project | 2 +- lib/config.ml | 7 ++++++- lib/contents.ml | 13 +++++++++---- lib/layouts.ml | 2 +- lib/oskel.ml | 5 +++++ 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/examples/binary/dune-project b/examples/binary/dune-project index 42fd4f2..7cfa173 100644 --- a/examples/binary/dune-project +++ b/examples/binary/dune-project @@ -14,4 +14,4 @@ Binary that depends on a tested library ") (documentation https://JoeBloggs.github.io/binary/) - (depends alcotest fmt logs)) + (depends (alcotest :with-test) fmt logs)) diff --git a/examples/library/dune-project b/examples/library/dune-project index 9b7e3e4..d019d73 100644 --- a/examples/library/dune-project +++ b/examples/library/dune-project @@ -14,4 +14,4 @@ Single package in `src` ") (documentation https://JoeBloggs.github.io/library/) - (depends alcotest fmt logs)) + (depends (alcotest :with-test) fmt logs)) diff --git a/lib/config.ml b/lib/config.ml index e704661..1f4d515 100644 --- a/lib/config.ml +++ b/lib/config.ml @@ -7,6 +7,11 @@ type versions = { ocamlformat : string; } +type dependency = { + dep_name : string; + dep_filter : string option; (** For example, ["with-test"]. *) +} + type t = { name : string; project_synopsis : string; @@ -15,7 +20,7 @@ type t = { github_organisation : string; initial_version : string; license : License.t; - dependencies : string list; + dependencies : dependency list; versions : versions; ocamlformat_options : (string * string) list; current_year : int; diff --git a/lib/contents.ml b/lib/contents.ml index d803162..699f9e2 100644 --- a/lib/contents.ml +++ b/lib/contents.ml @@ -3,12 +3,17 @@ open Utils type file_printer = Config.t -> Format.formatter -> unit +let dep_alcotest = { dep_name = "alcotest"; dep_filter = Some "with-test" } + module Dune_project = struct + let pp_depend ppf dep = + match dep.dep_filter with + | None -> Fmt.string ppf dep.dep_name + | Some filter -> Fmt.pf ppf "(%s :%s)" dep.dep_name filter + let package c ppf = let dependencies = - c.dependencies - |> List.append [ "alcotest" ] - |> List.sort_uniq String.compare + c.dependencies |> List.append [ dep_alcotest ] |> List.sort_uniq compare in Fmt.pf ppf {|(lang dune %s) (name %s) @@ -35,7 +40,7 @@ module Dune_project = struct (documentation https://%s.github.io/%s/) (depends %a))|} c.name c.project_synopsis c.project_synopsis c.github_organisation c.name - Fmt.(list ~sep:(const string " ") string) + Fmt.(list ~sep:(const string " ") pp_depend) dependencies let minimal config ppf = Fmt.pf ppf "(lang dune %s)" config.versions.dune diff --git a/lib/layouts.ml b/lib/layouts.ml index 3a66692..0e5359c 100644 --- a/lib/layouts.ml +++ b/lib/layouts.ml @@ -152,7 +152,7 @@ let binary = { layout = binary; post_init = [] } let executable (config : Config.t) = let name = config.name in let toplevel_file = Utils.Utils_naming.file_of_project name in - let libraries = config.dependencies in + let libraries = List.map (fun d -> d.Config.dep_name) config.dependencies in let open Contents in Folder ( config.name, diff --git a/lib/oskel.ml b/lib/oskel.ml index f86ca00..913157d 100644 --- a/lib/oskel.ml +++ b/lib/oskel.ml @@ -180,6 +180,11 @@ let run ~project_kind ?name ?project_synopsis ~maintainer_fullname if !progress_bar_active then Printf.printf "\r\n%!"; return ()) and+ c = config >* progress in + let dependencies = + List.map + (fun dep_name -> { Config.dep_name; dep_filter = None }) + dependencies + in let versions = versions |> function From f99093f7a8d7bee34638681e3a2a323c4173f5e2 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 28 Oct 2021 19:24:26 +0200 Subject: [PATCH 3/3] Opam: Generate the same dependencies as Dune --- lib/contents.ml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/contents.ml b/lib/contents.ml index 699f9e2..85adb16 100644 --- a/lib/contents.ml +++ b/lib/contents.ml @@ -5,6 +5,9 @@ type file_printer = Config.t -> Format.formatter -> unit let dep_alcotest = { dep_name = "alcotest"; dep_filter = Some "with-test" } +let project_dependencies config = + config.dependencies |> List.append [ dep_alcotest ] |> List.sort_uniq compare + module Dune_project = struct let pp_depend ppf dep = match dep.dep_filter with @@ -12,9 +15,6 @@ module Dune_project = struct | Some filter -> Fmt.pf ppf "(%s :%s)" dep.dep_name filter let package c ppf = - let dependencies = - c.dependencies |> List.append [ dep_alcotest ] |> List.sort_uniq compare - in Fmt.pf ppf {|(lang dune %s) (name %s) (implicit_transitive_deps false) @@ -41,7 +41,7 @@ module Dune_project = struct (depends %a))|} c.name c.project_synopsis c.project_synopsis c.github_organisation c.name Fmt.(list ~sep:(const string " ") pp_depend) - dependencies + (project_dependencies c) let minimal config ppf = Fmt.pf ppf "(lang dune %s)" config.versions.dune end @@ -203,6 +203,9 @@ let opam config ppf = Fmt.pf ppf "git+https://github.com/%s/%s.git" config.github_organisation config.name in + let pp_depend ppf dep = + Fmt.pf ppf "%S%a" dep.dep_name Fmt.(option (fmt " {%s}")) dep.dep_filter + in Fmt.pf ppf {|opam-version: "%s" maintainer: "%s" @@ -221,14 +224,14 @@ build: [ depends: [ "ocaml" {>= "%s"} "dune" {build & >= "%s"} - "fmt" - "logs" - "alcotest" {with-test} + @[%a@] ] synopsis: "%s"|} config.versions.opam config.maintainer_fullname config.maintainer_fullname Config.pp_license config.license pp_homepage config pp_bugreports config pp_devrepo config config.versions.ocaml config.versions.dune + Fmt.(list ~sep:cut pp_depend) + (project_dependencies config) config.project_synopsis let test_main_ml config ppf =