Skip to content

Commit d393ddf

Browse files
Add dependency on dune path to action
Signed-off-by: Marek Kubica <marek@tarides.com>
1 parent 8329dcc commit d393ddf

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

src/dune_rules/pkg_rules.ml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,14 @@ module Action_expander = struct
986986
| Path p | Dir p -> Path p))
987987
in
988988
let ocamlfind_destdir = (Lazy.force expander.paths.install_roots).lib_root in
989+
let dune_exe = Path.of_string Sys.executable_name in
989990
Run_with_path.action
990991
~depexts
991992
~pkg:(expander.name, prog_loc)
992993
exe
993994
args
994-
~ocamlfind_destdir)
995+
~ocamlfind_destdir
996+
~dune_exe)
995997
| Progn t ->
996998
let+ args = Memo.parallel_map t ~f:(expand ~expander) in
997999
Action.Progn args
@@ -1143,15 +1145,33 @@ module Action_expander = struct
11431145

11441146
let sandbox = Sandbox_mode.Set.singleton Sandbox_mode.copy
11451147

1148+
let rec action_contains_run action =
1149+
match (action : Dune_lang.Action.t) with
1150+
| Run _ -> true
1151+
| Progn actions -> actions |> List.find ~f:action_contains_run |> Option.is_some
1152+
| When (_, action) -> action_contains_run action
1153+
| Withenv (_, action) -> action_contains_run action
1154+
| _ -> false
1155+
;;
1156+
11461157
let expand context (pkg : Pkg.t) action =
1158+
let depend_on_dune =
1159+
match action_contains_run action with
1160+
| false -> Action_builder.return ()
1161+
| true ->
1162+
Path.External.of_string Sys.executable_name
1163+
|> Path.external_
1164+
|> Action_builder.path
1165+
in
11471166
let+ action =
11481167
let expander = expander context pkg in
11491168
expand action ~expander >>| Action.chdir pkg.paths.source_dir
11501169
in
11511170
(* TODO copying is needed for build systems that aren't dune and those
11521171
with an explicit install step *)
1153-
Action.Full.make ~sandbox action
1154-
|> Action_builder.return
1172+
let open Action_builder.O in
1173+
depend_on_dune
1174+
>>> (Action.Full.make ~sandbox action |> Action_builder.return)
11551175
|> Action_builder.with_no_targets
11561176
;;
11571177

src/dune_rules/run_with_path.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module Spec = struct
8484
{ prog : ('path, Action.Prog.Not_found.t) result
8585
; args : 'path arg Array.Immutable.t
8686
; ocamlfind_destdir : 'path
87+
; dune_exe : 'path
8788
; pkg : Dune_pkg.Package_name.t * Loc.t
8889
; depexts : string list
8990
}
@@ -101,13 +102,16 @@ module Spec = struct
101102
{ t with
102103
args = Array.Immutable.map t.args ~f:(map_arg ~f)
103104
; ocamlfind_destdir = f t.ocamlfind_destdir
105+
; dune_exe = f t.dune_exe
104106
; prog = Result.map t.prog ~f
105107
}
106108
;;
107109

108110
let is_useful_to ~memoize:_ = true
109111

110-
let encode { prog; args; ocamlfind_destdir; pkg = _; depexts = _ } path _ : Sexp.t =
112+
let encode { prog; args; ocamlfind_destdir; dune_exe; pkg = _; depexts = _ } path _
113+
: Sexp.t
114+
=
111115
let prog : Sexp.t =
112116
match prog with
113117
| Ok p -> path p
@@ -120,11 +124,11 @@ module Spec = struct
120124
| String s -> Sexp.Atom s
121125
| Path p -> path p)))
122126
in
123-
List [ List ([ prog ] @ args); path ocamlfind_destdir ]
127+
List [ List ([ prog ] @ args); path ocamlfind_destdir; path dune_exe ]
124128
;;
125129

126130
let action
127-
{ prog; args; ocamlfind_destdir; pkg; depexts }
131+
{ prog; args; ocamlfind_destdir; dune_exe; pkg; depexts }
128132
~(ectx : Action.context)
129133
~(eenv : Action.env)
130134
=
@@ -144,8 +148,7 @@ module Spec = struct
144148
let dune_folder =
145149
let bin_folder = Temp.create Dir ~prefix:"dune" ~suffix:"self-in-path" in
146150
let dst = Path.relative bin_folder "dune" in
147-
let src = Path.of_string Sys.executable_name in
148-
Io.portable_symlink ~src ~dst;
151+
Io.portable_symlink ~src:dune_exe ~dst;
149152
Path.to_string bin_folder
150153
in
151154
let env =
@@ -188,6 +191,6 @@ end
188191

189192
module A = Action_ext.Make (Spec)
190193

191-
let action ~pkg ~depexts prog args ~ocamlfind_destdir =
192-
A.action { Spec.prog; args; ocamlfind_destdir; pkg; depexts }
194+
let action ~pkg ~depexts prog args ~ocamlfind_destdir ~dune_exe =
195+
A.action { Spec.prog; args; ocamlfind_destdir; dune_exe; pkg; depexts }
193196
;;

src/dune_rules/run_with_path.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ val action
2020
-> Action.Prog.t
2121
-> Path.t Spec.arg Array.Immutable.t
2222
-> ocamlfind_destdir:Path.t
23+
-> dune_exe:Path.t
2324
-> Action.t

0 commit comments

Comments
 (0)