Skip to content

Commit

Permalink
refactor(rules): remove support for patch back into source tree
Browse files Browse the repository at this point in the history
It was never allowed in the public rules without a special toggle and
there was never any use for it. It was only added b/c it was available
in the JS fork. No need to keep it around.

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: e004ffe8-5e6c-41bd-9e3c-daf693ace63a -->
  • Loading branch information
rgrinberg committed Jul 28, 2024
1 parent 8a60342 commit a046cb9
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 90 deletions.
33 changes: 0 additions & 33 deletions src/dune_rules/rule_mode_decoder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,5 @@ let mode_decoders =
]
;;

module Extended = struct
type t =
| Normal of Rule.Mode.t
| Patch_back_source_tree

let patch_back_from_source_tree_syntax =
Dune_lang.Syntax.create
~experimental:true
~name:"patch-back-source-tree"
~desc:"experimental support for (mode patch-back-source-tree)"
[ (0, 1), `Since (3, 0) ]
;;

let () =
Dune_project.Extension.register_simple
patch_back_from_source_tree_syntax
(Dune_lang.Decoder.return [])
;;

let decode =
sum
(( "patch-back-source-tree"
, let+ () = Dune_lang.Syntax.since patch_back_from_source_tree_syntax (0, 1) in
Patch_back_source_tree )
:: List.map mode_decoders ~f:(fun (name, dec) ->
( name
, let+ x = dec in
Normal x )))
;;

let field = field "mode" decode ~default:(Normal Standard)
end

let decode = sum mode_decoders
let field = field "mode" decode ~default:Rule.Mode.Standard
8 changes: 0 additions & 8 deletions src/dune_rules/rule_mode_decoder.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,5 @@ module Promote : sig
val into_decode : Rule.Promote.Into.t Dune_lang.Decoder.t
end

module Extended : sig
type t =
| Normal of Rule.Mode.t
| Patch_back_source_tree

val field : t Dune_lang.Decoder.fields_parser
end

val decode : Rule.Mode.t Dune_lang.Decoder.t
val field : Rule.Mode.t Dune_lang.Decoder.fields_parser
15 changes: 1 addition & 14 deletions src/dune_rules/simple_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule_conf.t) =
~targets
~targets_dir:dir
in
if rule.patch_back_source_tree
then
Action_builder.With_targets.map action ~f:(fun action ->
(* Here we expect that [action.sandbox] is [Sandbox_config.default]
because the parsing of [rule] stanzas forbids having both a
sandboxing setting in [deps] and a [patch_back_source_tree] field
at the same time.
If we didn't have this restriction and [action.sandbox] was
something that didn't permit [Some Patch_back_source_tree], Dune
would crash in a way that would be difficult for the user to
understand. *)
Action.Full.add_sandbox Sandbox_mode.Set.patch_back_source_tree_only action)
else action
action
in
(match rule_kind ~rule ~action with
| No_alias ->
Expand Down
35 changes: 2 additions & 33 deletions src/dune_rules/stanzas/rule_conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type t =
; deps : Dep_conf.t Bindings.t
; action : Loc.t * Dune_lang.Action.t
; mode : Rule.Mode.t
; patch_back_source_tree : bool
; locks : Locks.t
; loc : Loc.t
; enabled_if : Blang.t
Expand Down Expand Up @@ -73,7 +72,6 @@ let short_form =
; deps = Bindings.empty
; action = loc, action
; mode = Standard
; patch_back_source_tree = false
; locks = []
; loc
; enabled_if = Blang.true_
Expand Down Expand Up @@ -117,7 +115,7 @@ let long_form =
to provide a nice error message for people switching from jbuilder
to dune. *)
assert (not fallback)
and+ mode = Mode.Extended.field
and+ mode = Mode.field
and+ enabled_if = Enabled_if.decode ~allowed_vars:Any ~since:(Some (1, 4)) ()
and+ package =
field_o
Expand All @@ -136,23 +134,6 @@ let long_form =
)
]
in
let mode, patch_back_source_tree =
match mode with
| Normal mode -> mode, false
| Patch_back_source_tree ->
if List.exists (Bindings.to_list deps) ~f:(function
| Dep_conf.Sandbox_config _ -> true
| _ -> false)
then
User_error.raise
~loc
[ Pp.text
"Rules with (mode patch-back-source-tree) cannot have an explicit \
sandbox configuration because it is implied by (mode \
patch-back-source-tree)."
];
Standard, true
in
let action =
match action_o with
| Some action -> action
Expand All @@ -165,17 +146,7 @@ let long_form =
in
field_missing ~hints loc "action"
in
{ targets
; deps
; action
; mode
; locks
; loc
; enabled_if
; aliases
; package
; patch_back_source_tree
})
{ targets; deps; action; mode; locks; loc; enabled_if; aliases; package })
;;

let decode =
Expand Down Expand Up @@ -243,7 +214,6 @@ let ocamllex_to_rule loc { modules; mode; enabled_if } =
; S.virt_pform __POS__ (Var Deps)
] ) )
; mode
; patch_back_source_tree = false
; locks = []
; loc
; enabled_if
Expand Down Expand Up @@ -273,7 +243,6 @@ let ocamlyacc_to_rule loc { modules; mode; enabled_if } =
(S.virt_text __POS__ "ocamlyacc")
[ S.virt_pform __POS__ (Var Deps) ] ) )
; mode
; patch_back_source_tree = false
; locks = []
; loc
; enabled_if
Expand Down
1 change: 0 additions & 1 deletion src/dune_rules/stanzas/rule_conf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type t =
; deps : Dep_conf.t Bindings.t
; action : Loc.t * Dune_lang.Action.t
; mode : Rule.Mode.t
; patch_back_source_tree : bool
; locks : Locks.t
; loc : Loc.t
; enabled_if : Blang.t
Expand Down
1 change: 0 additions & 1 deletion src/dune_rules/test_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents =
, Action_unexpanded.Redirect_out (Stdout, diff.file2, Normal, run_action)
)
; mode = Standard
; patch_back_source_tree = false
; locks = t.locks
; loc
; enabled_if = t.enabled_if
Expand Down

0 comments on commit a046cb9

Please sign in to comment.