diff --git a/src/dune_engine/section.ml b/src/dune_engine/section.ml index dd04a532ec56..b16e22b6f07d 100644 --- a/src/dune_engine/section.ml +++ b/src/dune_engine/section.ml @@ -3,23 +3,30 @@ include Dune_section let compare : t -> t -> Ordering.t = Poly.compare +let allmap = + [ ("lib", Lib) + ; ("lib_root", Lib_root) + ; ("libexec", Libexec) + ; ("libexec_root", Libexec_root) + ; ("bin", Bin) + ; ("sbin", Sbin) + ; ("toplevel", Toplevel) + ; ("share", Share) + ; ("share_root", Share_root) + ; ("etc", Etc) + ; ("doc", Doc) + ; ("stublibs", Stublibs) + ; ("man", Man) + ; ("misc", Misc) + ] + let to_dyn x = + let s = + List.find_map ~f:(fun (s, v) -> Option.some_if (x = v) s) allmap + |> Option.value_exn + in let open Dyn.Encoder in - match x with - | Lib -> constr "Lib" [] - | Lib_root -> constr "Lib_root" [] - | Libexec -> constr "Libexec" [] - | Libexec_root -> constr "Libexec_root" [] - | Bin -> constr "Bin" [] - | Sbin -> constr "Sbin" [] - | Toplevel -> constr "Toplevel" [] - | Share -> constr "Share" [] - | Share_root -> constr "Share_root" [] - | Etc -> constr "Etc" [] - | Doc -> constr "Doc" [] - | Stublibs -> constr "Stublibs" [] - | Man -> constr "Man" [] - | Misc -> constr "Misc" [] + constr (String.uppercase_ascii s) [] module Key = struct type nonrec t = t @@ -40,44 +47,13 @@ let parse_string s = let decode = let open Dune_lang.Decoder in - enum - [ ("lib", Lib) - ; ("lib_root", Lib_root) - ; ("libexec", Libexec) - ; ("libexec_root", Libexec_root) - ; ("bin", Bin) - ; ("sbin", Sbin) - ; ("toplevel", Toplevel) - ; ("share", Share) - ; ("share_root", Share_root) - ; ("etc", Etc) - ; ("doc", Doc) - ; ("stublibs", Stublibs) - ; ("man", Man) - ; ("misc", Misc) - ] + enum allmap let encode v = let open Dune_lang.Encoder in string (to_string v) -let all = - Set.of_list - [ Lib - ; Lib_root - ; Libexec - ; Libexec_root - ; Bin - ; Sbin - ; Toplevel - ; Share - ; Share_root - ; Etc - ; Doc - ; Stublibs - ; Man - ; Misc - ] +let all = Set.of_list (List.map ~f:snd allmap) let should_set_executable_bit = function | Lib