diff options
author | Tim Watson <watson.timothy@gmail.com> | 2011-05-03 00:15:19 +0100 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-08-29 17:27:45 +0200 |
commit | 3b58935b8621a876afad2f649bbd00a12f7ab03f (patch) | |
tree | e7d90f6d318e8d52f9db40635c4bd22f40b1e9a5 /inttest | |
parent | 7a1c88228be2129ad517d5b4eda9c4c9232115bf (diff) |
Load plugins dynamically from source
This patch updates rebar_core to look for missing plugins (i.e. those
that aren't found on the code path at runtime) in a configurable
plugin directory, and dynamically compile and load them at runtime.
By default, the directory "plugins" is searched, although this can be
overriden by setting the plugin_dir in your rebar.config.
Diffstat (limited to 'inttest')
-rw-r--r-- | inttest/tplugins/bad.config | 2 | ||||
-rw-r--r-- | inttest/tplugins/bad_plugin.erl | 7 | ||||
-rw-r--r-- | inttest/tplugins/fish.erl | 5 | ||||
-rw-r--r-- | inttest/tplugins/rebar.config | 1 | ||||
-rw-r--r-- | inttest/tplugins/test_plugin.erl | 8 | ||||
-rw-r--r-- | inttest/tplugins/tplugins_rt.erl | 40 |
6 files changed, 63 insertions, 0 deletions
diff --git a/inttest/tplugins/bad.config b/inttest/tplugins/bad.config new file mode 100644 index 0000000..23069b8 --- /dev/null +++ b/inttest/tplugins/bad.config @@ -0,0 +1,2 @@ +{plugins, [bad_plugin]}. +{plugin_dir, "bad_plugins"}. diff --git a/inttest/tplugins/bad_plugin.erl b/inttest/tplugins/bad_plugin.erl new file mode 100644 index 0000000..77ec01b --- /dev/null +++ b/inttest/tplugins/bad_plugin.erl @@ -0,0 +1,7 @@ +-module(bad_plugin). +-compile(export_all). + +%% this plugin contains numerous DELIBERATE syntax errors + +fwibble(Config, _) > + file:delete("fwibble.test") diff --git a/inttest/tplugins/fish.erl b/inttest/tplugins/fish.erl new file mode 100644 index 0000000..739cb94 --- /dev/null +++ b/inttest/tplugins/fish.erl @@ -0,0 +1,5 @@ +-module(fish). + +-compile(export_all). + +fish() -> fish. diff --git a/inttest/tplugins/rebar.config b/inttest/tplugins/rebar.config new file mode 100644 index 0000000..0b9c887 --- /dev/null +++ b/inttest/tplugins/rebar.config @@ -0,0 +1 @@ +{plugins, [test_plugin]}. diff --git a/inttest/tplugins/test_plugin.erl b/inttest/tplugins/test_plugin.erl new file mode 100644 index 0000000..461247c --- /dev/null +++ b/inttest/tplugins/test_plugin.erl @@ -0,0 +1,8 @@ +-module(test_plugin). +-compile(export_all). + +fwibble(Config, _) -> + Pwd = rebar_utils:get_cwd(), + Ok = filelib:is_regular(filename:join(Pwd, "fwibble.test")), + rebar_log:log(info, "~p:~p in ~s :: ~p~n", [test_plugin, clean, Pwd, Ok]), + ok = file:delete("fwibble.test"). diff --git a/inttest/tplugins/tplugins_rt.erl b/inttest/tplugins/tplugins_rt.erl new file mode 100644 index 0000000..d2ef382 --- /dev/null +++ b/inttest/tplugins/tplugins_rt.erl @@ -0,0 +1,40 @@ +-module(tplugins_rt). +-compile(export_all). + +-include_lib("eunit/include/eunit.hrl"). + +-define(COMPILE_ERROR, + "ERROR: Plugin bad_plugin contains compilation errors:"). + +files() -> + [ + {copy, "../../rebar", "rebar"}, + {copy, "rebar.config", "rebar.config"}, + {copy, "bad.config", "bad.config"}, + {copy, "fish.erl", "src/fish.erl"}, + {copy, "test_plugin.erl", "plugins/test_plugin.erl"}, + {copy, "bad_plugin.erl", "bad_plugins/bad_plugin.erl"}, + {create, "fwibble.test", <<"fwibble">>}, + {create, "ebin/fish.app", app(fish, [fish])} + ]. + +run(Dir) -> + ?assertMatch({ok, _}, retest_sh:run("./rebar fwibble -v", [])), + ?assertEqual(false, filelib:is_regular("fwibble.test")), + Ref = retest:sh("./rebar -C bad.config -v clean", [{async, true}]), + {ok, _} = retest:sh_expect(Ref, "ERROR: Plugin .*bad_plugin.erl " + "contains compilation errors:.*", + [{newline, any}]), + ok. + +%% +%% Generate the contents of a simple .app file +%% +app(Name, Modules) -> + App = {application, Name, + [{description, atom_to_list(Name)}, + {vsn, "1"}, + {modules, Modules}, + {registered, []}, + {applications, [kernel, stdlib]}]}, + io_lib:format("~p.\n", [App]). |