Skip to content

Commit

Permalink
pkg: fix the fetch of ocamlformat dev tool
Browse files Browse the repository at this point in the history
Signed-off-by: Alpha DIALLO <[email protected]>
  • Loading branch information
moyodiallo committed Jul 2, 2024
1 parent 45f0187 commit 5affb57
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
9 changes: 3 additions & 6 deletions bin/pkg/lock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ let solve
~project_sources
~solver_env_from_current_system
~version_preference
~lock_dirs
~lock_dirs_arg
=
let open Fiber.O in
(* a list of thunks that will perform all the file IO side
effects after performing validation so that if materializing any
lockdir would fail then no side effect takes place. *)
(let+ errors, solutions =
lock_dirs
Pkg_common.Lock_dirs_arg.lock_dirs_of_workspace lock_dirs_arg workspace
|> Fiber.parallel_map
~f:
(solve_lock_dir
Expand Down Expand Up @@ -154,16 +154,13 @@ let lock ~version_preference ~lock_dirs_arg =
and+ project_sources = project_sources in
workspace, local_packages, project_sources
in
let lock_dirs =
Pkg_common.Lock_dirs_arg.lock_dirs_of_workspace lock_dirs_arg workspace
in
solve
workspace
~local_packages
~project_sources
~solver_env_from_current_system
~version_preference
~lock_dirs
~lock_dirs_arg
;;

let term =
Expand Down
2 changes: 1 addition & 1 deletion src/dune_pkg/dev_tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let to_local (t : t) : Local_package.t =
}
;;

let lock_dir = Path.Source.relative (Path.Source.of_string "dune.lock") "dev_tools.lock"
let lock_dir = Path.Source.of_string "dev_tools.locks"

module Ocamlformat = struct
(* CR-moyodiallo: just to experiement the solving, hard-coded version is going to be removed *)
Expand Down
14 changes: 13 additions & 1 deletion src/dune_rules/fetch_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include struct
module Pkg = Lock_dir.Pkg
module OpamUrl = OpamUrl
module Source = Source
module Dev_tool = Dev_tool
end

let context_name = Context_name.of_string "_fetch"
Expand Down Expand Up @@ -173,7 +174,18 @@ let find_checksum, find_url =
~init:(Checksum.Map.empty, Digest.Map.empty)
~f:(fun (checksums, urls) (lockdir : Dune_pkg.Lock_dir.t) ->
let checksums', urls' = extract_checksums_and_urls lockdir in
Checksum.Map.superpose checksums checksums', Digest.Map.superpose urls urls'))
Checksum.Map.superpose checksums checksums', Digest.Map.superpose urls urls')
>>= fun all ->
Fs_memo.dir_exists (In_source_dir Dev_tool.Ocamlformat.lock_dir)
>>= function
| false -> Memo.return all
| true ->
all
|> fun (checksums, urls) ->
Lock_dir.get_ocamlformat
>>| fun lockdir ->
let checksums', urls' = extract_checksums_and_urls lockdir in
Checksum.Map.superpose checksums checksums', Digest.Map.superpose urls urls')
in
let find_url digest =
let+ _, urls = Memo.Lazy.force all in
Expand Down
56 changes: 42 additions & 14 deletions test/blackbox-tests/test-cases/pkg/ocamlformat-dev-tool.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Make a project that uses the library:
$ cat >dune-workspace <<EOF
> (lang dune 3.13)
> (lock_dir
> (path "dune.lock/dev_tools.lock/ocamlformat_dev")
> (path "dev_tools.locks/ocamlformat_dev")
> (repositories mock))
> (lock_dir
> (repositories mock))
Expand All @@ -89,26 +89,32 @@ Make a project that uses the library:

Lock, build, and run the `dune fmt` command in the project:

We lock the to trigger package management
Lock the to trigger package management
$ dune pkg lock
Solution for dune.lock:
(no dependencies to lock)

We format the foo.ml
Format the foo.ml
$ dune fmt
Solution for dune.lock/dev_tools.lock/ocamlformat_dev:
Solution for dev_tools.locks/ocamlformat_dev:
- ocamlformat.0.26.2
Error: unknown checksum md5=0f438cf036709326e9e0d82ea9eaf2ec
-> required by _build/_private/default/.ocamlformat/ocamlformat/source
-> required by _build/_private/default/.ocamlformat/ocamlformat/target/cookie
-> required by _build/default/.formatted/foo.ml
-> required by alias .formatted/fmt
-> required by alias fmt
File "foo.ml", line 1, characters 0-0:
Error: Files _build/default/foo.ml and _build/default/.formatted/foo.ml
differ.
Promoting _build/default/.formatted/foo.ml to foo.ml.
[1]
$ cat foo.ml
let () = print_endline "Hello, world"
formatted

We format again, ocamlformat is a dependency now
The second time, it is not supposed to solve again but at the moment is doing it.
$ dune fmt
Solution for dev_tools.locks/ocamlformat_dev:
- ocamlformat.0.26.2

Format again, ocamlformat is a dependency now, 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
Expand All @@ -118,13 +124,35 @@ We format again, ocamlformat is a dependency now
$ cat > foo.ml <<EOF
> let () = print_endline "Hello, world"
> EOF
$ 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"
> checksum: [
> "md5=$(md5sum ocamlformat.tar.gz | cut -f1 -d' ')"
> ]
> }
> EOF

We lock the to trigger package management
Lock the to trigger package management
$ dune pkg lock
Solution for dune.lock:
- ocamlformat.0.26.2

We format the foo.ml
Format the foo.ml
$ dune fmt
File "foo.ml", line 1, characters 0-0:
Error: Files _build/default/foo.ml and _build/default/.formatted/foo.ml
Expand Down

0 comments on commit 5affb57

Please sign in to comment.