From 275f2981aa02fdb1c62f2aeb7be83601750a8ae5 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 4 Jul 2020 12:37:31 -0600 Subject: [PATCH] prv_plugins_upgrade: fix compilation of upgraded plugins this fixes the issue where using 'rebar3 plugins upgrade P' would result in a plugin's .app file having an empty modules list. The code this replaces hadn't been touched since rebar3 3.0.0-beta.3 and a lot of improvements have gone into dep handling and the compiler since then. This change should take advantage of those changes. --- src/rebar_prv_compile.erl | 2 +- src/rebar_prv_plugins_upgrade.erl | 14 +++++--------- test/rebar_plugins_SUITE.erl | 8 ++++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 7537b63c..252c3620 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -6,7 +6,7 @@ do/1, format_error/1]). --export([compile/2, compile/3]). +-export([compile/2, compile/3, compile/4]). -include_lib("providers/include/providers.hrl"). -include("rebar.hrl"). diff --git a/src/rebar_prv_plugins_upgrade.erl b/src/rebar_prv_plugins_upgrade.erl index 39107c91..bf51f903 100644 --- a/src/rebar_prv_plugins_upgrade.erl +++ b/src/rebar_prv_plugins_upgrade.erl @@ -62,7 +62,7 @@ upgrade(Plugin, State) -> ?PRV_ERROR({not_found, Plugin}); {ok, P, Profile} -> State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR), - {Apps, _State2} = rebar_prv_install_deps:handle_deps_as_profile(Profile, State1, [P], true), + {Apps, State2} = rebar_prv_install_deps:handle_deps_as_profile(Profile, State1, [P], true), {no_cycle, Sorted} = rebar_prv_install_deps:find_cycles(Apps), ToBuild = rebar_prv_install_deps:cull_compile(Sorted, []), @@ -72,7 +72,8 @@ upgrade(Plugin, State) -> code:add_pathsa(CodePaths), %% Build plugin and its deps - [build_plugin(AppInfo, Apps, State) || AppInfo <- ToBuild], + _ = build_plugin(ToBuild, State2), + {ok, State} end. @@ -88,11 +89,6 @@ find_plugin(Plugin, Profiles, State) -> end end, Profiles). -build_plugin(AppInfo, Apps, State) -> +build_plugin(ToBuild, State) -> Providers = rebar_state:providers(State), - Resources = rebar_state:resources(State), - AppDir = rebar_app_info:dir(AppInfo), - C = rebar_config:consult(AppDir), - S = rebar_state:new(rebar_state:all_deps(rebar_state:new(), Apps), C, AppDir), - AppInfo1 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C), - rebar_prv_compile:compile(rebar_state:set_resources(S, Resources), Providers, AppInfo1). + rebar_prv_compile:compile(State, Providers, ToBuild, plugins). diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl index c7a5d51d..16993f3c 100644 --- a/test/rebar_plugins_SUITE.erl +++ b/test/rebar_plugins_SUITE.erl @@ -191,13 +191,17 @@ upgrade(Config) -> {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]} ]), + %% beam file to verify plugin is acutally compiled + PluginBeam = filename:join([AppDir, "_build", "default", "plugins", + PkgName, "ebin", [PkgName, ".beam"]]), + RConfFile = rebar_test_utils:create_config(AppDir, [{plugins, [list_to_atom(PkgName)]}]), {ok, RConf} = file:consult(RConfFile), %% Build with deps. rebar_test_utils:run_and_check( Config, RConf, ["compile"], - {ok, [{app, Name}, {plugin, PkgName, <<"0.1.1">>}]} + {ok, [{app, Name, valid}, {file, PluginBeam}, {plugin, PkgName, <<"0.1.1">>}]} ), catch mock_pkg_resource:unmock(), @@ -212,7 +216,7 @@ upgrade(Config) -> %% Build with deps. rebar_test_utils:run_and_check( Config, RConf, ["plugins", "upgrade", PkgName], - {ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]} + {ok, [{app, Name, valid}, {file, PluginBeam}, {plugin, PkgName, <<"0.1.3">>}]} ). upgrade_project_plugin(Config) ->