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

Remove more old jbuild support #2458

Merged
merged 3 commits into from
Jul 29, 2019
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
would not do this normalization for rules defined in jbuild files. (#2457,
@rgrinberg)

- Modules may no longer belong to more than one stanza. This was previously
allowed only in stanzas defined in `jbuild` files. (#2458, @rgrinberg)

1.11.0 (23/07/2019)
-------------------

Expand Down
4 changes: 0 additions & 4 deletions src/compilation_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type t =
; scope : Scope.t
; expander : Expander.t
; obj_dir : Path.Build.t Obj_dir.t
; dir_kind : Dune_lang.File_syntax.t
; modules : Modules.t
; flags : Ocaml_flags.t
; requires_compile : Lib.t list Or_exn.t
Expand All @@ -68,7 +67,6 @@ let super_context t = t.super_context
let scope t = t.scope
let expander t = t.expander
let dir t = Obj_dir.dir t.obj_dir
let dir_kind t = t.dir_kind
let obj_dir t = t.obj_dir
let modules t = t.modules
let flags t = t.flags
Expand All @@ -88,7 +86,6 @@ let vimpl t = t.vimpl
let context t = Super_context.context t.super_context

let create ~super_context ~scope ~expander ~obj_dir
?(dir_kind=Dune_lang.File_syntax.Dune)
~modules ~flags ~requires_compile ~requires_link
?(preprocessing=Preprocessing.dummy) ?(no_keep_locs=false)
~opaque ?stdlib ~js_of_ocaml ~dynlink ?sandbox ~package ?vimpl () =
Expand All @@ -102,7 +99,6 @@ let create ~super_context ~scope ~expander ~obj_dir
; scope
; expander
; obj_dir
; dir_kind
; modules
; flags
; requires_compile
Expand Down
2 changes: 0 additions & 2 deletions src/compilation_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ val create
-> scope : Scope.t
-> expander : Expander.t
-> obj_dir : Path.Build.t Obj_dir.t
-> ?dir_kind : Dune_lang.File_syntax.t
-> modules : Modules.t
-> flags : Ocaml_flags.t
-> requires_compile : Lib.t list Or_exn.t
Expand All @@ -43,7 +42,6 @@ val expander : t -> Expander.t
val context : t -> Context.t
val scope : t -> Scope.t
val dir : t -> Path.Build.t
val dir_kind : t -> Dune_lang.File_syntax.t
val obj_dir : t -> Path.Build.t Obj_dir.t
val modules : t -> Modules.t
val flags : t -> Ocaml_flags.t
Expand Down
72 changes: 22 additions & 50 deletions src/dir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -332,55 +332,28 @@ end = struct
(List.concat_map libs ~f:(fun (l, m) -> by_name l.buildable m))
(List.concat_map exes ~f:(fun (e, m) -> by_name e.buildable m))
in
match d.kind with
| Dune -> begin
match Module.Name.Map.of_list rev_modules with
| Ok x -> x
| Error (name, _, _) ->
let open Module.Name.Infix in
let locs =
List.filter_map rev_modules ~f:(fun (n, b) ->
Option.some_if (n = name) b.loc)
|> List.sort ~compare
in
User_error.raise ~loc:(Loc.drop_position (List.hd locs))
[ Pp.textf "Module %S is used in several stanzas:"
(Module.Name.to_string name)
; Pp.enumerate locs ~f:(fun loc ->
Pp.verbatim (Loc.to_file_colon_line loc))
; Pp.text
"To fix this error, you must specify an explicit \
\"modules\" field in every library, executable, and \
executables stanzas in this dune file. Note that \
each module cannot appear in more than one \
\"modules\" field - it must belong to a single \
library or executable."
]
end
| Jbuild ->
Module.Name.Map.of_list_multi rev_modules
|> Module.Name.Map.mapi ~f:(fun name buildables ->
match buildables with
| [] -> assert false
| [b] -> b
| b :: rest ->
let locs =
List.sort ~compare
(b.Buildable.loc :: List.map rest ~f:(fun b -> b.Buildable.loc))
in
User_error.raise ~loc:(Loc.drop_position b.loc)
[ Pp.textf "Module %S is used in several stanzas:"
(Module.Name.to_string name)
; Pp.enumerate locs ~f:(fun loc ->
Pp.verbatim (Loc.to_file_colon_line loc))
; Pp.text
"To remove this warning, you must specify an \
explicit \"modules\" field in every library, \
executable, and executables stanzas in this jbuild \
file. Note that each module cannot appear in more \
than one \"modules\" field - it must belong to a \
single library or executable."
])
match Module.Name.Map.of_list rev_modules with
| Ok x -> x
| Error (name, _, _) ->
let open Module.Name.Infix in
let locs =
List.filter_map rev_modules ~f:(fun (n, b) ->
Option.some_if (n = name) b.loc)
|> List.sort ~compare
in
User_error.raise ~loc:(Loc.drop_position (List.hd locs))
[ Pp.textf "Module %S is used in several stanzas:"
(Module.Name.to_string name)
; Pp.enumerate locs ~f:(fun loc ->
Pp.verbatim (Loc.to_file_colon_line loc))
; Pp.text
"To fix this error, you must specify an explicit \
\"modules\" field in every library, executable, and \
executables stanzas in this dune file. Note that \
each module cannot appear in more than one \
\"modules\" field - it must belong to a single \
library or executable."
]
in
{ Dir_modules. libraries; executables; rev_map }

Expand All @@ -391,7 +364,6 @@ end = struct
; src_dir
; scope = _
; data = stanzas
; kind = _
; dune_version = _
} =
(* Interpret a few stanzas in order to determine the list of
Expand Down
1 change: 0 additions & 1 deletion src/dir_with_dune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type 'data t =
; ctx_dir : Path.Build.t
; data : 'data
; scope : Scope.t
; kind : Dune_lang.File_syntax.t
; dune_version : Syntax.Version.t
}

Expand Down
1 change: 0 additions & 1 deletion src/dir_with_dune.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type 'data t =
; ctx_dir : Path.Build.t (** [_build/context-name/src_dir] *)
; data : 'data
; scope : Scope.t
; kind : Dune_lang.File_syntax.t
; dune_version : Syntax.Version.t
}

Expand Down
12 changes: 5 additions & 7 deletions src/exe_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ open! No_io
open Build.O
module SC = Super_context

let executables_rules ~sctx ~dir ~dir_kind ~expander
~dir_contents ~scope ~compile_info
(exes : Dune_file.Executables.t) =
let executables_rules ~sctx ~dir ~expander ~dir_contents ~scope
~compile_info (exes : Dune_file.Executables.t) =
(* Use "eobjs" rather than "objs" to avoid a potential conflict
with a library of the same name *)
let obj_dir = Obj_dir.make_exe ~dir ~name:(snd (List.hd exes.names)) in
Expand Down Expand Up @@ -114,7 +113,6 @@ let executables_rules ~sctx ~dir ~dir_kind ~expander
~expander
~scope
~obj_dir
~dir_kind
~modules
~flags
~requires_link
Expand Down Expand Up @@ -142,7 +140,7 @@ let executables_rules ~sctx ~dir ~dir_kind ~expander
~preprocess:(Dune_file.Buildable.single_preprocess exes.buildable)
~obj_dir)

let rules ~sctx ~dir ~dir_contents ~scope ~expander ~dir_kind
let rules ~sctx ~dir ~dir_contents ~scope ~expander
(exes : Dune_file.Executables.t) =
let compile_info =
Lib.DB.resolve_user_written_deps_for_exes
Expand All @@ -154,8 +152,8 @@ let rules ~sctx ~dir ~dir_contents ~scope ~expander ~dir_kind
~variants:exes.variants
in
let f () =
executables_rules exes ~sctx ~dir
~dir_contents ~scope ~expander ~compile_info ~dir_kind
executables_rules exes ~sctx ~dir ~dir_contents ~scope ~expander
~compile_info
in
SC.Libs.gen_select_rules sctx compile_info ~dir;
SC.Libs.with_lib_deps sctx compile_info ~dir ~f
1 change: 0 additions & 1 deletion src/exe_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ val rules
-> dir_contents:Dir_contents.t
-> scope:Scope.t
-> expander:Expander.t
-> dir_kind:Dune_lang.File_syntax.t
-> Dune_file.Executables.t
-> Compilation_context.t * Merlin.t
10 changes: 3 additions & 7 deletions src/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module Gen(P : sig val sctx : Super_context.t end) = struct

let gen_rules dir_contents cctxs
{ Dir_with_dune. src_dir; ctx_dir; data = stanzas
; scope; kind = dir_kind ; dune_version = _ } =
; scope; dune_version = _; } =
let expander =
Super_context.expander sctx ~dir:ctx_dir in
let for_stanza stanza =
Expand All @@ -88,8 +88,7 @@ module Gen(P : sig val sctx : Super_context.t end) = struct
For_stanza.empty_none
| Library lib ->
let cctx, merlin =
Lib_rules.rules lib ~sctx ~dir ~scope ~dir_contents ~expander
~dir_kind in
Lib_rules.rules lib ~sctx ~dir ~scope ~dir_contents ~expander in
{ For_stanza.
merlin = Some merlin
; cctx = Some (lib.buildable.loc, cctx)
Expand All @@ -98,9 +97,7 @@ module Gen(P : sig val sctx : Super_context.t end) = struct
}
| Executables exes ->
let cctx, merlin =
Exe_rules.rules exes
~sctx ~dir ~scope ~expander
~dir_contents ~dir_kind
Exe_rules.rules exes ~sctx ~dir ~scope ~expander ~dir_contents
in
{ For_stanza.
merlin = Some merlin
Expand All @@ -118,7 +115,6 @@ module Gen(P : sig val sctx : Super_context.t end) = struct
| Tests tests ->
let cctx, merlin =
Test_rules.rules tests ~sctx ~dir ~scope ~expander ~dir_contents
~dir_kind
in
{ For_stanza.
merlin = Some merlin
Expand Down
6 changes: 2 additions & 4 deletions src/lib_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ let setup_build_archives (lib : Dune_file.Library.t)
build_shared ~sctx lib ~dir ~flags

let library_rules (lib : Library.t) ~sctx ~dir_contents ~dir ~expander ~scope
~compile_info ~dir_kind =
~compile_info =
let dep_kind =
if lib.optional then Lib_deps_info.Kind.Optional else Required
in
Expand Down Expand Up @@ -366,7 +366,6 @@ let library_rules (lib : Library.t) ~sctx ~dir_contents ~dir ~expander ~scope
~super_context:sctx
~expander
~scope
~dir_kind
~obj_dir
~modules
~flags
Expand Down Expand Up @@ -420,14 +419,13 @@ let library_rules (lib : Library.t) ~sctx ~dir_contents ~dir ~expander ~scope
)

let rules (lib : Library.t) ~sctx ~dir_contents ~dir ~expander ~scope
~dir_kind : Compilation_context.t * Merlin.t =
: Compilation_context.t * Merlin.t =
let compile_info =
Lib.DB.get_compile_info (Scope.libs scope) (Library.best_name lib)
~allow_overlaps:lib.buildable.allow_overlapping_dependencies
in
let f () =
library_rules lib ~sctx ~dir_contents ~dir ~scope ~expander ~compile_info
~dir_kind
in
Super_context.Libs.gen_select_rules sctx compile_info ~dir;
Super_context.Libs.with_lib_deps sctx compile_info ~dir ~f
1 change: 0 additions & 1 deletion src/lib_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ val rules
-> dir:Path.Build.t
-> expander:Expander.t
-> scope:Scope.t
-> dir_kind:Dune_lang.File_syntax.t
-> Compilation_context.t * Merlin.t
1 change: 0 additions & 1 deletion src/link_time_code_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ let generate_and_compile_module cctx ~precompiled_cmi ~name:basename
~super_context:sctx
~expander:(Compilation_context.expander cctx)
~scope:(Compilation_context.scope cctx)
~dir_kind:(Compilation_context.dir_kind cctx)
~obj_dir
~modules
~requires_compile:requires
Expand Down
3 changes: 1 addition & 2 deletions src/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,14 @@ let create
in
let stanzas =
List.map stanzas
~f:(fun { Dune_load.Dune_file. dir; project; stanzas; kind } ->
~f:(fun { Dune_load.Dune_file. dir; project; stanzas; kind = _ } ->
let ctx_dir = Path.Build.append_source context.build_dir dir in
let dune_version = Dune_project.dune_version project in
{ Dir_with_dune.
src_dir = dir
; ctx_dir
; data = stanzas
; scope = Scope.DB.find_by_project scopes project
; kind
; dune_version
})
in
Expand Down
3 changes: 1 addition & 2 deletions src/test_rules.boot.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let rules _ ~sctx:_ ~dir:_ ~scope:_ ~expander:_ ~dir_contents:_
~dir_kind:_ =
let rules _ ~sctx:_ ~dir:_ ~scope:_ ~expander:_ ~dir_contents:_ =
failwith "test stanza not supported in bootstrap"
5 changes: 2 additions & 3 deletions src/test_rules.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
open Import
open! No_io

let rules (t : Dune_file.Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents
~dir_kind =
let rules (t : Dune_file.Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents =
let test_kind (loc, name) =
let files = Dir_contents.text_files dir_contents in
let expected_basename = name ^ ".expected" in
Expand Down Expand Up @@ -63,4 +62,4 @@ let rules (t : Dune_file.Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents
add_alias ~loc ~action:(Diff diff) ~locks:t.locks;
ignore (Simple_rules.user_rule sctx rule ~extra_bindings ~dir ~expander
: Path.Build.Set.t));
Exe_rules.rules t.exes ~sctx ~dir ~scope ~expander ~dir_kind ~dir_contents
Exe_rules.rules t.exes ~sctx ~dir ~scope ~expander ~dir_contents
1 change: 0 additions & 1 deletion src/test_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ val rules
-> scope:Scope.t
-> expander:Expander.t
-> dir_contents:Dir_contents.t
-> dir_kind:Dune_lang.File_syntax.t
-> Compilation_context.t * Merlin.t

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

40 changes: 0 additions & 40 deletions test/blackbox-tests/test-cases/ocamldep-multi-stanzas/run.t
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
$ dune exec ./test.exe --debug-dep --display short --root jbuild --profile release
Entering directory 'jbuild'
File "jbuild", line 1, characters 0-0:
Warning: jbuild files are not allowed inside Dune 2.0 projects, please
convert this file to a dune file instead.
Note: You can use "dune upgrade" to convert your project to dune.
File "src/jbuild", line 1, characters 0-0:
Warning: jbuild files are not allowed inside Dune 2.0 projects, please
convert this file to a dune file instead.
Note: You can use "dune upgrade" to convert your project to dune.
File "jbuild", line 1, characters 0-0:
Error: Module "Lib" is used in several stanzas:
- jbuild:2
- jbuild:6
To remove this warning, you must specify an explicit "modules" field in every
library, executable, and executables stanzas in this jbuild file. Note that
each module cannot appear in more than one "modules" field - it must belong
to a single library or executable.
[1]

$ dune build src/a.cma --debug-dep --display short --root jbuild
Entering directory 'jbuild'
File "jbuild", line 1, characters 0-0:
Warning: jbuild files are not allowed inside Dune 2.0 projects, please
convert this file to a dune file instead.
Note: You can use "dune upgrade" to convert your project to dune.
File "src/jbuild", line 1, characters 0-0:
Warning: jbuild files are not allowed inside Dune 2.0 projects, please
convert this file to a dune file instead.
Note: You can use "dune upgrade" to convert your project to dune.
File "src/jbuild", line 1, characters 0-0:
Error: Module "X" is used in several stanzas:
- src/jbuild:1
- src/jbuild:2
To remove this warning, you must specify an explicit "modules" field in every
library, executable, and executables stanzas in this jbuild file. Note that
each module cannot appear in more than one "modules" field - it must belong
to a single library or executable.
[1]

$ dune exec ./test.exe --debug-dep --display short --root dune
Entering directory 'dune'
File "dune", line 1, characters 0-0:
Expand Down