Skip to content

Fix dune targets and dependencies #11570

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

Closed
wants to merge 19 commits 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
6 changes: 3 additions & 3 deletions src/dune_lang/action.mli
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this from the PR.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end

module File_perm : sig
(** File mode, for when creating files. We only allow what Dune takes into
account when memoizing commands. *)
account when memoizing commands. *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this from the PR.


type t = File_perm.t =
| Normal
Expand Down Expand Up @@ -95,8 +95,8 @@ type t =
| Chdir of String_with_vars.t * t
| Setenv of String_with_vars.t * String_with_vars.t * t
(* It's not possible to use a build String_with_vars.t here since jbuild
supports redirecting to /dev/null. In [dune] files this is replaced with
%{null} *)
supports redirecting to /dev/null. In [dune] files this is replaced with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this from the PR.

%{null} *)
| Redirect_out of Outputs.t * String_with_vars.t * File_perm.t * t
| Redirect_in of Inputs.t * String_with_vars.t * t
| Ignore of Outputs.t * t
Expand Down
54 changes: 49 additions & 5 deletions src/dune_lang/pform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module Var = struct
| Arch
| Sys_ocaml_version
| Section_dir of Section.t
| Target of string

let compare = Poly.compare

Expand All @@ -75,6 +76,7 @@ module Var = struct
| Sys_ocaml_version -> variant "Sys_ocaml_version" []
| Section_dir section ->
variant "Section_dir" [ string (Section.to_string section) ]
| Target target -> variant "Target" [ string target ]
;;

let encode_to_latest_dune_lang_version = function
Expand All @@ -91,6 +93,7 @@ module Var = struct
| Arch -> "arch"
| Sys_ocaml_version -> "sys_ocaml_version"
| Section_dir section -> Section.to_string section
| Target target -> target
;;
end

Expand All @@ -102,7 +105,7 @@ module Var = struct
| First_dep
| Deps
| Targets
| Target
| Target of string
| Cc
| Cxx
| Ccomp_type
Expand Down Expand Up @@ -141,9 +144,16 @@ module Var = struct
| Toolchain
| Pkg of Pkg.t

let compare : t -> t -> Ordering.t = Poly.compare
let compare (a : t) (b : t) : Ordering.t =
match a, b with
| Target a, Target b -> String.compare a b
| Target _, _ -> Lt
| _, Target _ -> Gt
| a, b -> Poly.compare a b
;;

let to_dyn = function
| Target name -> Dyn.Variant ("Target", [ String name ])
| User_var v -> Dyn.Variant ("User_var", [ String v ])
| t ->
let open Dyn in
Expand All @@ -155,7 +165,7 @@ module Var = struct
| First_dep -> variant "First_dep" []
| Deps -> variant "Deps" []
| Targets -> variant "Targets" []
| Target -> variant "Target" []
| Target _ -> assert false (* Handled above *)
| Cc -> variant "Cc" []
| Cxx -> variant "Cxx" []
| Ccomp_type -> variant "Ccomp_type" []
Expand Down Expand Up @@ -465,7 +475,7 @@ let encode_to_latest_dune_lang_version t =
| First_dep -> None
| Deps -> Some "deps"
| Targets -> Some "targets"
| Target -> Some "target"
| Target _ -> Some "target"
| Cc -> Some "cc"
| Cxx -> Some "cxx"
| Ccomp_type -> Some "ccomp_type"
Expand Down Expand Up @@ -654,7 +664,8 @@ module Env = struct
in
let other : (string * Var.t With_versioning_info.t) list =
[ "targets", since ~version:(1, 0) Var.Targets
; "target", since ~version:(1, 11) Var.Target
; "target", since ~version:(1, 11) (Var.Target "")
(* or some appropriate default value *)
; "deps", since ~version:(1, 0) Var.Deps
; "project_root", since ~version:(1, 0) Var.Project_root
; ( "<"
Expand Down Expand Up @@ -816,3 +827,36 @@ module Env = struct
~f:(fun _ _ _ -> assert false)
;;
end

let parse_target_var s =
match String.split_on_char ~sep:':' s with
| [ "target"; name ] -> Some (Var (Var.Target name))
| [ "targets" ] -> Some (Var Var.Targets)
| _ -> None
;;

let parse_pkg_target_var s =
match String.split_on_char ~sep:':' s with
| [ "pkg"; pkg_name; "target"; target_name ] ->
Some (Var.Pkg.Target (pkg_name ^ ":" ^ target_name))
| [ "pkg"; pkg_name; section ] ->
(match Var.Pkg.Section.of_string section with
| Some section -> Some (Var.Pkg.Section_dir section)
| None -> Some (Var.Pkg.Target (pkg_name ^ ":" ^ section)))
| [ "pkg"; var ] ->
(match var with
| "switch" -> Some Var.Pkg.Switch
| "os" -> Some Var.Pkg.Os
| "os_version" -> Some Var.Pkg.Os_version
| "os_distribution" -> Some Var.Pkg.Os_distribution
| "os_family" -> Some Var.Pkg.Os_family
| "build" -> Some Var.Pkg.Build
| "prefix" -> Some Var.Pkg.Prefix
| "user" -> Some Var.Pkg.User
| "group" -> Some Var.Pkg.Group
| "jobs" -> Some Var.Pkg.Jobs
| "arch" -> Some Var.Pkg.Arch
| "sys_ocaml_version" -> Some Var.Pkg.Sys_ocaml_version
| target -> Some (Var.Pkg.Target target))
| _ -> None
;;
6 changes: 5 additions & 1 deletion src/dune_lang/pform.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Var : sig
| Arch
| Sys_ocaml_version
| Section_dir of Section.t
| Target of string

val compare : t -> t -> Ordering.t
val to_dyn : t -> Dyn.t
Expand All @@ -47,7 +48,7 @@ module Var : sig
| First_dep
| Deps
| Targets
| Target
| Target of string
| Cc
| Cxx
| Ccomp_type
Expand Down Expand Up @@ -207,3 +208,6 @@ module Env : sig
val to_stamp : t -> stamp
val to_dyn : t -> Dyn.t
end

val parse_target_var : string -> t option
val parse_pkg_target_var : string -> Var.Pkg.t option
22 changes: 11 additions & 11 deletions src/dune_lang/string_with_vars.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val add_user_vars_to_decoding_env
-> ('a, 'k) Decoder.parser

(** [t] generated by the OCaml code. The first argument should be [__POS__].
[quoted] says whether the string is quoted ([false] by default). *)
[quoted] says whether the string is quoted ([false] by default). *)
val virt_pform : ?quoted:bool -> string * int * int * int -> Pform.t -> t

val virt_text : string * int * int * int -> string -> t
Expand All @@ -57,12 +57,12 @@ val pform_only : t -> Pform.t option

module Mode : sig
(** How many values expansion of a template must produce.

The caller always knows which of the contexts below it requires, therefore
it can specify this to the expansion functions. This allows us to return a
precise result type from the expansion, and do some validation to make
sure we aren't expanding into multiple values in cases where it's not
allowed. *)
The caller always knows which of the contexts below it requires, therefore
it can specify this to the expansion functions. This allows us to return a
precise result type from the expansion, and do some validation to make
sure we aren't expanding into multiple values in cases where it's not
allowed. *)
type (_, _) t =
| Single : (Value.Deferred_concat.t, Value.t) t
(** Expansion must produce a single value *)
Expand Down Expand Up @@ -104,8 +104,8 @@ module type Expander = sig
type 'a app

(** [expand ~f] attempts to expand all percent forms in a template. If [f]
returns [None] for any variable (no substitution was found), then this
function will raise. *)
returns [None] for any variable (no substitution was found), then this
function will raise. *)
val expand
: t
-> mode:(_, 'value) Mode.t
Expand All @@ -114,7 +114,7 @@ module type Expander = sig
-> 'value app

(** Behaves the same as [expand] except the pform expander [f] returns a
result and errors are propagated *)
result and errors are propagated *)
val expand_result
: t
-> mode:(_, 'value) Mode.t
Expand All @@ -129,7 +129,7 @@ module type Expander = sig
-> ('deferred_concat, 'error) result app

(** [expand_as_much_as_possible] expands all variables for which [f] returns
[None] and left other unexpanded. *)
[None] and left other unexpanded. *)
val expand_as_much_as_possible
: t
-> dir:Path.t
Expand Down
Loading