Skip to content

Commit e23e2cf

Browse files
committed
Add %{toolchain} variable
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent 7079536 commit e23e2cf

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased
22
----------
33

4+
- Add a `%{toolchain}` expansion variable (#4899, fixes #3949, @rgrinberg)
5+
46
- Include dependencies of executables when creating toplevels (either `dune
57
top` or `dune utop`) (#4882, fixes #4872, @Gopiancode)
68

src/dune_engine/pform.ml

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Var = struct
4444
| Test
4545
| Corrected_suffix
4646
| Inline_tests
47+
| Toolchain
4748

4849
let compare : t -> t -> Ordering.t = Poly.compare
4950

@@ -94,6 +95,7 @@ module Var = struct
9495
| Test -> "Test"
9596
| Corrected_suffix -> "Corrected_suffix"
9697
| Inline_tests -> "Inline_tests"
98+
| Toolchain -> "Toolchain"
9799
in
98100
Dyn.Variant (cstr, [])
99101
end
@@ -285,6 +287,7 @@ let encode_to_latest_dune_lang_version t =
285287
| Test -> Some "test"
286288
| Corrected_suffix -> Some "corrected-suffix"
287289
| Inline_tests -> Some "inline_tests"
290+
| Toolchain -> Some "toolchain"
288291
with
289292
| None -> Pform_was_deleted
290293
| Some name -> Success { name; payload = None })
@@ -469,6 +472,7 @@ module Env = struct
469472
; ("input-file", since ~version:(1, 0) Var.Input_file)
470473
; ("corrected-suffix", No_info Corrected_suffix)
471474
; ("inline_tests", No_info Inline_tests)
475+
; ("toolchains", since ~version:(3, 0) Var.Toolchain)
472476
]
473477
in
474478
String.Map.of_list_exn (List.concat [ lowercased; uppercased; other ])

src/dune_engine/pform.mli

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Var : sig
4444
| Test
4545
| Corrected_suffix
4646
| Inline_tests
47+
| Toolchain
4748

4849
val compare : t -> t -> Ordering.t
4950

src/dune_rules/expander.ml

+10-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,16 @@ let expand_pform_gen ~(context : Context.t) ~bindings ~dir ~source
371371
| Ccomp_type ->
372372
static
373373
(string
374-
(Ocaml_config.Ccomp_type.to_string context.lib_config.ccomp_type)))
374+
(Ocaml_config.Ccomp_type.to_string context.lib_config.ccomp_type))
375+
| Toolchain ->
376+
static
377+
(string
378+
(match context.findlib_toolchain with
379+
| Some toolchain -> Context_name.to_string toolchain
380+
| None ->
381+
let loc = Dune_lang.Template.Pform.loc source in
382+
User_error.raise ~loc
383+
[ Pp.text "No toolchain defined for this context" ])))
375384
| Macro (macro, s) -> (
376385
match macro with
377386
| Ocaml_config ->

0 commit comments

Comments
 (0)