summaryrefslogtreecommitdiff
path: root/src/rebar_prv_compile.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-11-22 09:35:17 -0500
committerFred Hebert <mononcqc@ferd.ca>2017-11-22 09:41:36 -0500
commitc550cf0c4c9df09ff1fe7eca0fbe8e26fa800502 (patch)
treea1cc32a9dff081a281b0e867c3fb7b3cf96fa07a /src/rebar_prv_compile.erl
parent07e19ba60dfd04b1d81e1d5764a814f06c9dbcb2 (diff)
Fix compilation for custom resources dynamic vsn
The Erlang compiler runs based on a global state built from currently loaded libraries and the configured code path that is available. For this reason, the rebar3 compiler job unloads all plugin paths before calling the Erlang compiler. However, this causes a problem when an application uses a custom resource handler with a dynamic version in their .app.src file since the plugin that can be used to find the version has been unloaded. Fortunately, the compile phase that runs the version handling is distinct from the phase that uses the Erlang compiler. This patch fixes the problem by re-loading the plugins' paths in memory before generating the .app file, and before unloading them afterwards. It appears that unloading them is unnecessary because the hooks after that will re-load them, but it is likely better to play it safe with that global state and clean up after ourselves. It offers better protection for future changes. Fixes #1657
Diffstat (limited to 'src/rebar_prv_compile.erl')
-rw-r--r--src/rebar_prv_compile.erl13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index c9a77a5..72320fb 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -136,7 +136,18 @@ compile(State, Providers, AppInfo) ->
AppInfo3 = rebar_hooks:run_all_hooks(AppDir, post, ?ERLC_HOOK, Providers, AppInfo2, State),
AppInfo4 = rebar_hooks:run_all_hooks(AppDir, pre, ?APP_HOOK, Providers, AppInfo3, State),
- case rebar_otp_app:compile(State, AppInfo4) of
+
+ %% Load plugins back for make_vsn calls in custom resources.
+ %% The rebar_otp_app compilation step is safe regarding the
+ %% overall path management, so we can just load all plugins back
+ %% in memory.
+ PluginDepsPaths = rebar_state:code_paths(State, all_plugin_deps),
+ code:add_pathsa(PluginDepsPaths),
+ AppFileCompileResult = rebar_otp_app:compile(State, AppInfo4),
+ %% Clean up after ourselves, leave things as they were.
+ rebar_utils:remove_from_code_path(PluginDepsPaths),
+
+ case AppFileCompileResult of
{ok, AppInfo5} ->
AppInfo6 = rebar_hooks:run_all_hooks(AppDir, post, ?APP_HOOK, Providers, AppInfo5, State),
AppInfo7 = rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo6, State),