Skip to content

Commit

Permalink
fix(pkg): [Context.which] should look up packages in lock dir (#8744)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Sep 23, 2023
1 parent 5e23b37 commit 51183c0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/dune_rules/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ and t =
; default_ocamlpath : Path.t list
; build_context : Build_context.t
; builder : builder
; which : Filename.t -> Path.t option Memo.t
}

module Builder = struct
Expand Down Expand Up @@ -181,7 +182,7 @@ let profile t = t.builder.profile
let equal x y = Context_name.equal x.builder.name y.builder.name
let hash t = Context_name.hash t.builder.name
let build_context t = t.build_context
let which t fname = Which.which ~path:t.builder.path fname
let which t fname = t.which fname
let host t = Option.value ~default:t t.builder.for_host
let name t = t.builder.name
let path t = t.builder.path
Expand Down Expand Up @@ -490,6 +491,7 @@ let create (builder : Builder.t) ~(kind : Kind.t) =
; findlib_paths = ocamlpath @ default_ocamlpath
; default_ocamlpath
; build_context = Build_context.create ~name:builder.name
; which
}
;;

Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ let file_of_lib db context ~loc ~lib ~file =
in
let pkg_root =
let package = Lib_name.package_name name in
(* Why do we return the install path? *)
Install.Context.lib_dir ~context:(Context.name context) ~package
in
Path.build (Path.Build.append_local pkg_root subdir)
Expand Down
7 changes: 1 addition & 6 deletions test/blackbox-tests/test-cases/pkg/installed-binary.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,4 @@ It should also be visible in the workspace:
> EOF

$ dune build ./testout && cat _build/default/testout
File "dune", line 2, characters 30-40:
2 | (with-stdout-to testout (run %{bin:foo})))
^^^^^^^^^^
Error: Program foo not found in the tree or in PATH
(context: default)
[1]
from test package
21 changes: 7 additions & 14 deletions test/blackbox-tests/test-cases/pkg/pkg-deps.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ We should be able to specify (package ..) deps on locally built packages.
> (install
> (progn
> (run mkdir -p %{prefix}/bin)
> (run touch %{prefix}/bin/foo)))
> (run touch %{prefix}/bin/foo)
> (run chmod +x %{prefix}/bin/foo)))
> EOF

$ cat >dune <<EOF
$ cat >dune <<'EOF'
> (dirs :standard \ external_sources)
> (rule
> (alias foo)
Expand All @@ -26,12 +27,8 @@ We should be able to specify (package ..) deps on locally built packages.
> EOF

$ dune build @foo
File "dune", line 7, characters 9-19:
7 | (echo %{bin:foo})))
^^^^^^^^^^
Error: Program foo not found in the tree or in PATH
(context: default)
[1]
$TESTCASE_ROOT/_build/_private/default/.pkg/foo/target/bin/foo
../_private/default/.pkg/foo/target/bin/foo

Now we define the external package using a dune project:

Expand All @@ -53,9 +50,5 @@ Now we define the external package using a dune project:
> (build (run dune build @install --promote-install-files))
> EOF
$ dune build @foo
File "dune", line 7, characters 9-19:
7 | (echo %{bin:foo})))
^^^^^^^^^^
Error: Program foo not found in the tree or in PATH
(context: default)
[1]
$TESTCASE_ROOT/_build/_private/default/.pkg/foo/target/bin/foo
../_private/default/.pkg/foo/target/bin/foo

0 comments on commit 51183c0

Please sign in to comment.