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

pkg: defer evaluating platform vars in commands #11475

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/dune_lang/package_variable_name.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ let post = of_string "post"
let one_of t xs = List.mem xs ~equal t
let dev = of_string "dev"

let platform_specific =
Set.of_list [ arch; os; os_version; os_distribution; os_family; sys_ocaml_version ]
;;

module Project = struct
let encode name = Dune_sexp.Encoder.string (":" ^ to_string name)

Expand Down
4 changes: 4 additions & 0 deletions src/dune_lang/package_variable_name.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ val build : t
val dev : t
val one_of : t -> t list -> bool

(** The set of variable names whose values are expected to differ depending on
the current platform. *)
val platform_specific : Set.t

module Project : sig
val encode : t Dune_sexp.Encoder.t
val decode : t Dune_sexp.Decoder.t
Expand Down
15 changes: 12 additions & 3 deletions src/dune_pkg/opam_solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1736,9 +1736,18 @@ let opam_package_to_lock_file_pkg
| [] -> action
| env_update -> Action.Withenv (env_update, action)
in
let get_solver_var variable_name =
Solver_stats.Updater.expand_variable stats_updater variable_name;
Solver_env.get solver_env variable_name
let get_solver_var =
(* Remove platform-specific variables from the solver env so that the
generated commands are portable rather than specialized to the computer
performing the solve. *)
let portable_solver_env =
Solver_env.unset_multi solver_env Package_variable_name.platform_specific
in
fun variable_name ->
let value = Solver_env.get portable_solver_env variable_name in
if Option.is_some value
then Solver_stats.Updater.expand_variable stats_updater variable_name;
value
in
let build_command =
if Resolved_package.dune_build resolved_package
Expand Down
3 changes: 3 additions & 0 deletions src/dune_pkg/solver_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ val extend : t -> t -> t
val with_defaults : t

val pp : t -> 'a Pp.t

(** Remove a set of bindings from the env *)
val unset_multi : t -> Package_variable_name.Set.t -> t

val to_env : t -> OpamFilter.env
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,18 @@ stored in the lockdir metadata:
(version 0.0.1)

(install
(run echo qux))
(when
(= %{arch} arm)
(run echo qux)))

(build
(progn
(run echo foo)
(when
(= %{os} linux)
(run echo foo))
(when
(= %{os} macos)
(run echo bar))
(run echo baz)))
$ cat dune.lock/lock.dune
(lang package 0.1)
Expand All @@ -154,9 +161,3 @@ stored in the lockdir metadata:
(repositories
(complete false)
(used))

(expanded_solver_variable_bindings
(variable_values
(os linux)
(arch arm))
(unset_variables x))
Loading