Skip to content

Commit df4399b

Browse files
authored
refactor: allow setting workspace root in execution parameters (#8535)
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent ba6dfed commit df4399b

9 files changed

Lines changed: 68 additions & 39 deletions

File tree

src/dune_engine/action_exec.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,15 +668,15 @@ let exec
668668
and eenv =
669669
let env =
670670
match
671-
Execution_parameters.add_workspace_root_to_build_path_prefix_map
672-
execution_parameters
671+
Execution_parameters.workspace_root_to_build_path_prefix_map execution_parameters
673672
with
674-
| false -> env
675-
| true ->
673+
| Unset -> env
674+
| Set target ->
676675
Dune_util.Build_path_prefix_map.extend_build_path_prefix_map
677676
env
678677
`New_rules_have_precedence
679-
[ Some { source = Path.to_absolute_filename root; target = "/workspace_root" } ]
678+
(* TODO generify *)
679+
[ Some { source = Path.to_absolute_filename root; target } ]
680680
in
681681
{ working_dir = Path.root
682682
; env

src/dune_engine/build_system.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ end = struct
235235

236236
(* The current version of the rule digest scheme. We should increment it when
237237
making any changes to the scheme, to avoid collisions. *)
238-
let rule_digest_version = 15
238+
let rule_digest_version = 16
239239

240240
let compute_rule_digest
241241
(rule : Rule.t)
@@ -270,8 +270,8 @@ end = struct
270270
, List.map locks ~f:Path.to_string
271271
, Execution_parameters.action_stdout_on_success execution_parameters
272272
, Execution_parameters.action_stderr_on_success execution_parameters
273-
, Execution_parameters.add_workspace_root_to_build_path_prefix_map
274-
execution_parameters )
273+
, Execution_parameters.workspace_root_to_build_path_prefix_map execution_parameters
274+
)
275275
in
276276
Digest.generic trace
277277
;;

src/dune_engine/execution_parameters.ml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,33 @@ module Action_output_limit = struct
2727
let equal = Int.equal
2828
end
2929

30+
module Workspace_root_for_build_prefix_map = struct
31+
type t =
32+
| Unset
33+
| Set of string
34+
35+
let equal x y =
36+
match x, y with
37+
| Unset, Unset -> true
38+
| Unset, _ | _, Unset -> false
39+
| Set x, Set y -> String.equal x y
40+
;;
41+
42+
let to_dyn =
43+
let open Dyn in
44+
function
45+
| Unset -> variant "Unset" []
46+
| Set s -> variant "Set" [ string s ]
47+
;;
48+
end
49+
3050
type t =
3151
{ action_stdout_on_success : Action_output_on_success.t
3252
; action_stderr_on_success : Action_output_on_success.t
3353
; action_stdout_limit : Action_output_limit.t
3454
; action_stderr_limit : Action_output_limit.t
3555
; expand_aliases_in_sandbox : bool
36-
; add_workspace_root_to_build_path_prefix_map : bool
56+
; workspace_root_to_build_path_prefix_map : Workspace_root_for_build_prefix_map.t
3757
; should_remove_write_permissions_on_generated_files : bool
3858
}
3959

@@ -43,7 +63,7 @@ let equal
4363
; action_stdout_limit
4464
; action_stderr_limit
4565
; expand_aliases_in_sandbox
46-
; add_workspace_root_to_build_path_prefix_map
66+
; workspace_root_to_build_path_prefix_map
4767
; should_remove_write_permissions_on_generated_files
4868
}
4969
t
@@ -53,9 +73,9 @@ let equal
5373
&& Action_output_limit.equal action_stdout_limit t.action_stdout_limit
5474
&& Action_output_limit.equal action_stderr_limit t.action_stderr_limit
5575
&& Bool.equal expand_aliases_in_sandbox t.expand_aliases_in_sandbox
56-
&& Bool.equal
57-
add_workspace_root_to_build_path_prefix_map
58-
t.add_workspace_root_to_build_path_prefix_map
76+
&& Workspace_root_for_build_prefix_map.equal
77+
workspace_root_to_build_path_prefix_map
78+
t.workspace_root_to_build_path_prefix_map
5979
&& Bool.equal
6080
should_remove_write_permissions_on_generated_files
6181
t.should_remove_write_permissions_on_generated_files
@@ -67,7 +87,7 @@ let hash
6787
; action_stdout_limit
6888
; action_stderr_limit
6989
; expand_aliases_in_sandbox
70-
; add_workspace_root_to_build_path_prefix_map
90+
; workspace_root_to_build_path_prefix_map
7191
; should_remove_write_permissions_on_generated_files
7292
}
7393
=
@@ -77,7 +97,7 @@ let hash
7797
, action_stdout_limit
7898
, action_stderr_limit
7999
, expand_aliases_in_sandbox
80-
, add_workspace_root_to_build_path_prefix_map
100+
, workspace_root_to_build_path_prefix_map
81101
, should_remove_write_permissions_on_generated_files )
82102
;;
83103

@@ -87,7 +107,7 @@ let to_dyn
87107
; action_stdout_limit
88108
; action_stderr_limit
89109
; expand_aliases_in_sandbox
90-
; add_workspace_root_to_build_path_prefix_map
110+
; workspace_root_to_build_path_prefix_map
91111
; should_remove_write_permissions_on_generated_files
92112
}
93113
=
@@ -97,8 +117,9 @@ let to_dyn
97117
; "action_stdout_limit", Action_output_limit.to_dyn action_stdout_limit
98118
; "action_stderr_limit", Action_output_limit.to_dyn action_stderr_limit
99119
; "expand_aliases_in_sandbox", Bool expand_aliases_in_sandbox
100-
; ( "add_workspace_root_to_build_path_prefix_map"
101-
, Bool add_workspace_root_to_build_path_prefix_map )
120+
; ( "workspace_root_to_build_path_prefix_map"
121+
, Workspace_root_for_build_prefix_map.to_dyn workspace_root_to_build_path_prefix_map
122+
)
102123
; ( "should_remove_write_permissions_on_generated_files"
103124
, Bool should_remove_write_permissions_on_generated_files )
104125
]
@@ -110,7 +131,7 @@ let builtin_default =
110131
; action_stdout_limit = Action_output_limit.default
111132
; action_stderr_limit = Action_output_limit.default
112133
; expand_aliases_in_sandbox = true
113-
; add_workspace_root_to_build_path_prefix_map = true
134+
; workspace_root_to_build_path_prefix_map = Set "/workspace_root"
114135
; should_remove_write_permissions_on_generated_files = true
115136
}
116137
;;
@@ -121,20 +142,16 @@ let set_action_stdout_limit x t = { t with action_stdout_limit = x }
121142
let set_action_stderr_limit x t = { t with action_stderr_limit = x }
122143
let set_expand_aliases_in_sandbox x t = { t with expand_aliases_in_sandbox = x }
123144

124-
let set_add_workspace_root_to_build_path_prefix_map x t =
125-
{ t with add_workspace_root_to_build_path_prefix_map = x }
145+
let set_workspace_root_to_build_path_prefix_map x t =
146+
{ t with workspace_root_to_build_path_prefix_map = x }
126147
;;
127148

128149
let set_should_remove_write_permissions_on_generated_files x t =
129150
{ t with should_remove_write_permissions_on_generated_files = x }
130151
;;
131152

132153
let expand_aliases_in_sandbox t = t.expand_aliases_in_sandbox
133-
134-
let add_workspace_root_to_build_path_prefix_map t =
135-
t.add_workspace_root_to_build_path_prefix_map
136-
;;
137-
154+
let workspace_root_to_build_path_prefix_map t = t.workspace_root_to_build_path_prefix_map
138155
let action_stdout_on_success t = t.action_stdout_on_success
139156
let action_stderr_on_success t = t.action_stderr_on_success
140157
let action_stdout_limit t = t.action_stdout_limit

src/dune_engine/execution_parameters.mli

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,25 @@ end
4949

5050
(** {1 Constructors} *)
5151

52+
(** Set the workspace root directory for the build prefix map, if desired. *)
53+
module Workspace_root_for_build_prefix_map : sig
54+
type t =
55+
| Unset (** Do not set the workspace root; only used by external Dune rules *)
56+
| Set of string (** [Set root] substitute the root with [root] *)
57+
end
58+
5259
val builtin_default : t
5360
val set_action_stdout_on_success : Action_output_on_success.t -> t -> t
5461
val set_action_stderr_on_success : Action_output_on_success.t -> t -> t
5562
val set_action_stdout_limit : Action_output_limit.t -> t -> t
5663
val set_action_stderr_limit : Action_output_limit.t -> t -> t
5764
val set_expand_aliases_in_sandbox : bool -> t -> t
58-
val set_add_workspace_root_to_build_path_prefix_map : bool -> t -> t
59-
val add_workspace_root_to_build_path_prefix_map : t -> bool
65+
66+
val set_workspace_root_to_build_path_prefix_map
67+
: Workspace_root_for_build_prefix_map.t
68+
-> t
69+
-> t
70+
6071
val set_should_remove_write_permissions_on_generated_files : bool -> t -> t
6172

6273
(** As configured by [init] *)
@@ -70,6 +81,7 @@ val action_stdout_on_success : t -> Action_output_on_success.t
7081
val action_stderr_on_success : t -> Action_output_on_success.t
7182
val action_stdout_limit : t -> Action_output_limit.t
7283
val action_stderr_limit : t -> Action_output_limit.t
84+
val workspace_root_to_build_path_prefix_map : t -> Workspace_root_for_build_prefix_map.t
7385

7486
(** {1 Initialisation} *)
7587

src/dune_rules/dune_project.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,8 @@ let info t = t.info
10791079
let update_execution_parameters t ep =
10801080
ep
10811081
|> Execution_parameters.set_expand_aliases_in_sandbox t.expand_aliases_in_sandbox
1082-
|> Execution_parameters.set_add_workspace_root_to_build_path_prefix_map
1083-
t.map_workspace_root
1082+
|> Execution_parameters.set_workspace_root_to_build_path_prefix_map
1083+
(if t.map_workspace_root then Set "/workspace_root" else Unset)
10841084
|> Execution_parameters.set_should_remove_write_permissions_on_generated_files
10851085
(t.dune_version >= (2, 4))
10861086
;;

test/blackbox-tests/test-cases/dune-cache/mode-copy.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ never built [target1] before.
4040
$ dune build --config-file=config target1 --debug-cache=shared,workspace-local \
4141
> 2>&1 | grep '_build/default/source\|_build/default/target'
4242
Workspace-local cache miss: _build/default/source: never seen this target before
43-
Shared cache miss [a0435a82f38c0cb32e265a22d1f9e08c] (_build/default/source): not found in cache
43+
Shared cache miss [9acd3a08d49c004c7c4af47984604b5c] (_build/default/source): not found in cache
4444
Workspace-local cache miss: _build/default/target1: never seen this target before
45-
Shared cache miss [25faf482a530be4a0e4efbd8e38411f5] (_build/default/target1): not found in cache
45+
Shared cache miss [c8ba5d0ce97e5b84d90b24999e54d106] (_build/default/target1): not found in cache
4646

4747
$ dune_cmd stat hardlinks _build/default/source
4848
1

test/blackbox-tests/test-cases/dune-cache/mode-hardlink.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ never built [target1] before.
3535
$ dune build --config-file=config target1 --debug-cache=shared,workspace-local \
3636
> 2>&1 | grep '_build/default/source\|_build/default/target'
3737
Workspace-local cache miss: _build/default/source: never seen this target before
38-
Shared cache miss [b134f8385a83866193d82617babc213e] (_build/default/source): not found in cache
38+
Shared cache miss [4971137801799003aa6e088963677239] (_build/default/source): not found in cache
3939
Workspace-local cache miss: _build/default/target1: never seen this target before
40-
Shared cache miss [bd1e628609440e4bf23adfd96baa7548] (_build/default/target1): not found in cache
40+
Shared cache miss [967c475fcb42c969b0a32a612f7f8918] (_build/default/target1): not found in cache
4141

4242
$ dune_cmd stat hardlinks _build/default/source
4343
3

test/blackbox-tests/test-cases/dune-cache/repro-check.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Set 'cache-check-probability' to 1.0, which should trigger the check
6767
> EOF
6868
$ rm -rf _build
6969
$ dune build --config-file config reproducible non-reproducible
70-
Warning: cache store error [a37871748f60d220bd4536190e1620c4]: ((in_cache
70+
Warning: cache store error [9c0ced5efcd85d0a6c5364bee242c3a2]: ((in_cache
7171
((non-reproducible 1c8fc4744d4cef1bd2b8f5e915b36be9))) (computed
7272
((non-reproducible 6cfaa7a90747882bcf4ffe7252c1cf89)))) after executing
7373
(echo 'build non-reproducible';cp dep non-reproducible)
@@ -119,7 +119,7 @@ Test that the environment variable and the command line flag work too
119119

120120
$ rm -rf _build
121121
$ DUNE_CACHE_CHECK_PROBABILITY=1.0 dune build --cache=enabled reproducible non-reproducible
122-
Warning: cache store error [a37871748f60d220bd4536190e1620c4]: ((in_cache
122+
Warning: cache store error [9c0ced5efcd85d0a6c5364bee242c3a2]: ((in_cache
123123
((non-reproducible 1c8fc4744d4cef1bd2b8f5e915b36be9))) (computed
124124
((non-reproducible 6cfaa7a90747882bcf4ffe7252c1cf89)))) after executing
125125
(echo 'build non-reproducible';cp dep non-reproducible)
@@ -131,7 +131,7 @@ Test that the environment variable and the command line flag work too
131131

132132
$ rm -rf _build
133133
$ dune build --cache=enabled --cache-check-probability=1.0 reproducible non-reproducible
134-
Warning: cache store error [a37871748f60d220bd4536190e1620c4]: ((in_cache
134+
Warning: cache store error [9c0ced5efcd85d0a6c5364bee242c3a2]: ((in_cache
135135
((non-reproducible 1c8fc4744d4cef1bd2b8f5e915b36be9))) (computed
136136
((non-reproducible 6cfaa7a90747882bcf4ffe7252c1cf89)))) after executing
137137
(echo 'build non-reproducible';cp dep non-reproducible)

test/blackbox-tests/test-cases/dune-cache/trim.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ entries uniformly.
7878

7979
$ (cd "$PWD/.xdg-cache/dune/db/meta/v5"; grep -rws . -e 'metadata' | sort ) > out
8080
$ cat out
81-
./00/005056244c2ed30e70b9cafe3a820bbe:((8:metadata)(5:files(8:target_a32:5637dd9730e430c7477f52d46de3909c)))
82-
./93/931ec90aa8ac4a33a5af177649ff8b71:((8:metadata)(5:files(8:target_b32:8a53bfae3829b48866079fa7f2d97781)))
81+
./25/259be1c0c7a2f2eab4f17969ff8486f5:((8:metadata)(5:files(8:target_a32:5637dd9730e430c7477f52d46de3909c)))
82+
./f2/f280f0a3c487ec316e741894b164691a:((8:metadata)(5:files(8:target_b32:8a53bfae3829b48866079fa7f2d97781)))
8383

8484
$ digest="$(awk -F: '/target_b/ { digest=$1 } END { print digest }' < out)"
8585

0 commit comments

Comments
 (0)