Skip to content

Commit

Permalink
pkg: apply suggestion from code review
Browse files Browse the repository at this point in the history
Signed-off-by: Alpha DIALLO <moyodiallo@gmail.com>
  • Loading branch information
moyodiallo committed Jul 3, 2024
1 parent fb85bb2 commit 20b25e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
4 changes: 2 additions & 2 deletions doc/changes/10647.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- pkg: A new feature that will build and make ocamlformat available for `dune fmt`
or `dune build @fmt`.
- pkg: A new feature that build and install ocamlformat automatically without user
having to install it, this is done during the use of `dune fmt`. (#10647, @moyodiallo)
7 changes: 3 additions & 4 deletions src/dune_pkg/dev_tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ type t =
}

let to_local (t : t) : Local_package.t =
let open Local_package in
{ name = t.name
{ Local_package.name = t.name
; version = None
; dependencies = t.dependencies
; conflicts = []
Expand All @@ -18,7 +17,7 @@ let to_local (t : t) : Local_package.t =
}
;;

let lock_dir = Path.Source.of_string "dev_tools.locks"
let lock_dir = Path.Source.of_string "dev_tools"

module Ocamlformat = struct
(* CR-moyodiallo: just to experiement the solving, hard-coded version is going to be removed *)
Expand All @@ -40,5 +39,5 @@ module Ocamlformat = struct
let package_dev = to_local _ocamlformat_dev
let program = "ocamlformat"
let pkg_name = "ocamlformat"
let lock_dir = Path.Source.relative lock_dir "ocamlformat_dev"
let lock_dir = Path.Source.relative lock_dir "ocamlformat.lock"
end
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/pkg/dune
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@
(cram
(deps %{bin:tar})
(applies_to source-caching tarball))

(cram
(deps %{bin:md5sum})
(applies_to ocamlformat-dev-tool))
39 changes: 15 additions & 24 deletions test/blackbox-tests/test-cases/pkg/ocamlformat-dev-tool.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Exercises end to end, locking and building ocamlformat dev tool.
$ . ./helpers.sh
$ mkrepo

Make a library:
Make a fake ocamlformat:
$ mkdir ocamlformat
$ cd ocamlformat
$ cat > dune-project <<EOF
Expand Down Expand Up @@ -32,28 +32,23 @@ Start a oneshot webserver so dune can download the packgae with http:
Make a package for the library:
$ mkpkg ocamlformat 0.26.2 <<EOF
> build: [
> ["dune" "subst"] {dev}
> [
> "dune"
> "build"
> "-p"
> name
> "-j"
> jobs
> "@install"
> "@runtest" {with-test}
> "@doc" {with-doc}
> ]
> ]
> url {
> src: "http://0.0.0.0:$PORT"
> src: "http://127.0.0.1:$PORT"
> checksum: [
> "md5=$(md5sum ocamlformat.tar.gz | cut -f1 -d' ')"
> ]
> }
> EOF

Make a project that uses the library:
Make a project that uses the fake ocamlformat:

$ cat > dune-project <<EOF
> (lang dune 3.13)
Expand All @@ -71,14 +66,13 @@ Make a project that uses the library:
> EOF

$ cat > .ocamlformat <<EOF
> profile = default
> version = 0.26.2
> EOF

$ cat >dune-workspace <<EOF
> (lang dune 3.13)
> (lock_dir
> (path "dev_tools.locks/ocamlformat_dev")
> (path "dev_tools/ocamlformat.lock")
> (repositories mock))
> (lock_dir
> (repositories mock))
Expand All @@ -96,7 +90,7 @@ Lock the to trigger package management

Format the foo.ml
$ dune fmt
Solution for dev_tools.locks/ocamlformat_dev:
Solution for dev_tools/ocamlformat.lock:
- ocamlformat.0.26.2
File "foo.ml", line 1, characters 0-0:
Error: Files _build/default/foo.ml and _build/default/.formatted/foo.ml
Expand All @@ -110,51 +104,48 @@ The second time, it is not supposed to solve again.
$ dune fmt

When dev_tools.locks is removed, the solving is renewed
$ rm -r dev_tools.locks
$ rm -r dev_tools/ocamlformat.lock
$ dune fmt
Solution for dev_tools.locks/ocamlformat_dev:
Solution for dev_tools/ocamlformat.lock:
- ocamlformat.0.26.2

Format again, ocamlformat is a dependency now, to make sure it works without pkg management
Format again, ocamlformat is a dependency with different version, to make sure it works
without pkg management
$ webserver_oneshot --content-file ocamlformat.tar.gz --port-file port.txt &
$ until test -f port.txt; do sleep 0.1; done
$ PORT=$(cat port.txt)
$ cat > dune-project <<EOF
> (lang dune 3.13)
> (package
> (name foo)
> (depends ocamlformat))
> (depends (ocamlformat (= 0.26.3))))
> EOF
$ cat > foo.ml <<EOF
> let () = print_endline "Hello, world"
> EOF
$ mkpkg ocamlformat 0.26.2 <<EOF
Create another version of ocamlformat and the new webserver PORT for the URL.
$ mkpkg ocamlformat 0.26.3 <<EOF
> build: [
> ["dune" "subst"] {dev}
> [
> "dune"
> "build"
> "-p"
> name
> "-j"
> jobs
> "@install"
> "@runtest" {with-test}
> "@doc" {with-doc}
> ]
> ]
> url {
> src: "http://0.0.0.0:$PORT"
> src: "http://127.0.0.1:$PORT"
> checksum: [
> "md5=$(md5sum ocamlformat.tar.gz | cut -f1 -d' ')"
> ]
> }
> EOF

Lock the to trigger package management
Lock the to trigger package management with the new version
$ dune pkg lock
Solution for dune.lock:
- ocamlformat.0.26.2
- ocamlformat.0.26.3

Format the foo.ml
$ dune fmt
Expand Down

0 comments on commit 20b25e7

Please sign in to comment.