Skip to content
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
2 changes: 2 additions & 0 deletions doc/changes/added/12832.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- support expanding variables in `(promote (into ..))` (#12832, fixes #12742,
@anmonteiro)
1 change: 1 addition & 0 deletions src/dune_lang/dune_lang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module Menhir_env = Menhir_env
module Dune_env = Dune_env
module Js_of_ocaml = Js_of_ocaml
module Menhir = Menhir
module Rule_mode = Rule_mode
module Rule_mode_decoder = Rule_mode_decoder
module Mode_conf = Mode_conf
module Oxcaml = Oxcaml
Expand Down
26 changes: 26 additions & 0 deletions src/dune_lang/rule_mode.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Import
module Rule = Dune_engine.Rule

module Promote = struct
module Into = struct
type t =
{ loc : Loc.t
; dir : String_with_vars.t
}
end

type t =
{ lifetime : Rule.Promote.Lifetime.t
; into : Into.t option
; only : Filename.t Predicate.t option
}
end

type t =
| Standard
| Fallback (** Only use this rule if the source files don't exist. *)
| Promote of Promote.t (** Silently promote the targets to the source tree. *)
| Ignore_source_files
(** Just ignore the source files entirely. This is for cases where the
targets are promoted only in a specific context, such as for
.install files. *)
25 changes: 25 additions & 0 deletions src/dune_lang/rule_mode.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
open Import

module Promote : sig
module Into : sig
type t =
{ loc : Loc.t
; dir : String_with_vars.t
}
end

type t =
{ lifetime : Dune_engine.Rule.Promote.Lifetime.t
; into : Into.t option
; only : Filename.t Predicate.t option
}
end

type t =
| Standard
| Fallback (** Only use this rule if the source files don't exist. *)
| Promote of Promote.t (** Silently promote the targets to the source tree. *)
| Ignore_source_files
(** Just ignore the source files entirely. This is for cases where the
targets are promoted only in a specific context, such as for
.install files. *)
22 changes: 11 additions & 11 deletions src/dune_lang/rule_mode_decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module Rule = Dune_engine.Rule

module Promote = struct
let into_decode =
let+ loc, dir = located relative_file in
{ Rule.Promote.Into.loc; dir }
let+ loc, dir = located String_with_vars.decode in
{ Rule_mode.Promote.Into.loc; dir }
;;

let decode : Rule.Promote.t Decoder.t =
let decode : Rule_mode.Promote.t Decoder.t =
fields
(let+ until_clean =
field_b "until-clean" ~check:(Syntax.since Stanza.syntax (1, 10))
Expand All @@ -20,27 +20,27 @@ module Promote = struct
Option.map only ~f:(fun only ->
Predicate.create (Predicate_lang.Glob.test only ~standard:Predicate_lang.true_))
in
{ Rule.Promote.lifetime = (if until_clean then Until_clean else Unlimited)
{ Rule_mode.Promote.lifetime = (if until_clean then Until_clean else Unlimited)
; into
; only
})
;;
end

let mode_decoders =
[ "standard", return Rule.Mode.Standard
; "fallback", return Rule.Mode.Fallback
[ "standard", return Rule_mode.Standard
; "fallback", return Rule_mode.Fallback
; ( "promote"
, let+ p = Promote.decode in
Rule.Mode.Promote p )
Rule_mode.Promote p )
; ( "promote-until-clean"
, let+ () =
Syntax.deleted_in
Stanza.syntax
(3, 0)
~extra_info:"Use the (promote (until-clean)) syntax instead."
in
Rule.Mode.Promote { lifetime = Until_clean; into = None; only = None } )
Rule_mode.Promote { lifetime = Until_clean; into = None; only = None } )
; ( "promote-into"
, let+ () = Syntax.since Stanza.syntax (1, 8)
and+ () =
Expand All @@ -49,7 +49,7 @@ let mode_decoders =
(3, 0)
~extra_info:"Use the (promote (into <dir>)) syntax instead."
and+ into = Promote.into_decode in
Rule.Mode.Promote { lifetime = Unlimited; into = Some into; only = None } )
Rule_mode.Promote { lifetime = Unlimited; into = Some into; only = None } )
; ( "promote-until-clean-into"
, let+ () = Syntax.since Stanza.syntax (1, 8)
and+ () =
Expand All @@ -58,9 +58,9 @@ let mode_decoders =
(3, 0)
~extra_info:"Use the (promote (until-clean) (into <dir>)) syntax instead."
and+ into = Promote.into_decode in
Rule.Mode.Promote { lifetime = Until_clean; into = Some into; only = None } )
Rule_mode.Promote { lifetime = Until_clean; into = Some into; only = None } )
]
;;

let decode = sum mode_decoders
let field = field "mode" decode ~default:Rule.Mode.Standard
let field = field "mode" decode ~default:Rule_mode.Standard
9 changes: 4 additions & 5 deletions src/dune_lang/rule_mode_decoder.mli
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
open Import
module Rule := Dune_engine.Rule

module Promote : sig
val decode : Rule.Promote.t Decoder.t
val into_decode : Rule.Promote.Into.t Decoder.t
val decode : Rule_mode.Promote.t Decoder.t
val into_decode : Rule_mode.Promote.Into.t Decoder.t
end

val decode : Rule.Mode.t Decoder.t
val field : Rule.Mode.t Decoder.fields_parser
val decode : Rule_mode.t Decoder.t
val field : Rule_mode.t Decoder.fields_parser
4 changes: 2 additions & 2 deletions src/dune_lang/stanzas/copy_files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type origin =
type t =
{ add_line_directive : bool
; alias : Alias_name.t option
; mode : Rule.Mode.t
; mode : Rule_mode.t
; enabled_if : Blang.t
; files : String_with_vars.t
; only_sources : Blang.t
Expand All @@ -32,7 +32,7 @@ let decode_only_sources =
let long_form =
let check = Syntax.since Stanza.syntax (2, 7) in
let+ alias = field_o "alias" (check >>> Alias.decode)
and+ mode = field "mode" ~default:Rule.Mode.Standard (check >>> Rule_mode_decoder.decode)
and+ mode = field "mode" ~default:Rule_mode.Standard (check >>> Rule_mode_decoder.decode)
and+ enabled_if = Enabled_if.decode ~allowed_vars:Any ~since:(Some (2, 8)) ()
and+ files = field "files" (check >>> String_with_vars.decode)
and+ only_sources =
Expand Down
2 changes: 1 addition & 1 deletion src/dune_lang/stanzas/copy_files.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type origin =
type t =
{ add_line_directive : bool
; alias : Alias_name.t option
; mode : Dune_engine.Rule.Mode.t
; mode : Rule_mode.t
; enabled_if : Blang.t
; files : String_with_vars.t
; only_sources : Blang.t
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Mask = struct

let is_promoted_rule =
let is_promoted_mode version = function
| Rule.Mode.Promote { only = None; lifetime; _ } ->
| Rule_mode.Promote { only = None; lifetime; _ } ->
if version >= (3, 5)
then (
match lifetime with
Expand Down
19 changes: 10 additions & 9 deletions src/dune_rules/exe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,17 @@ let link_exe
; Dyn link_args
]
>>| Action.Full.add_sandbox sandbox
and* mode =
let sctx = Compilation_context.super_context cctx in
let* expander = Super_context.expander sctx ~dir in
let rule_mode =
match promote with
| None -> Rule_mode.Standard
| Some p -> Promote p
in
Rule_mode_expand.expand_path ~expander ~dir rule_mode
in
Super_context.add_rule
sctx
~loc
~dir
~mode:
(match promote with
| None -> Standard
| Some p -> Promote p)
action_with_targets
Super_context.add_rule sctx ~loc ~dir ~mode action_with_targets
;;

let link_js
Expand Down
6 changes: 3 additions & 3 deletions src/dune_rules/exe.mli
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ val link_many
-> ?sandbox:Sandbox_config.t
-> programs:Program.t list
-> linkages:Linkage.t list
-> promote:Rule.Promote.t option
-> promote:Rule_mode.Promote.t option
-> Compilation_context.t
-> dep_graphs Memo.t

Expand All @@ -74,7 +74,7 @@ val build_and_link
-> ?sandbox:Sandbox_config.t
-> program:Program.t
-> linkages:Linkage.t list
-> promote:Rule.Promote.t option
-> promote:Rule_mode.Promote.t option
-> Compilation_context.t
-> dep_graphs Memo.t

Expand All @@ -85,7 +85,7 @@ val build_and_link_many
-> ?sandbox:Sandbox_config.t
-> programs:Program.t list
-> linkages:Linkage.t list
-> promote:Rule.Promote.t option
-> promote:Rule_mode.Promote.t option
-> Compilation_context.t
-> dep_graphs Memo.t

Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ include struct
module Js_of_ocaml = Js_of_ocaml
module Copy_files = Copy_files
module Enabled_if = Enabled_if
module Rule_mode = Rule_mode
module Rule_mode_decoder = Rule_mode_decoder
module Alias_conf = Alias_conf
module Stanza_pkg = Stanza_pkg
Expand Down
12 changes: 8 additions & 4 deletions src/dune_rules/jsoo/jsoo_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,14 @@ let build_exe
(Path.Build.set_extension src ~ext:(Js_of_ocaml.Ext.runtime ~mode))
]
in
let rule_mode : Rule.Mode.t =
match promote with
| None -> Standard
| Some p -> Promote p
let* rule_mode : Rule.Mode.t =
let* expander = Super_context.expander sctx ~dir in
let rule_mode =
match promote with
| None -> Rule_mode.Standard
| Some p -> Promote p
in
Rule_mode_expand.expand_path ~expander ~dir rule_mode
in
let* cmode =
match compilation_mode with
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/jsoo/jsoo_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val build_exe
-> src:Path.Build.t
-> obj_dir:Path.Build.t Obj_dir.t
-> top_sorted_modules:Module.t list Action_builder.t
-> promote:Rule.Promote.t option
-> promote:Rule_mode.Promote.t option
-> linkall:bool Action_builder.t
-> link_time_code_gen:Link_time_code_gen_type.t Resolve.t
-> jsoo_mode:Js_of_ocaml.Mode.t
Expand Down
Loading
Loading