Skip to content

Commit

Permalink
refactor(melange): move stanza definition (#6775)
Browse files Browse the repository at this point in the history
It should exist in [Melange_stanzas]

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Dec 27, 2022
1 parent cc12f0d commit 2f85081
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 20 deletions.
6 changes: 0 additions & 6 deletions src/dune_engine/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,6 @@ end

module Melange_syntax = struct
let name = "melange"

let t =
Dune_lang.Syntax.create ~name ~desc:"support for Melange compiler"
[ ((0, 1), `Since (3, 6)) ]

let () = Extension.register_simple t (return [])
end

let explicit_extensions_map explicit_extensions =
Expand Down
2 changes: 1 addition & 1 deletion src/dune_engine/dune_project.mli
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,5 @@ val encode : t -> Dune_lang.t list
val dune_site_extension : unit Extension.t

module Melange_syntax : sig
val t : Dune_lang.Syntax.t
val name : string
end
2 changes: 1 addition & 1 deletion src/dune_rules/dir_status.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let get_include_subdirs stanzas =
let find_module_stanza stanzas =
List.find_map stanzas ~f:(fun stanza ->
match stanza with
| Melange_emit { loc; _ }
| Melange_stanzas.Emit.T { loc; _ }
| Library { buildable = { loc; _ }; _ }
| Executables { buildable = { loc; _ }; _ }
| Tests { exes = { buildable = { loc; _ }; _ }; _ } -> Some loc
Expand Down
7 changes: 1 addition & 6 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ module Mode_conf = struct
; ("native", return @@ Ocaml Native)
; ("best", return @@ Ocaml Best)
; ( "melange"
, Dune_lang.Syntax.since Dune_project.Melange_syntax.t (0, 1)
, Dune_lang.Syntax.since Melange_stanzas.syntax (0, 1)
>>> return Melange )
]

Expand Down Expand Up @@ -2274,7 +2274,6 @@ type Stanza.t +=
| Cram of Cram_stanza.t
| Generate_sites_module of Generate_sites_module.t
| Plugin of Plugin.t
| Melange_emit of Melange_stanzas.Emit.t

module Stanzas = struct
type t = Stanza.t list
Expand Down Expand Up @@ -2391,10 +2390,6 @@ module Stanzas = struct
, let+ () = Dune_lang.Syntax.since Section.dune_site_syntax (0, 1)
and+ t = Plugin.decode in
[ Plugin t ] )
; ( "melange.emit"
, let+ () = Dune_lang.Syntax.since Dune_project.Melange_syntax.t (0, 1)
and+ t = Melange_stanzas.Emit.decode in
[ Melange_emit t ] )
]

let () = Dune_project.Lang.register Stanza.syntax stanzas
Expand Down
1 change: 0 additions & 1 deletion src/dune_rules/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ type Stanza.t +=
| Cram of Cram_stanza.t
| Generate_sites_module of Generate_sites_module.t
| Plugin of Plugin.t
| Melange_emit of Melange_stanzas.Emit.t

val stanza_package : Stanza.t -> Package.t option

Expand Down
6 changes: 3 additions & 3 deletions src/dune_rules/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end = struct
| true ->
let+ () = Mdx.gen_rules ~sctx ~dir ~scope ~expander mdx in
empty_none)
| Melange_emit mel ->
| Melange_stanzas.Emit.T mel ->
let+ cctx, merlin =
Melange_rules.setup_emit_cmj_rules ~dir_contents ~dir ~scope ~sctx
~expander mel
Expand Down Expand Up @@ -380,7 +380,7 @@ let under_melange_emit_target ~dir =
| None -> None
| Some stanzas ->
List.find_map stanzas.stanzas ~f:(function
| Melange_emit mel ->
| Melange_stanzas.Emit.T mel ->
let target_dir = Path.Build.relative parent mel.target in
Option.some_if (Path.Build.equal target_dir dir) mel
| _ -> None)
Expand Down Expand Up @@ -506,7 +506,7 @@ let gen_rules ~sctx ~dir components : Build_config.gen_rules_result Memo.t =
| None -> subdirs
| Some stanzas ->
List.filter_map stanzas.stanzas ~f:(function
| Melange_emit mel -> Some mel.target
| Melange_stanzas.Emit.T mel -> Some mel.target
| _ -> None)
|> String.Set.of_list |> String.Set.union subdirs
in
Expand Down
11 changes: 11 additions & 0 deletions src/dune_rules/melange_stanzas.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Emit = struct
; javascript_extension : string
}

type Stanza.t += T of t

let decode_lib =
let+ loc = loc
and+ t =
Expand Down Expand Up @@ -125,3 +127,12 @@ module Emit = struct
; modules_without_implementation
})
end

let syntax =
Dune_lang.Syntax.create ~name:Dune_project.Melange_syntax.name
~desc:"support for Melange compiler"
[ ((0, 1), `Since (3, 6)) ]

let () =
Dune_project.Extension.register_simple syntax
(return [ ("melange.emit", Emit.decode >>| fun x -> [ Emit.T x ]) ])
4 changes: 4 additions & 0 deletions src/dune_rules/melange_stanzas.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ module Emit : sig
; javascript_extension : string
}

type Stanza.t += T of t

val decode : t Dune_lang.Decoder.t
end

val syntax : Syntax.t
2 changes: 1 addition & 1 deletion src/dune_rules/ml_sources.ml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ let modules_of_stanzas dune_file ~dir ~scope ~lookup_vlib ~modules =
Modules_group.relocate_alias_module modules ~src_dir
in
Memo.return (`Executables (exes, modules, obj_dir))
| Melange_emit mel ->
| Melange_stanzas.Emit.T mel ->
let modules =
let modules =
Modules_field_evaluator.eval ~modules ~stanza_loc:mel.loc
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/ocaml_flags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module Spec = struct
and+ native = field_oslu "ocamlopt_flags"
and+ melange =
field_oslu
~check:(Dune_lang.Syntax.since Dune_project.Melange_syntax.t (0, 1))
~check:(Dune_lang.Syntax.since Melange_stanzas.syntax (0, 1))
"melange.compile_flags"
in
let specific = Lib_mode.Map.make ~byte ~native ~melange in
Expand Down

0 comments on commit 2f85081

Please sign in to comment.