Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pkg): improve locations for local path repos #9670

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading