From 7fc6f4383d2786a5ea88da8d4722b1934aa39699 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Thu, 8 Aug 2024 19:18:46 +1000 Subject: [PATCH] Use [Config.Toggle] for toolchains (#10810) This changes the variable that enables toolchains from DUNE_CONFIG__TOOLCHAINS_ENABLED=[true|false] to DUNE_CONFIG__TOOLCHAINS=[enabled|disabled], following the established convention for such variables in dune, and for compatibility with upcoming support for compile-time configuration. Signed-off-by: Stephen Sherratt --- src/dune_config/config.ml | 1 + src/dune_config/config.mli | 2 ++ src/dune_rules/pkg_toolchain.ml | 33 +++++++------------ .../test-cases/pkg/toolchain-installation.t | 2 +- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/dune_config/config.ml b/src/dune_config/config.ml index fb9dc69e6c0..1ec1ef3313c 100644 --- a/src/dune_config/config.ml +++ b/src/dune_config/config.ml @@ -85,6 +85,7 @@ let make ~name ~of_string ~default = t ;; +let make_toggle ~name ~default = make ~name ~default ~of_string:Toggle.of_string let global_lock = make ~name:"global_lock" ~of_string:Toggle.of_string ~default:`Enabled let cutoffs_that_reduce_concurrency_in_watch_mode = diff --git a/src/dune_config/config.mli b/src/dune_config/config.mli index b43559bfc25..4c1d3944aaa 100644 --- a/src/dune_config/config.mli +++ b/src/dune_config/config.mli @@ -26,6 +26,8 @@ end parsed using [of_string], defaulting to [default]. *) val make : name:string -> of_string:(string -> ('a, string) result) -> default:'a -> 'a t +val make_toggle : name:string -> default:Toggle.t -> Toggle.t t + (** [get t] return the value of the configuration for [t] *) val get : 'a t -> 'a diff --git a/src/dune_rules/pkg_toolchain.ml b/src/dune_rules/pkg_toolchain.ml index 3e86c44bc7e..b98b4b7b03a 100644 --- a/src/dune_rules/pkg_toolchain.ml +++ b/src/dune_rules/pkg_toolchain.ml @@ -18,17 +18,7 @@ let base_dir () = path ;; -let make_bool ~name ~default = - let of_string s = - match Bool.of_string s with - | Some b -> Ok b - | None -> - Error (sprintf "%s is not a bool (must be \"true\" or \"false\")" (String.quoted s)) - in - Config.make ~name ~of_string ~default -;; - -let enabled = make_bool ~name:"toolchains_enabled" ~default:false +let enabled = Config.make_toggle ~name:"toolchains" ~default:`Disabled let pkg_dir (pkg : Dune_pkg.Lock_dir.Pkg.t) = (* The name of this package's directory within the toolchains @@ -53,16 +43,17 @@ let pkg_dir (pkg : Dune_pkg.Lock_dir.Pkg.t) = let installation_prefix ~pkg_dir = Path.Outside_build_dir.relative pkg_dir "target" let is_compiler_and_toolchains_enabled name = - Config.get enabled - && - let module Package_name = Dune_pkg.Package_name in - let compiler_package_names = - (* TODO don't hardcode these names here *) - [ Package_name.of_string "ocaml-base-compiler" - ; Package_name.of_string "ocaml-variants" - ] - in - List.mem compiler_package_names name ~equal:Package_name.equal + match Config.get enabled with + | `Enabled -> + let module Package_name = Dune_pkg.Package_name in + let compiler_package_names = + (* TODO don't hardcode these names here *) + [ Package_name.of_string "ocaml-base-compiler" + ; Package_name.of_string "ocaml-variants" + ] + in + List.mem compiler_package_names name ~equal:Package_name.equal + | `Disabled -> false ;; let files ~bin_dir = diff --git a/test/blackbox-tests/test-cases/pkg/toolchain-installation.t b/test/blackbox-tests/test-cases/pkg/toolchain-installation.t index 976f50cdd85..97d7efcafdf 100644 --- a/test/blackbox-tests/test-cases/pkg/toolchain-installation.t +++ b/test/blackbox-tests/test-cases/pkg/toolchain-installation.t @@ -78,7 +78,7 @@ name so the output is consistent across test runs. Attempt to build the project. This will fail due to the fake compiler but the fake compiler will end up installed as a toolchain package. - $ XDG_CACHE_HOME=$PWD/fake-cache DUNE_CONFIG__TOOLCHAINS_ENABLED=true dune build 2>&1 | remove_hash + $ XDG_CACHE_HOME=$PWD/fake-cache DUNE_CONFIG__TOOLCHAINS=enabled dune build 2>&1 | remove_hash Error: Failed to parse the output of '$TESTCASE_ROOT/fake-cache/dune/toolchains/ocaml-base-compiler.1-HASH/target/bin/ocamlc -config':