From 97a2eafe24cac0622f26612beb298a527ba5c8c9 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 8 Jan 2024 10:44:24 -0700 Subject: [PATCH] fix(pkg): improve locations for local path repos Signed-off-by: Rudi Grinberg --- bin/pkg/pkg_common.ml | 2 +- src/dune_pkg/opam_repo.ml | 8 +++++- src/dune_pkg/opam_repo.mli | 2 +- .../pkg/invalid-opam-repo-errors.t/run.t | 25 ++++++++++++++----- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/bin/pkg/pkg_common.ml b/bin/pkg/pkg_common.ml index 2b7604e23f91..ccddcaf7a4e7 100644 --- a/bin/pkg/pkg_common.ml +++ b/bin/pkg/pkg_common.ml @@ -105,7 +105,7 @@ let get_repos repos ~repositories ~update_opam_repositories = | `Git -> let* source = Opam_repo.Source.of_opam_url loc opam_url in Opam_repo.of_git_repo ~update:update_opam_repositories source - | `Path path -> Fiber.return @@ Opam_repo.of_opam_repo_dir_path path)) + | `Path path -> Fiber.return @@ Opam_repo.of_opam_repo_dir_path loc path)) ;; let find_local_packages = diff --git a/src/dune_pkg/opam_repo.ml b/src/dune_pkg/opam_repo.ml index 30f7372d0625..affac3def53f 100644 --- a/src/dune_pkg/opam_repo.ml +++ b/src/dune_pkg/opam_repo.ml @@ -134,17 +134,20 @@ let equal { source; serializable } t = let serializable { serializable; _ } = serializable -let of_opam_repo_dir_path opam_repo_dir_path = +let of_opam_repo_dir_path loc opam_repo_dir_path = (match Path.stat opam_repo_dir_path with | Error (Unix.ENOENT, _, _) -> User_error.raise + ~loc [ Pp.textf "%s does not exist" (Path.to_string_maybe_quoted opam_repo_dir_path) ] | Error _ -> User_error.raise + ~loc [ Pp.textf "could not read %s" (Path.to_string_maybe_quoted opam_repo_dir_path) ] | Ok { Unix.st_kind = S_DIR; _ } -> () | Ok _ -> User_error.raise + ~loc [ Pp.textf "%s is not a directory" (Path.to_string_maybe_quoted opam_repo_dir_path) ]); (let packages = Path.append_local opam_repo_dir_path Paths.packages in @@ -152,9 +155,11 @@ let of_opam_repo_dir_path opam_repo_dir_path = | Ok { Unix.st_kind = S_DIR; _ } -> () | Ok _ -> User_error.raise + ~loc [ Pp.textf "%s is not a directory" (Path.to_string_maybe_quoted packages) ] | Error (Unix.ENOENT, _, _) -> User_error.raise + ~loc [ Pp.textf "%s doesn't look like a path to an opam repository as it lacks a subdirectory \ named \"packages\"" @@ -162,6 +167,7 @@ let of_opam_repo_dir_path opam_repo_dir_path = ] | Error _ -> User_error.raise + ~loc [ Pp.textf "could not read %s" (Path.to_string_maybe_quoted opam_repo_dir_path) ]); { source = Directory opam_repo_dir_path; serializable = None } ;; diff --git a/src/dune_pkg/opam_repo.mli b/src/dune_pkg/opam_repo.mli index 36a445f9620c..b5c347a10e7f 100644 --- a/src/dune_pkg/opam_repo.mli +++ b/src/dune_pkg/opam_repo.mli @@ -36,7 +36,7 @@ end (** [of_opam_repo_dir_path opam_repo_dir] creates a repo represented by a local directory in the path given by [opam_repo_dir]. *) -val of_opam_repo_dir_path : Path.t -> t +val of_opam_repo_dir_path : Loc.t -> Path.t -> t (** [of_git_repo git ~update source] loads the opam repository located at [source] from git. [source] can be any URL that [git remote add] diff --git a/test/blackbox-tests/test-cases/pkg/invalid-opam-repo-errors.t/run.t b/test/blackbox-tests/test-cases/pkg/invalid-opam-repo-errors.t/run.t index 197426b489a3..4ea11919070a 100644 --- a/test/blackbox-tests/test-cases/pkg/invalid-opam-repo-errors.t/run.t +++ b/test/blackbox-tests/test-cases/pkg/invalid-opam-repo-errors.t/run.t @@ -14,11 +14,22 @@ Test the error cases for invalid opam repositories > (source "file://$(pwd)/directory-that-does-not-exist")) > EOF - $ dune pkg lock + $ lock() { + > out="$(dune pkg lock 2>&1)" + > local code="$?" + > printf "[%d]" "$code" + > echo "$out" | sed 's/character.*:/characters X-X:/g' \ + > | sed 's/source ".*"/source ../g' \ + > | grep -v "\^" + > printf "[%d]\n" "$code" + > } + + $ lock + File "dune-workspace", line 6, characters X-X: + 6 | (source ..)) Error: $TESTCASE_ROOT/directory-that-does-not-exist does not exist - [1] $ touch empty $ cat >dune-workspace < (name mock) > (source "file://$(pwd)/empty")) > EOF - $ dune pkg lock + $ lock + File "dune-workspace", line 6, characters X-X: + 6 | (source ..)) Error: $TESTCASE_ROOT/empty is not a directory - [1] $ cat >dune-workspace < (lang dune 3.8) @@ -43,9 +55,10 @@ Test the error cases for invalid opam repositories > (name mock) > (source "file://$(pwd)/no-packages-dir")) > EOF - $ dune pkg lock + $ lock + File "dune-workspace", line 6, characters X-X: + 6 | (source ..)) Error: $TESTCASE_ROOT/no-packages-dir doesn't look like a path to an opam repository as it lacks a subdirectory named "packages" - [1]