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

refactor: move [Copy_files] to own module #9480

Merged
merged 1 commit into from
Dec 13, 2023
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
44 changes: 0 additions & 44 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1761,50 +1761,6 @@ module Toplevel = struct
;;
end

module Copy_files = struct
type t =
{ add_line_directive : bool
; alias : Alias.Name.t option
; mode : Rule.Mode.t
; enabled_if : Blang.t
; files : String_with_vars.t
; syntax_version : Dune_lang.Syntax.Version.t
}

include Stanza.Make (struct
type nonrec t = t

include Poly
end)

let long_form =
let check = Dune_lang.Syntax.since Stanza.syntax (2, 7) in
let+ alias = field_o "alias" (check >>> Dune_lang.Alias.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+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
{ add_line_directive = false; alias; mode; enabled_if; files; syntax_version }
;;

let decode =
peek_exn
>>= function
| List _ -> fields long_form
| _ ->
let+ files = String_with_vars.decode
and+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
{ add_line_directive = false
; alias = None
; mode = Standard
; enabled_if = Blang.true_
; files
; syntax_version
}
;;
end

module Documentation = struct
type t =
{ loc : Loc.t
Expand Down
13 changes: 0 additions & 13 deletions src/dune_rules/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,6 @@ module Executables : sig
val obj_dir : t -> dir:Path.Build.t -> Path.Build.t Obj_dir.t
end

module Copy_files : sig
type t =
{ add_line_directive : bool
; alias : Alias.Name.t option
; mode : Rule.Mode.t
; enabled_if : Blang.t
; files : String_with_vars.t
; syntax_version : Dune_lang.Syntax.Version.t
}

include Stanza.S with type t := t
end

module Documentation : sig
type t =
{ loc : Loc.t
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/simple_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ let user_rule sctx ?extra_bindings ~dir ~expander (rule : Rule_conf.t) =
None)
;;

let copy_files sctx ~dir ~expander ~src_dir (def : Dune_file.Copy_files.t) =
let copy_files sctx ~dir ~expander ~src_dir (def : Copy_files.t) =
let loc = String_with_vars.loc def.files in
let* glob_in_src =
let+ src_glob = Expander.No_deps.expand_str expander def.files in
Expand Down Expand Up @@ -255,7 +255,7 @@ let copy_files sctx ~dir ~expander ~src_dir (def : Dune_file.Copy_files.t) =
targets
;;

let copy_files sctx ~dir ~expander ~src_dir (def : Dune_file.Copy_files.t) =
let copy_files sctx ~dir ~expander ~src_dir (def : Copy_files.t) =
Expander.eval_blang expander def.enabled_if
>>= function
| true -> copy_files sctx ~dir ~expander ~src_dir def
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/simple_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val copy_files
-> dir:Path.Build.t
-> expander:Expander.t
-> src_dir:Path.Source.t
-> Dune_file.Copy_files.t
-> Copy_files.t
-> Path.Set.t Memo.t

(** Interpret an [(alias ...)] stanza. *)
Expand Down
43 changes: 43 additions & 0 deletions src/dune_rules/stanzas/copy_files.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
open Import
open Dune_lang.Decoder

type t =
{ add_line_directive : bool
; alias : Alias.Name.t option
; mode : Rule.Mode.t
; enabled_if : Blang.t
; files : String_with_vars.t
; syntax_version : Dune_lang.Syntax.Version.t
}

include Stanza.Make (struct
type nonrec t = t

include Poly
end)

let long_form =
let check = Dune_lang.Syntax.since Stanza.syntax (2, 7) in
let+ alias = field_o "alias" (check >>> Dune_lang.Alias.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+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
{ add_line_directive = false; alias; mode; enabled_if; files; syntax_version }
;;

let decode =
peek_exn
>>= function
| List _ -> fields long_form
| _ ->
let+ files = String_with_vars.decode
and+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
{ add_line_directive = false
; alias = None
; mode = Standard
; enabled_if = Blang.true_
; files
; syntax_version
}
;;
14 changes: 14 additions & 0 deletions src/dune_rules/stanzas/copy_files.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Import

type t =
{ add_line_directive : bool
; alias : Alias.Name.t option
; mode : Rule.Mode.t
; enabled_if : Blang.t
; files : String_with_vars.t
; syntax_version : Dune_lang.Syntax.Version.t
}

include Stanza.S with type t := t

val decode : t Dune_lang.Decoder.t