Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use [Config.Toggle] for toolchains #10810

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading