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

feat: support libraries with the same name in multiple contexts #10307

Merged
merged 38 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a712bd8
feat: support libraries with the same name in multiple contexts
jchavarri Mar 1, 2024
04d2024
rules: remove unnecessary changes in dune_pkg Entry.t
jchavarri Mar 26, 2024
27bfc4a
refactor: flip available / available_by_name
anmonteiro Mar 26, 2024
dbebe2e
refactor: avoid passing `Blang.true_` everytime to Sentinel.external_
anmonteiro Mar 26, 2024
4b3c537
refactor: rename sentinel back to library_id
anmonteiro Mar 26, 2024
590a32d
refactor: remove `library_id` from Lib.t
anmonteiro Mar 26, 2024
bcdfa5a
refactor: tighten bindings, remove unnecessary lib id payload
anmonteiro Mar 26, 2024
0efd9d3
refactor: remove path from constructor
anmonteiro Mar 26, 2024
4d70eb9
refactor: rename resolve_name back to resolve, tighten bindings
anmonteiro Mar 26, 2024
889ad47
refactor: single pass over stanazas in scope
anmonteiro Mar 26, 2024
67466c3
refactor: tighten bindings
anmonteiro Mar 26, 2024
558d1cb
refactor: use Nonempty_list.t for multiple_results
anmonteiro Mar 26, 2024
df0bf46
refactor: library_id construction functions
anmonteiro Mar 26, 2024
8828a9f
fix: lib collision public same folder
jchavarri Mar 26, 2024
52c3723
ml_sources: use obj_dir instead of priv_name
jchavarri Mar 27, 2024
93a592d
refactor: use the library name!
anmonteiro Mar 28, 2024
1437ede
refactor: more coherent error message
anmonteiro Mar 29, 2024
8419ef6
fix: change `db.all` back to returning Lib_name.t list
anmonteiro Mar 29, 2024
34b3d42
code review: rename library_id to lib_id, rm id from
anmonteiro Mar 30, 2024
007b41e
refactor: use a variant for Lib_id to distinguish Local / External
anmonteiro Mar 30, 2024
1bb1cc5
fix: account for deprecated libraries too
anmonteiro Mar 31, 2024
727e4ba
_
rgrinberg Mar 31, 2024
1076ade
promote
rgrinberg Mar 31, 2024
47ba0db
_
rgrinberg Mar 31, 2024
5e46654
_
rgrinberg Mar 31, 2024
ac240e0
_
rgrinberg Mar 31, 2024
e4cbf76
_
rgrinberg Mar 31, 2024
f42679d
_
rgrinberg Mar 31, 2024
e6bba92
_
rgrinberg Mar 31, 2024
f04fe48
_
rgrinberg Mar 31, 2024
cf7bbc8
fix: pattern matching in lib.ml
anmonteiro Mar 31, 2024
265ca4e
fix: bring back conflict map for redirects
anmonteiro Mar 31, 2024
dbba929
refactor: remove Nonempty_list.t from resolve results
anmonteiro Mar 31, 2024
3f3c50c
refactor: remove `With_multiple_results` module
anmonteiro Apr 1, 2024
318ebb8
refactor: use the empty list
anmonteiro Apr 1, 2024
d305b10
fix: Not_found case, recurse on the empty list
anmonteiro Apr 1, 2024
bdfe638
List.filter_opt
anmonteiro Apr 1, 2024
7e992fc
chore: add changelog entry
anmonteiro Apr 1, 2024
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: 2 additions & 1 deletion bin/describe/describe_workspace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ module Crawl = struct
let* modules_, obj_dir_ =
Dir_contents.get sctx ~dir:(Path.as_in_build_dir_exn src_dir)
>>= Dir_contents.ocaml
>>| Ml_sources.modules_and_obj_dir ~for_:(Library name)
>>| Ml_sources.modules_and_obj_dir
~for_:(Library (Lib_info.lib_id info |> Lib_id.to_local_exn))
in
let* pp_map =
let+ version =
Expand Down
4 changes: 4 additions & 0 deletions doc/changes/10307.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- allow libraries with the same `(name ..)` in projects as long as they don't
conflict during resolution (via `enabled_if`). (#10307, @anmonteiro,
@jchavarri)

4 changes: 2 additions & 2 deletions src/dune_rules/dir_contents.ml
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ let modules_of_local_lib sctx lib =
let dir = Lib_info.src_dir info in
get sctx ~dir
in
let name = Lib_info.name info in
ocaml t >>| Ml_sources.modules ~for_:(Library name)
ocaml t
>>| Ml_sources.modules ~for_:(Library (Lib_info.lib_id info |> Lib_id.to_local_exn))
;;

let modules_of_lib sctx lib =
Expand Down
2 changes: 2 additions & 0 deletions src/dune_rules/dune_package.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ module Lib = struct
let entry_modules = Modules.entry_modules modules |> List.map ~f:Module.name in
let info : Path.t Lib_info.t =
let src_dir = Obj_dir.dir obj_dir in
let lib_id = Lib_id.External (loc, name) in
let enabled = Memo.return Lib_info.Enabled_status.Normal in
let status =
match Lib_name.analyze name with
Expand All @@ -255,6 +256,7 @@ module Lib = struct
~path_kind:External
~loc
~name
~lib_id
~kind
~status
~src_dir
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/dune_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Expander = Expander
module Lib = Lib
module Lib_flags = Lib_flags
module Lib_info = Lib_info
module Lib_id = Lib_id
module Modules = Modules
module Module_compilation = Module_compilation
module Exe_rules = Exe_rules
Expand Down
5 changes: 4 additions & 1 deletion src/dune_rules/findlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,13 @@ let to_dune_library (t : Findlib.Package.t) ~dir_contents ~ext_lib ~external_loc
| Error e -> Error e))))
in
let modules = Lib_info.Source.External None in
let name = t.name in
let lib_id = Lib_id.External (loc, name) in
Lib_info.create
~loc
~path_kind:External
~name:t.name
~name
~lib_id
~kind
~status
~src_dir
Expand Down
6 changes: 5 additions & 1 deletion src/dune_rules/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ end = struct
let+ () = Toplevel.Stanza.setup ~sctx ~dir ~toplevel in
empty_none
| Library.T lib ->
let* enabled_if = Lib.DB.available (Scope.libs scope) (Library.best_name lib) in
let* enabled_if =
Lib.DB.available_by_lib_id
(Scope.libs scope)
(Local (Library.to_lib_id ~src_dir lib))
in
if_available_buildable
~loc:lib.buildable.loc
(fun () -> Lib_rules.rules lib ~sctx ~dir ~scope ~dir_contents ~expander)
Expand Down
23 changes: 19 additions & 4 deletions src/dune_rules/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ end = struct
let lib_files ~dir_contents ~dir ~lib_config lib =
let+ modules =
let+ ml_sources = Dir_contents.ocaml dir_contents in
Some (Ml_sources.modules ml_sources ~for_:(Library (Lib_info.name lib)))
Some
(Ml_sources.modules
ml_sources
~for_:(Library (Lib_info.lib_id lib |> Lib_id.to_local_exn)))
and+ foreign_archives =
match Lib_info.virtual_ lib with
| None -> Memo.return (Mode.Map.Multi.to_flat_list @@ Lib_info.foreign_archives lib)
Expand Down Expand Up @@ -181,7 +184,9 @@ end = struct
let lib_name = Library.best_name lib in
let* installable_modules =
let+ modules =
Dir_contents.ocaml dir_contents >>| Ml_sources.modules ~for_:(Library lib_name)
Dir_contents.ocaml dir_contents
>>| Ml_sources.modules
~for_:(Library (Lib_info.lib_id info |> Lib_id.to_local_exn))
and+ impl = Virtual_rules.impl sctx ~lib ~scope in
Vimpl.impl_modules impl modules |> Modules.split_by_lib
in
Expand Down Expand Up @@ -338,7 +343,15 @@ end = struct
if enabled_if
then
if lib.optional
then Lib.DB.available (Scope.libs scope) (Library.best_name lib)
then (
let src_dir =
Expander.dir expander
|> Path.build
|> Path.drop_optional_build_context_src_exn
in
Lib.DB.available_by_lib_id
(Scope.libs scope)
(Local (Library.to_lib_id ~src_dir lib)))
else Memo.return true
else Memo.return false
| Documentation.T _ -> Memo.return true
Expand Down Expand Up @@ -652,7 +665,9 @@ end = struct
|> Foreign.Sources.object_files ~dir ~ext_obj
|> List.map ~f:Path.build
and* modules =
Dir_contents.ocaml dir_contents >>| Ml_sources.modules ~for_:(Library name)
Dir_contents.ocaml dir_contents
>>| Ml_sources.modules
~for_:(Library (Lib_info.lib_id info |> Lib_id.to_local_exn))
and* melange_runtime_deps = file_deps (Lib_info.melange_runtime_deps info)
and* public_headers = file_deps (Lib_info.public_headers info) in
let+ dune_lib =
Expand Down
Loading
Loading