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

Add a test about dune-sites where plugin links extra libary. #4348

Merged
merged 9 commits into from
Nov 18, 2021
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Unreleased
- Improve error handling of misbehaving cram scripts. (#4981, fix #4230,
@rgrinberg)

- Fix missing -linkall flag when linking library dune-sites.plugin
( #4348, @kakadu, @bobot, reported by @kakadu)

- Fix `foreign_stubs` inside a `tests` stanza. Previously, dune would crash
when this field was present (#4942, fix #4946, @rgrinberg)

Expand Down
5 changes: 5 additions & 0 deletions otherlibs/site/src/plugins/plugins.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ let rec get_plugin plugins requires entries =

exception Library_not_found of string

exception Thread_library_required_by_plugin_but_not_required_by_main_executable

let rec find_library ~suffix directory meta =
let rec find_directory directory = function
| [] -> directory
Expand Down Expand Up @@ -194,6 +196,9 @@ let loaded_libraries =
let load_gen ~load_requires dirs name =
let loaded_libraries = Lazy.force loaded_libraries in
if not (Hashtbl.mem loaded_libraries name) then (
if name = "threads" then
raise
Thread_library_required_by_plugin_but_not_required_by_main_executable;
Hashtbl.add loaded_libraries name ();
let directory, plugins, requires = lookup_and_summarize dirs name in
List.iter load_requires requires;
Expand Down
1 change: 1 addition & 0 deletions otherlibs/site/test/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(cram
(applies_to :whole_subtree)
(deps
(package dune)
(package dune-site)))
6 changes: 6 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/app.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(* load all the available plugins *)
let () = Sites.Plugins.Plugins.load_all ()

let () = print_endline "Main app starts..."
(* Execute the code registered by the plugins *)
let () = Queue.iter (fun f -> f ()) Registration.todo
19 changes: 19 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(executable
(public_name app)
(modules sites app)
(libraries
app.register
dune-site
dune-site.plugins
;TOREMOVE threads
))

(library
(public_name app.register)
(name registration)
(modules registration))

(generate_sites_module
(module sites)
(plugins
(app plugins)))
8 changes: 8 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(lang dune 2.8)
(using dune_site 0.1)

(name app)

(package
(name app)
(sites (lib plugins)))
12 changes: 12 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/plugin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(env (_ (flags -w -33)))

(library
(public_name plugin1.plugin1_impl)
(name plugin1_impl)
(modules plugin1_impl)
(libraries app.MyControls app.register result threads))

(plugin
(name plugin1)
(libraries threads plugin1.plugin1_impl)
(site (app plugins)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(lang dune 2.8)
(using dune_site 0.1)

(generate_opam_files true)

(package
(name plugin1))
20 changes: 20 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/plugin/plugin1.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
depends: [
"dune" {>= "2.8"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let () =
let open Result in
print_endline "Registration of Plugin1";
Queue.add (fun () ->
let th = Thread.create (fun () ->
print_endline "Plugin1 is doing something...") () in
Thread.join th
) Registration.todo
15 changes: 15 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/plugin2/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(env
(_
(flags -w -33)))

(library
(public_name plugin2.plugin2_impl)
(name plugin2_impl)
(modules plugin2_impl)
(libraries app.MyControls app.register result threads))

(plugin
(name plugin2)
(libraries threads plugin2.plugin2_impl)
(site
(app plugins)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(lang dune 2.8)

(using dune_site 0.1)

(generate_opam_files true)

(package
(name plugin2))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let () =
print_endline "Registration of Plugin2";
Queue.add (fun () -> print_endline "Plugin2 is doing something...") Registration.todo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let todo : (unit -> unit) Queue.t = Queue.create ()
17 changes: 17 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

$ dune build ./app.exe @install
$ dune exec ./app.exe
The library is being used by two plugins finished initialization
Fatal error: exception Dune_site_plugins__Plugins.Thread_library_required_by_plugin_but_not_required_by_main_executable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails with a crash for me locally:

   Fatal error: exception Dune_site_plugins__Plugins.Thread_library_required_by_plugin_but_not_required_by_main_executable
+  Raised at Dune_site_plugins__Plugins.load_gen in file "otherlibs/site/src/plugins/plugins.ml", line 200, characters 6-89
+  Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
+  Called from Dune_site_plugins__Plugins.load_gen in file "otherlibs/site/src/plugins/plugins.ml", line 204, characters 4-36
+  Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
+  Called from Dune_site_plugins__Plugins.load_gen in file "otherlibs/site/src/plugins/plugins.ml", line 204, characters 4-36
+  Called from Stdlib__list.iter in file "list.ml",   [2] line 110, characters 12-15
+  Called from Dune__exe__App in file "app.ml", line 2, characters 9-42
   [2]

Could you do something about it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have something like "backtrace printing is always activated"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm not sure what "backtrace printing is always activated" means.

Copy link
Contributor Author

@Kakadu Kakadu Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like export OCAMLRUNPARAM=b in ~/.bashrc...

For my your problem is not easily reproducible too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kakadu I see. That may well be it: my ~/.bashrc collects settings from various sources, and I wouldn't be surprised if one of them does what you say.

[2]

$ sed -i -e "s/;TOREMOVE//" dune

$ dune build ./app.exe @install
$ dune exec ./app.exe
The library is being used by two plugins finished initialization
Registration of Plugin1
Registration of Plugin2
Main app starts...
Plugin1 is doing something...
Plugin2 is doing something...
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "The library is being used by two plugins finished initialization"
5 changes: 5 additions & 0 deletions otherlibs/site/test/plugin_require_thread.t/stubs/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(public_name app.MyControls)
(name MyControls)
(modules MyControls)
(libraries))
2 changes: 1 addition & 1 deletion src/dune_rules/link_time_code_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,6 @@ let handle_special_libs cctx =
in
process_libs libs
~to_link_rev:(LM.Lib lib :: Module (obj_dir, module_) :: to_link_rev)
~force_linkall))
~force_linkall:true))
in
process_libs all_libs ~to_link_rev:[] ~force_linkall:false