Skip to content

Commit

Permalink
fix(x-compilation): only install the context passed to -x
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
anmonteiro authored and rgrinberg committed Mar 26, 2023
1 parent 203fe02 commit 7533eb9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Fix `dune install` when cross compiling (#7410, fixes #6191, @anmonteiro,
@rizo)

- Dune in watch mode no longer builds concurrent rules in serial (#7395
@rgrinberg, @jchavarri)

Expand Down
2 changes: 2 additions & 0 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,8 @@ let root t = t.root

let watch t = t.builder.watch

let x t = t.builder.workspace_config.x

let print_metrics t = t.builder.print_metrics

let dump_memo_graph_file t = t.builder.dump_memo_graph_file
Expand Down
2 changes: 2 additions & 0 deletions bin/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ open Stdune

type t

val x : t -> Dune_engine.Context_name.t option

val capture_outputs : t -> bool

val root : t -> Workspace_root.t
Expand Down
36 changes: 28 additions & 8 deletions bin/install_uninstall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module Workspace = struct
and+ contexts = Context.DB.all () in
{ packages = conf.packages; contexts })

let package_install_file t pkg =
let package_install_file t ~findlib_toolchain pkg =
match Package.Name.Map.find t.packages pkg with
| None -> Error ()
| Some p ->
Expand All @@ -82,11 +82,11 @@ module Workspace = struct
Ok
(Path.Source.relative dir
(Dune_rules.Install_rules.install_file ~package:name
~findlib_toolchain:None))
~findlib_toolchain))
end

let resolve_package_install workspace pkg =
match Workspace.package_install_file workspace pkg with
let resolve_package_install workspace ~findlib_toolchain pkg =
match Workspace.package_install_file workspace ~findlib_toolchain pkg with
| Ok path -> path
| Error () ->
let pkg = Package.Name.to_string pkg in
Expand Down Expand Up @@ -573,7 +573,19 @@ let install_uninstall ~what =
let* workspace = Workspace.get () in
let contexts =
match context with
| None -> workspace.contexts
| None -> (
match Common.x common with
| Some findlib_toolchain ->
let contexts =
List.filter workspace.contexts ~f:(fun (ctx : Context.t) ->
match ctx.findlib_toolchain with
| None -> false
| Some ctx_findlib_toolchain ->
Dune_engine.Context_name.equal ctx_findlib_toolchain
findlib_toolchain)
in
contexts
| None -> workspace.contexts)
| Some name -> (
match
List.find workspace.contexts ~f:(fun c ->
Expand All @@ -599,9 +611,14 @@ let install_uninstall ~what =
in
let install_files, missing_install_files =
List.concat_map pkgs ~f:(fun pkg ->
let fn = resolve_package_install workspace pkg in
List.map contexts ~f:(fun (ctx : Context.t) ->
let fn = Path.append_source (Path.build ctx.build_dir) fn in
let fn =
let fn =
resolve_package_install workspace
~findlib_toolchain:ctx.findlib_toolchain pkg
in
Path.append_source (Path.build ctx.build_dir) fn
in
if Path.exists fn then Left (ctx, (pkg, fn)) else Right fn))
|> List.partition_map ~f:Fun.id
in
Expand Down Expand Up @@ -755,7 +772,10 @@ let install_uninstall ~what =
Fiber.return entry)
in
if create_install_files then
let fn = resolve_package_install workspace package in
let fn =
resolve_package_install workspace
~findlib_toolchain:context.findlib_toolchain package
in
Io.write_file (Path.source fn)
(Install.gen_install_file entries)))
in
Expand Down
21 changes: 15 additions & 6 deletions test/blackbox-tests/test-cases/cross-compilation-install.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ Installing a library with `-x foo` should install the library for that context

$ dune build @install -x foo

$ dune install --dry-run --prefix prefix --display short -p repro -x foo
Error: The following <package>.install are missing:
- _build/default/repro.install
- _build/default.foo/repro.install
Hint: try running: dune build [-p <pkg>] @install
[1]
$ dune install --dry-run --prefix prefix --display short -p repro -x foo 2>&1 | grep "Installing"
Installing prefix/foo-sysroot/lib/repro/META
Installing prefix/foo-sysroot/lib/repro/dune-package
Installing prefix/foo-sysroot/lib/repro/foo.ml
Installing prefix/foo-sysroot/lib/repro/repro.a
Installing prefix/foo-sysroot/lib/repro/repro.cma
Installing prefix/foo-sysroot/lib/repro/repro.cmi
Installing prefix/foo-sysroot/lib/repro/repro.cmt
Installing prefix/foo-sysroot/lib/repro/repro.cmx
Installing prefix/foo-sysroot/lib/repro/repro.cmxa
Installing prefix/foo-sysroot/lib/repro/repro.ml
Installing prefix/foo-sysroot/lib/repro/repro__Foo.cmi
Installing prefix/foo-sysroot/lib/repro/repro__Foo.cmt
Installing prefix/foo-sysroot/lib/repro/repro__Foo.cmx
Installing prefix/foo-sysroot/lib/repro/repro.cmxs

0 comments on commit 7533eb9

Please sign in to comment.