diff --git a/bootstrap b/bootstrap index c338624f..b58f1e52 100755 --- a/bootstrap +++ b/bootstrap @@ -20,10 +20,11 @@ main(_) -> %% cause weird failures when compilers get modified between releases. rm_rf("_build/prod"), %% The same pattern happens with default/ as well, particularly when - %% developing new things. - %% Keep other deps in default/lib for build environments like Nix + %% developing new things. + %% Keep other deps in /lib for build environments like Nix %% where internet access is disabled that deps are not downloadable. rm_rf("_build/default/lib/rebar"), + rm_rf("_build/test/lib/rebar"), %% We fetch a few deps from hex for boostraping, %% so we must compile r3_safe_erl_term.xrl which diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 3bbd4a88..7fe56b69 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -117,12 +117,11 @@ handle_plugin(Profile, Plugin, State, Upgrade) -> PreBuiltApps = [A || A <- Apps, Ebin <- [rebar_app_info:ebin_dir(A)], not lists:member(Ebin, ToBuildPaths)], - {PreUnsafe, PreSafe} = lists:partition(fun needs_rebuild/1, PreBuiltApps), - PreBuiltPaths = [rebar_app_info:ebin_dir(A) || A <- PreSafe], + PreBuiltPaths = [rebar_app_info:ebin_dir(A) || A <- PreBuiltApps], code:add_pathsa(PreBuiltPaths), %% Build plugin and its deps - [build_plugin(AppInfo, Apps, State2) || AppInfo <- PreUnsafe++ToBuild], + build_plugins(ToBuild -- PreBuiltApps, Apps, State2), %% Add newly built deps and plugin to code path State3 = rebar_state:update_all_plugin_deps(State2, Apps), @@ -140,11 +139,14 @@ handle_plugin(Profile, Plugin, State, Upgrade) -> {[], State} end. -build_plugin(AppInfo, Apps, State) -> - Providers = rebar_state:providers(State), - S = rebar_state:all_deps(State, Apps), - S1 = rebar_state:set(S, deps_dir, ?DEFAULT_PLUGINS_DIR), - rebar_prv_compile:compile(S1, Providers, AppInfo). +build_plugins(MustBuildApps, AllApps, State) -> + State1 = rebar_state:deps_to_build(State, MustBuildApps), + State2 = rebar_state:all_deps(State1, AllApps), + State3 = rebar_state:set(State2, deps_dir, ?DEFAULT_PLUGINS_DIR), + {Args, Extra} = rebar_state:command_parsed_args(State), + State4 = rebar_state:command_parsed_args(State3, {[{deps_only, true}|Args], Extra}), + rebar_prv_compile:do(State4), + ok. plugin_providers({Plugin, _, _, _}) when is_atom(Plugin) -> validate_plugin(Plugin); @@ -171,38 +173,3 @@ validate_plugin(Plugin) -> end end. -%% @private do a quick validation of whether a plugin is expected to need -%% to be rebuilt; usually this is handled by the compiler, but since this -%% module does quick filtering by detection, we need to discriminate against -%% cases like the compiler version having changed that would otherwise -%% trigger a rebuild. -needs_rebuild(AppInfo) -> - Ebin = rebar_app_info:ebin_dir(AppInfo), - application:load(compiler), - {ok, CurrentCompileVsn} = application:get_key(compiler, vsn), - case find_some_beam(Ebin) of - {ok, Beam} -> - case beam_lib:chunks(Beam, [compile_info]) of - {ok, {_mod, Chunks}} -> - CompileInfo = proplists:get_value(compile_info, Chunks, []), - CompileVsn = proplists:get_value(version, CompileInfo, "unknown"), - CurrentCompileVsn =/= CompileVsn; - _ -> - %% could be built without debug_info - false - end; - _ -> - %% well we would expect a plugin to have a beam file - true - end. - -find_some_beam(Path) -> - case file:list_dir(Path) of - {error, Reason} -> - {error, Reason}; - {ok, Files} -> - case lists:dropwhile(fun(P) -> filename:extension(P) =/= ".beam" end, Files) of - [Beam|_] -> {ok, filename:join(Path, Beam)}; - _ -> {error, no_beam} - end - end.