1
1
open Stdune
2
2
open Dune_sexp
3
3
open Dune_util.Action
4
- open Pform.Macro
5
- open Pform
6
-
7
- module Named_targets = struct
8
- type t = (string * String_with_vars .t ) list
9
- end
10
4
11
5
module Action_plugin = struct
12
6
let syntax =
@@ -18,55 +12,6 @@ module Action_plugin = struct
18
12
;;
19
13
end
20
14
21
- module Pform = struct
22
- module Var = struct
23
- type t =
24
- | Values
25
- | Loc
26
- | C_flags
27
- | Cxx_flags
28
- | Cpp_flags
29
- | Target of string (* New variant for named targets *)
30
- | Ocaml
31
- | Ocamlc
32
- | Ocamlopt
33
- | Ocamldep
34
- | Ocamlmklib
35
- | Dev_null
36
- | Null
37
- | Ext_obj
38
- | Ext_asm
39
- | Ext_lib
40
- | Ext_dll
41
- | Ext_exe
42
- | Ext_plugin
43
- | Profile
44
- | Context_name
45
- | Os_type
46
- | Architecture
47
- | System
48
- | Model
49
- | Ignoring_promoted_rules
50
- | Project_root
51
- | Workspace_root
52
- | Build_context
53
- | First_dep
54
- | Input_file
55
- | Library_name
56
- | Partition
57
- | Impl_files
58
- | Intf_files
59
- | Test
60
- | Corrected_suffix
61
- | Inline_tests
62
- | Toolchain
63
-
64
- let compare = compare
65
- end
66
-
67
- type t = Var of Var .t
68
- end
69
-
70
15
module Diff = struct
71
16
include Diff
72
17
@@ -163,7 +108,7 @@ module Env_update = struct
163
108
164
109
type 'a t =
165
110
{ op : Op .t
166
- ; var : Var .t
111
+ ; var : Env. Var.t
167
112
; value : 'a
168
113
}
169
114
@@ -175,36 +120,28 @@ module Env_update = struct
175
120
{ op = other_op ; var = other_var ; value = other_value }
176
121
=
177
122
Op. equal op other_op
178
- && Var. compare var other_var = Ordering. Eq
123
+ && Ordering. is_eq ( Env. Var. compare var other_var)
179
124
&& value_equal value other_value
180
125
;;
181
126
182
127
let to_dyn value_to_dyn { op; var; value } =
183
- Dyn. record [ " op" , Op. to_dyn op; " var" , Var. to_dyn var; " value" , value_to_dyn value ]
128
+ Dyn. record
129
+ [ " op" , Op. to_dyn op; " var" , Env.Var. to_dyn var; " value" , value_to_dyn value ]
184
130
;;
185
131
186
132
let decode =
187
133
let open Decoder in
188
134
let env_update_op = enum Op. all in
189
135
let + op, var, value = triple env_update_op string String_with_vars. decode in
190
- { op; var = Var. User_var var ; value }
136
+ { op; var; value }
191
137
;;
192
138
193
139
let encode { op; var; value } =
194
- let op_str =
140
+ let op =
195
141
List. find_map Op. all ~f: (fun (k , v ) -> if Poly. equal v op then Some k else None )
196
142
|> Option. value_exn
197
143
in
198
- let var_str =
199
- match var with
200
- | Var. User_var s -> s
201
- | Var. Target -> " target"
202
- | _ ->
203
- (* Handle other cases or raise an error *)
204
- Code_error. raise " Action.encode: unsupported variable" []
205
- in
206
- Dune_sexp. List
207
- [ Dune_sexp. atom op_str; Dune_sexp. atom var_str; String_with_vars. encode value ]
144
+ List [ atom op; atom var; String_with_vars. encode value ]
208
145
;;
209
146
end
210
147
@@ -241,12 +178,6 @@ type t =
241
178
| When of Slang .blang * t
242
179
| Format_dune_file of String_with_vars .t * String_with_vars .t
243
180
244
- type expansion_context =
245
- { dir : Path .t
246
- ; named_targets : (string * String_with_vars .t ) list
247
- ; named_deps : (string * Dep_conf .t ) list
248
- }
249
-
250
181
let is_dev_null t = String_with_vars. is_pform t (Var Dev_null )
251
182
252
183
let translate_to_ignore fn output action =
@@ -255,59 +186,6 @@ let translate_to_ignore fn output action =
255
186
else Redirect_out (output, fn, Normal , action)
256
187
;;
257
188
258
- let expand_str ~context sw =
259
- let module S = String_with_vars in
260
- match S. text_only sw with
261
- | Some s -> s
262
- | None ->
263
- let expand_var = function
264
- | Pform. Var (Var. User_var name ) ->
265
- (* Fixed pattern *)
266
- (match List. assoc_opt name context.named_targets with
267
- | Some target -> S. to_string target
268
- | None ->
269
- (match List. assoc_opt name context.named_deps with
270
- | Some dep -> Dep_conf. to_string dep
271
- | None ->
272
- User_error. raise
273
- ~loc: (S. loc sw)
274
- [ Pp. textf " Undefined variable %%{%s}" name
275
- ; Pp. text " Available variables:"
276
- ; Pp. enumerate
277
- (List. map
278
- (context.named_targets @ context.named_deps)
279
- ~f: (fun (n , _ ) -> n))
280
- ]))
281
- | Pform. Var Var. Target ->
282
- (* Correct pattern *)
283
- (match List. assoc_opt " target" context.named_targets with
284
- | Some target -> S. to_string target
285
- | None ->
286
- User_error. raise ~loc: (S. loc sw) [ Pp. text " Undefined target %{target}" ])
287
- | Pform. Var other_var ->
288
- (* Handle other built-in variables *)
289
- S. to_string (S. make_var (S. loc sw) (Pform. Var other_var))
290
- | Pform. Macro macro ->
291
- (* Handle macros *)
292
- S. to_string (S. make_var (S. loc sw) (Pform. Macro macro))
293
- in
294
- S. expand sw ~f: expand_var
295
- ;;
296
-
297
- let create_action targets action =
298
- let named_targets =
299
- List. filter_map targets ~f: (fun (target , _ , name ) ->
300
- Option. map name ~f: (fun n -> n, target))
301
- in
302
- { action with
303
- expansion_context =
304
- { dir = Path. root
305
- ; named_targets
306
- ; named_deps = [] (* Will be populated from rule.deps later *)
307
- }
308
- }
309
- ;;
310
-
311
189
let two_or_more decode =
312
190
let open Decoder in
313
191
let + n1 = decode
@@ -377,21 +255,6 @@ let decode_with_accepted_exit_codes =
377
255
]
378
256
;;
379
257
380
- let decode_rule =
381
- let open Decoder in
382
- let + targets =
383
- repeat
384
- (let * target = String_with_vars. decode in
385
- let * name = optional string in
386
- return (target, () , name))
387
- and + deps = field " deps" (Bindings. decode Dep_conf. decode) ~default: Bindings. empty
388
- and + action = decode_dune_file in
389
- let rule = create_action targets action in
390
- { rule with
391
- expansion_context = { rule.expansion_context with named_deps = Bindings. to_list deps }
392
- }
393
- ;;
394
-
395
258
let sw = String_with_vars. decode
396
259
397
260
let cstrs_dune_file t =
@@ -768,4 +631,4 @@ let decode_pkg = make_decode decode_pkg
768
631
let to_dyn a = to_dyn (encode a)
769
632
let equal x y = Poly. equal x y
770
633
let chdir dir t = Chdir (dir, t)
771
- let run prog args = Run (Slang. Literal prog :: List. map args ~f: (fun x -> Slang. Literal x))
634
+ let run prog args = Run (Slang. Literal prog :: List. map args ~f: (fun x -> Slang. Literal x))
0 commit comments