Skip to content

Commit

Permalink
fix(pkg): improve locations for local path repos (#9670)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 9a1ab9a0-d6f5-49c3-af68-ace2a8029a6c -->
  • Loading branch information
rgrinberg authored Jan 10, 2024
1 parent 0df4bc2 commit e7bbb5e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/pkg/pkg_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 7 additions & 1 deletion src/dune_pkg/opam_repo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,34 +134,40 @@ 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
match Path.stat packages with
| 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\""
(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) ]);
{ source = Directory opam_repo_dir_path; serializable = None }
;;
Expand Down
2 changes: 1 addition & 1 deletion src/dune_pkg/opam_repo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ 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="$?"
> 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
Expand All @@ -29,7 +40,9 @@ Test the error cases for invalid opam repositories
> (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
Expand All @@ -43,7 +56,9 @@ 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
Expand Down

0 comments on commit e7bbb5e

Please sign in to comment.