Skip to content

Commit

Permalink
Use [Config.Toggle] for toolchains (ocaml#10810)
Browse files Browse the repository at this point in the history
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 <stephen@sherra.tt>
  • Loading branch information
gridbugs authored and anmonteiro committed Nov 17, 2024
1 parent a91e23e commit a6eb177
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/dune_config/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/dune_config/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 12 additions & 21 deletions src/dune_rules/pkg_toolchain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit a6eb177

Please sign in to comment.