Skip to content

Commit

Permalink
refactor(pkg): rename [deps] to [depends] (#9762)
Browse files Browse the repository at this point in the history
This is more consistent with how the depends field in dune-project

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored Jan 18, 2024
1 parent 01ee7b7 commit c1f5466
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 68 deletions.
29 changes: 15 additions & 14 deletions src/dune_pkg/lock_dir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,37 @@ module Pkg = struct
type t =
{ build_command : Action.t option
; install_command : Action.t option
; deps : (Loc.t * Package_name.t) list
; depends : (Loc.t * Package_name.t) list
; info : Pkg_info.t
; exported_env : String_with_vars.t Action.Env_update.t list
}

let equal { build_command; install_command; deps; info; exported_env } t =
let equal { build_command; install_command; depends; info; exported_env } t =
Option.equal Action.equal_no_locs build_command t.build_command
&& Option.equal Action.equal_no_locs install_command t.install_command
&& List.equal (Tuple.T2.equal Loc.equal Package_name.equal) deps t.deps
&& List.equal (Tuple.T2.equal Loc.equal Package_name.equal) depends t.depends
&& Pkg_info.equal info t.info
&& List.equal
(Action.Env_update.equal String_with_vars.equal)
exported_env
t.exported_env
;;

let remove_locs { build_command; install_command; deps; info; exported_env } =
let remove_locs { build_command; install_command; depends; info; exported_env } =
{ info = Pkg_info.remove_locs info
; exported_env =
List.map exported_env ~f:(Action.Env_update.map ~f:String_with_vars.remove_locs)
; deps = List.map deps ~f:(fun (_, pkg) -> Loc.none, pkg)
; depends = List.map depends ~f:(fun (_, pkg) -> Loc.none, pkg)
; build_command = Option.map build_command ~f:Action.remove_locs
; install_command = Option.map install_command ~f:Action.remove_locs
}
;;

let to_dyn { build_command; install_command; deps; info; exported_env } =
let to_dyn { build_command; install_command; depends; info; exported_env } =
Dyn.record
[ "build_command", Dyn.option Action.to_dyn build_command
; "install_command", Dyn.option Action.to_dyn install_command
; "deps", Dyn.list (Dyn.pair Loc.to_dyn_hum Package_name.to_dyn) deps
; "depends", Dyn.list (Dyn.pair Loc.to_dyn_hum Package_name.to_dyn) depends
; "info", Pkg_info.to_dyn info
; ( "exported_env"
, Dyn.list (Action.Env_update.to_dyn String_with_vars.to_dyn) exported_env )
Expand All @@ -98,7 +98,7 @@ module Pkg = struct
let version = "version"
let install = "install"
let build = "build"
let deps = "deps"
let depends = "depends"
let source = "source"
let dev = "dev"
let exported_env = "exported_env"
Expand All @@ -112,7 +112,8 @@ module Pkg = struct
@@ let+ version = field Fields.version Package_version.decode
and+ install_command = field_o Fields.install Action.decode_pkg
and+ build_command = field_o Fields.build Action.decode_pkg
and+ deps = field ~default:[] Fields.deps (repeat (located Package_name.decode))
and+ depends =
field ~default:[] Fields.depends (repeat (located Package_name.decode))
and+ source = field_o Fields.source Source.decode
and+ dev = field_b Fields.dev
and+ exported_env =
Expand All @@ -137,7 +138,7 @@ module Pkg = struct
in
{ Pkg_info.name; version; dev; source; extra_sources }
in
{ build_command; deps; install_command; info; exported_env }
{ build_command; depends; install_command; info; exported_env }
;;

let encode_extra_source (local, source) : Dune_sexp.t =
Expand All @@ -150,7 +151,7 @@ module Pkg = struct
let encode
{ build_command
; install_command
; deps
; depends
; info = { Pkg_info.name = _; extra_sources; version; dev; source }
; exported_env
}
Expand All @@ -160,7 +161,7 @@ module Pkg = struct
[ field Fields.version Package_version.encode version
; field_o Fields.install Action.encode install_command
; field_o Fields.build Action.encode build_command
; field_l Fields.deps Package_name.encode (List.map deps ~f:snd)
; field_l Fields.depends Package_name.encode (List.map depends ~f:snd)
; field_o Fields.source Source.encode source
; field_b Fields.dev dev
; field_l Fields.exported_env Action.Env_update.encode exported_env
Expand Down Expand Up @@ -278,7 +279,7 @@ let validate_packages packages =
let missing_dependencies =
Package_name.Map.values packages
|> List.concat_map ~f:(fun (dependant_package : Pkg.t) ->
List.filter_map dependant_package.deps ~f:(fun (loc, dependency) ->
List.filter_map dependant_package.depends ~f:(fun (loc, dependency) ->
if Package_name.Map.mem packages dependency
then None
else Some { dependant_package; dependency; loc }))
Expand Down Expand Up @@ -696,7 +697,7 @@ let transitive_dependency_closure t start =
that its map of dependencies is closed under "depends on". *)
Package_name.Set.(
diff
(of_list_map (Package_name.Map.find_exn t.packages node).deps ~f:snd)
(of_list_map (Package_name.Map.find_exn t.packages node).depends ~f:snd)
seen)
in
push_set unseen_deps;
Expand Down
2 changes: 1 addition & 1 deletion src/dune_pkg/lock_dir.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Pkg : sig
type t =
{ build_command : Action.t option
; install_command : Action.t option
; deps : (Loc.t * Package_name.t) list
; depends : (Loc.t * Package_name.t) list
; info : Pkg_info.t
; exported_env : String_with_vars.t Action.Env_update.t list
}
Expand Down
8 changes: 4 additions & 4 deletions src/dune_pkg/opam_solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ let opam_package_to_lock_file_pkg
in
{ Lock_dir.Pkg_info.name; version; dev; source; extra_sources }
in
let deps =
let depends =
match
Resolve_opam_formula.filtered_formula_to_package_names
~with_test:false
Expand Down Expand Up @@ -642,7 +642,7 @@ let opam_package_to_lock_file_pkg
then `Compiler
else `Non_compiler
in
kind, { Lock_dir.Pkg.build_command; install_command; deps; info; exported_env }
kind, { Lock_dir.Pkg.build_command; install_command; depends; info; exported_env }
;;

let solve_package_list packages context =
Expand Down Expand Up @@ -771,8 +771,8 @@ let solve_lock_dir solver_env version_preference repos ~local_packages ~constrai
in
Package_name.Map.iter
pkgs_by_name
~f:(fun { Lock_dir.Pkg.deps; info = { name; _ }; _ } ->
List.iter deps ~f:(fun (loc, dep_name) ->
~f:(fun { Lock_dir.Pkg.depends; info = { name; _ }; _ } ->
List.iter depends ~f:(fun (loc, dep_name) ->
if Package_name.Map.mem local_packages dep_name
then
User_error.raise
Expand Down
28 changes: 14 additions & 14 deletions src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ module Pkg = struct
{ id : Id.t
; build_command : Dune_lang.Action.t option
; install_command : Dune_lang.Action.t option
; deps : t list
; depends : t list
; info : Pkg_info.t
; paths : Paths.t
; files_dir : Path.Build.t
Expand All @@ -294,12 +294,12 @@ module Pkg = struct

module Top_closure = Top_closure.Make (Id.Set) (Monad.Id)

let top_closure deps =
Top_closure.top_closure deps ~key:(fun t -> t.id) ~deps:(fun t -> t.deps)
let top_closure depends =
Top_closure.top_closure depends ~key:(fun t -> t.id) ~deps:(fun t -> t.depends)
;;

let deps_closure t =
match top_closure t.deps with
match top_closure t.depends with
| Ok s -> s
| Error _ -> assert false
;;
Expand Down Expand Up @@ -422,7 +422,7 @@ module Expander0 = struct
type t =
{ paths : Paths.t
; artifacts : Path.t Filename.Map.t
; deps : (Variable.value Variable_name.Map.t * Paths.t) Package.Name.Map.t
; depends : (Variable.value Variable_name.Map.t * Paths.t) Package.Name.Map.t
; context : Context_name.t
; version : Package_version.t
; env : Value.t list Env.Map.t
Expand Down Expand Up @@ -467,7 +467,7 @@ module Substitute = struct
let paths (p : Paths.t) = p.source_dir, p.target_dir, p.name in
( paths expander.paths
, expander.artifacts
, Package.Name.Map.to_list_map expander.deps ~f:(fun _ (m, p) -> m, paths p)
, Package.Name.Map.to_list_map expander.depends ~f:(fun _ (m, p) -> m, paths p)
, expander.version
, expander.context
, expander.env )
Expand Down Expand Up @@ -736,7 +736,7 @@ module Action_expander = struct
;;

let expand_pform
{ env = _; paths; artifacts = _; context; deps; version = _ }
{ env = _; paths; artifacts = _; context; depends; version = _ }
~source
(pform : Pform.t)
: (Value.t list, [ `Undefined_pkg_var of Variable_name.t ]) result Memo.t
Expand All @@ -753,7 +753,7 @@ module Action_expander = struct
in
Ok [ Value.Path make ]
| Macro ({ macro = Pkg | Pkg_self; _ } as macro_invocation) ->
expand_pkg_macro ~loc paths deps macro_invocation
expand_pkg_macro ~loc paths depends macro_invocation
| _ -> Expander0.isn't_allowed_in_this_position ~source
;;

Expand Down Expand Up @@ -994,7 +994,7 @@ module Action_expander = struct
Pkg.deps_closure pkg |> Artifacts_and_deps.of_closure
in
let env = Pkg.build_env pkg in
let deps =
let depends =
Package.Name.Map.add_exn
dep_info
pkg.info.name
Expand All @@ -1003,7 +1003,7 @@ module Action_expander = struct
{ Expander.paths = pkg.paths
; artifacts = binaries
; context
; deps
; depends
; version = pkg.info.version
; env
}
Expand Down Expand Up @@ -1071,10 +1071,10 @@ end = struct
let resolve_impl ((db : DB.t), ctx, (name : Package.Name.t)) =
match Package.Name.Map.find db.all name with
| None -> Memo.return None
| Some { Lock_dir.Pkg.build_command; install_command; deps; info; exported_env } ->
| Some { Lock_dir.Pkg.build_command; install_command; depends; info; exported_env } ->
assert (Package.Name.equal name info.name);
let* deps =
Memo.parallel_map deps ~f:(fun name ->
let* depends =
Memo.parallel_map depends ~f:(fun name ->
resolve db ctx name
>>| function
| `Inside_lock_dir pkg -> Some pkg
Expand All @@ -1095,7 +1095,7 @@ end = struct
{ Pkg.id
; build_command
; install_command
; deps
; depends
; paths
; info
; files_dir
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/pkg/default-exported-env.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Some environment variables are automatically exported by packages:
$ echo "(version 0.0.1)" > dune.lock/test.pkg
$ cat >dune.lock/usetest.pkg <<'EOF'
> (version 0.0.1)
> (deps test)
> (depends test)
> (build
> (system "\| echo MANPATH=$MANPATH
> "\| echo OCAMLPATH=$OCAMLPATH
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/pkg/exported-env.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Packages can export environment variables
> EOF

$ cat >dune.lock/usetest.pkg <<'EOF'
> (deps test)
> (depends test)
> (version 1.2.3)
> (build
> (progn
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/pkg/file-depends.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Now we make a package depending on file-depends.
$ cat > dune.lock/dep.pkg <<EOF
> (version 0.0.1)
> (deps file-depends)
> (depends file-depends)
> (build
> (system "echo Building dep"))
> EOF
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/pkg/gh8325.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Now it fails since adding the dependency modified PATH.
> (version 0.0.1)
> (source (copy $PWD/test-source))
> ; adding deps breaks cat
> (deps dependency)
> (depends dependency)
> (build
> (system "command -v cat > /dev/null 2>&1 || echo no cat"))
> EOF
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/pkg/installed-binary.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Test that installed binaries are visible in dependent packages

$ cat >dune.lock/usetest.pkg <<EOF
> (version 0.0.1)
> (deps test)
> (depends test)
> (build
> (progn
> (run foo)
Expand Down
14 changes: 7 additions & 7 deletions test/blackbox-tests/test-cases/pkg/lockdir-validation.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ package graph then it's caught when loading the lockdir.

$ cat >dune.lock/a.pkg <<EOF
> (version 0.0.1)
> (deps b)
> (depends b)
> EOF
$ cat >dune.lock/b.pkg <<EOF
> (version 0.0.1)
> (deps c)
> (depends c)
> EOF
$ cat >dune.lock/c.pkg <<EOF
> (version 0.0.1)
> (deps a)
> (depends a)
> EOF

$ dune describe pkg lock
Expand All @@ -27,11 +27,11 @@ package graph then it's caught when loading the lockdir.

$ cat >dune.lock/c.pkg <<EOF
> (version 0.0.1)
> (deps a d)
> (depends a d)
> EOF

$ dune describe pkg lock
File "dune.lock/c.pkg", line 2, characters 8-9:
File "dune.lock/c.pkg", line 2, characters 11-12:
The package "c" depends on the package "d", but "d" does not appear in the
lockdir dune.lock.
Error: At least one package dependency is itself not present as a package in
Expand All @@ -43,10 +43,10 @@ package graph then it's caught when loading the lockdir.
$ rm dune.lock/a.pkg

$ dune describe pkg lock
File "dune.lock/c.pkg", line 2, characters 6-7:
File "dune.lock/c.pkg", line 2, characters 9-10:
The package "c" depends on the package "a", but "a" does not appear in the
lockdir dune.lock.
File "dune.lock/c.pkg", line 2, characters 8-9:
File "dune.lock/c.pkg", line 2, characters 11-12:
The package "c" depends on the package "d", but "d" does not appear in the
lockdir dune.lock.
Error: At least one package dependency is itself not present as a package in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ of "a" that "c" could depend on is "a.0.0.1" which isn't part of the solution.
$ cat dune.lock/c.pkg
(version 0.0.1)

(deps b)
(depends b)
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Print the contents of each file in the lockdir:

(version 0.0.1)

(deps baz bar)
(depends baz bar)


---
Expand Down Expand Up @@ -114,7 +114,7 @@ Run the solver again preferring oldest versions of dependencies:

(version 0.0.1)

(deps baz bar)
(depends baz bar)


---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Demonstrate the translation of filtered dependencies
$ cat dune.lock/bar.pkg
(version 0.0.1)

(deps pkg-build)
(depends pkg-build)
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The exported env from the first package should be in the lock dir.
(run sh -c "echo $append_without_leading_sep")
(run sh -c "echo $append_with_leading_sep")))

(deps with-setenv)
(depends with-setenv)

When building the second package the exported env vars from the first package should be
available and all the env updates should be applied correctly.
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/pkg/opam-solver-or.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Only a1 or a2 should appear but not both.
$ cat dune.lock/b.pkg
(version 0.0.1)

(deps a1)
(depends a1)
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/pkg/opam-var/opam-var-pkg.t
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ corresponding Dune version.
(run echo 41 %{pkg-self:with-dev-setup})
(run echo 42 %{pkg:foo:with-dev-setup})))

(deps foo)
(depends foo)

The values here are not important, but Dune should be able to interpret the variables.

Expand Down
Loading

0 comments on commit c1f5466

Please sign in to comment.