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>
  • Loading branch information
anmonteiro committed Mar 25, 2023
1 parent ba131b1 commit 507fc48
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 35 deletions.
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name repro_main)
(public_name repro-main)
(name repro)
(public_name repro)
(modules foo))
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
(generate_opam_files true)

(package
(name repro-main)
(name repro)
(depends
(ocaml
(>= 4.12.0))
dune-site)
(sites
(share libs))
(synopsis "Repro main"))

(package
(name repro-libs)
(depends repro-main)
(synopsis "Repro libs"))
45 changes: 26 additions & 19 deletions test/blackbox-tests/test-cases/cross-compilation-install.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@
$ export OCAMLFIND_CONF=$PWD/etc/findlib.conf


$ dune build --display short --promote-install-files=false -p repro-main @install -x foo
ocamlc .repro_main.objs/byte/repro_main.{cmi,cmo,cmt} [default.foo]
ocamldep .repro_main.objs/repro_main__Foo.impl.d [default.foo]
ocamlopt .repro_main.objs/native/repro_main.{cmx,o} [default.foo]
ocamlc .repro_main.objs/byte/repro_main__Foo.{cmi,cmo,cmt} [default.foo]
ocamlopt .repro_main.objs/native/repro_main__Foo.{cmx,o} [default.foo]
ocamlc repro_main.cma [default.foo]
ocamlopt repro_main.{a,cmxa} [default.foo]
ocamlopt repro_main.cmxs [default.foo]
$ dune build --display short -p repro --promote-install-files=false @install -x foo
x: _build/default/repro.install
x: _build/default.foo/repro-foo.install
ocamlc .repro.objs/byte/repro.{cmi,cmo,cmt} [default.foo]
ocamldep .repro.objs/repro__Foo.impl.d [default.foo]
ocamlopt .repro.objs/native/repro.{cmx,o} [default.foo]
ocamlc .repro.objs/byte/repro__Foo.{cmi,cmo,cmt} [default.foo]
ocamlopt .repro.objs/native/repro__Foo.{cmx,o} [default.foo]
ocamlc repro.cma [default.foo]
ocamlopt repro.{a,cmxa} [default.foo]
ocamlopt repro.cmxs [default.foo]

$ ls | grep *.install
repro-main-foo.install

$ dune install --prefix prefix --display short -p repro-main --create-install-files repro-main -x foo
x: repro-main.install
Error: The following <package>.install are missing:
- _build/default/repro-main.install
- _build/default.foo/repro-main.install
Hint: try running: dune build [-p <pkg>] @install
[1]
$ dune install --prefix prefix --display short -p repro -x foo
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 507fc48

Please sign in to comment.