@@ -2,6 +2,25 @@ open Import
22module Payload = Template.Pform. Payload
33
44module Var = struct
5+ module Os = struct
6+ type t =
7+ | Os
8+ | Os_version
9+ | Os_distribution
10+ | Os_family
11+
12+ let all = [ Os ; Os_version ; Os_distribution ; Os_family ]
13+
14+ let to_string = function
15+ | Os -> " os"
16+ | Os_version -> " os_version"
17+ | Os_distribution -> " os_distribution"
18+ | Os_family -> " os_family"
19+ ;;
20+
21+ let to_dyn t = Dyn. variant (to_string t) []
22+ end
23+
524 module Pkg = struct
625 module Section = struct
726 type t =
@@ -42,10 +61,7 @@ module Var = struct
4261
4362 type t =
4463 | Switch
45- | Os
46- | Os_version
47- | Os_distribution
48- | Os_family
64+ | Os of Os .t
4965 | Build
5066 | Prefix
5167 | User
@@ -58,11 +74,8 @@ module Var = struct
5874 let compare = Poly. compare
5975
6076 let encode_to_latest_dune_lang_version = function
77+ | Os s -> Os. to_string s
6178 | Switch -> " switch"
62- | Os -> " os"
63- | Os_version -> " os_version"
64- | Os_distribution -> " os_distribution"
65- | Os_family -> " os_family"
6679 | Build -> " build"
6780 | Prefix -> " prefix"
6881 | User -> " user"
@@ -107,6 +120,7 @@ module Var = struct
107120 | Profile
108121 | Context_name
109122 | Os_type
123+ | Os of Os .t
110124 | Architecture
111125 | Arch_sixtyfour
112126 | System
@@ -174,6 +188,7 @@ module Var = struct
174188 | Corrected_suffix -> variant " Corrected_suffix" []
175189 | Inline_tests -> variant " Inline_tests" []
176190 | Toolchain -> variant " Toolchain" []
191+ | Os os -> Os. to_dyn os
177192 | Pkg pkg -> Pkg. to_dyn pkg)
178193 ;;
179194
@@ -184,10 +199,10 @@ module Var = struct
184199 (match name with
185200 | "make" -> Some Make
186201 | "switch" -> Some (Pkg Switch )
187- | "os" -> Some (Pkg Os )
188- | "os-version" -> Some (Pkg Os_version )
189- | "os-distribution" -> Some (Pkg Os_distribution )
190- | "os-family" -> Some (Pkg Os_family )
202+ | "os" -> Some (Pkg ( Os Os ) )
203+ | "os-version" -> Some (Pkg ( Os Os_version ) )
204+ | "os-distribution" -> Some (Pkg ( Os Os_distribution ) )
205+ | "os-family" -> Some (Pkg ( Os Os_family ) )
191206 | "build" -> Some (Pkg Build )
192207 | "prefix" -> Some (Pkg Prefix )
193208 | "user" -> Some (Pkg User )
@@ -484,6 +499,7 @@ let encode_to_latest_dune_lang_version t =
484499 | Corrected_suffix -> Some " corrected-suffix"
485500 | Inline_tests -> Some " inline_tests"
486501 | Toolchain -> Some " toolchain"
502+ | Os os -> Some (Var.Os. to_string os)
487503 | Pkg pkg -> Some (Var.Pkg. encode_to_latest_dune_lang_version pkg)
488504 with
489505 | None -> Pform_was_deleted
@@ -554,10 +570,10 @@ module Env = struct
554570 let vars =
555571 let pkg =
556572 [ " switch" , Var.Pkg. Switch
557- ; " os" , Os
558- ; " os_version" , Os_version
559- ; " os_distribution" , Os_distribution
560- ; " os_family" , Os_family
573+ ; " os" , Os Os
574+ ; " os_version" , Os Os_version
575+ ; " os_distribution" , Os Os_distribution
576+ ; " os_family" , Os Os_family
561577 ; " build" , Build
562578 ; " prefix" , Prefix
563579 ; " user" , User
@@ -685,7 +701,11 @@ module Env = struct
685701 ; " toolchains" , since ~version: (3 , 0 ) Var. Toolchain
686702 ]
687703 in
688- String.Map. of_list_exn (List. concat [ lowercased; uppercased; other ])
704+ let os =
705+ List. map Var.Os. all ~f: (fun v ->
706+ Var.Os. to_string v, since ~version: (3 , 20 ) (Var. Os v))
707+ in
708+ String.Map. of_list_exn (List. concat [ lowercased; uppercased; other; os ])
689709 in
690710 fun syntax_version -> { syntax_version; vars; macros }
691711 ;;
0 commit comments