浏览代码

store plugin providers in app_info's state for deps

pull/474/head
Tristan Sloughter 10 年前
父节点
当前提交
7d33dbf6aa
共有 6 个文件被更改,包括 43 次插入27 次删除
  1. +1
    -0
      src/rebar_core.erl
  2. +3
    -1
      src/rebar_hooks.erl
  3. +0
    -1
      src/rebar_prv_compile.erl
  4. +24
    -7
      src/rebar_prv_install_deps.erl
  5. +2
    -1
      test/mock_pkg_resource.erl
  6. +13
    -17
      test/rebar_compile_SUITE.erl

+ 1
- 0
src/rebar_core.erl 查看文件

@ -119,6 +119,7 @@ do([ProviderName | Rest], State) ->
,rebar_state:providers(State)
,rebar_state:namespace(State))
end,
case providers:do(Provider, State) of
{ok, State1} ->
do(Rest, State1);

+ 3
- 1
src/rebar_hooks.erl 查看文件

@ -12,10 +12,12 @@ run_all_hooks(Dir, Type, Command, Providers, State) ->
run_provider_hooks(Dir, Type, Command, Providers, State) ->
PluginDepsPaths = rebar_state:code_paths(State, all_plugin_deps),
code:add_pathsa(PluginDepsPaths),
State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers),
Providers1 = rebar_state:providers(State),
State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers++Providers1),
AllHooks = rebar_state:get(State1, provider_hooks, []),
TypeHooks = proplists:get_value(Type, AllHooks, []),
HookProviders = proplists:get_all_values(Command, TypeHooks),
State2 = rebar_core:do(HookProviders, State1),
rebar_utils:remove_from_code_path(PluginDepsPaths),
State2.

+ 0
- 1
src/rebar_prv_compile.erl 查看文件

@ -36,7 +36,6 @@ do(State) ->
rebar_utils:remove_from_code_path(PluginDepsPaths),
code:add_pathsa(DepsPaths),
ProjectApps = rebar_state:project_apps(State),
Providers = rebar_state:providers(State),
Deps = rebar_state:deps_to_build(State),

+ 24
- 7
src/rebar_prv_install_deps.erl 查看文件

@ -227,7 +227,22 @@ handle_pkg_dep(Profile, Pkg, Packages, Upgrade, DepsDir, Fetched, Seen, Locks, S
Level = rebar_app_info:dep_level(AppInfo),
{NewSeen, NewState} = maybe_lock(Profile, AppInfo, Seen, State, Level),
{_, AppInfo1} = maybe_fetch(AppInfo, Profile, Upgrade, Seen, NewState),
{[AppInfo1 | Fetched], NewSeen, NewState}.
Profiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo1),
C = rebar_config:consult(rebar_app_info:dir(AppInfo1)),
BaseDir = rebar_state:get(State, base_dir, []),
S1 = rebar_state:new(rebar_state:set(rebar_state:new(), base_dir, BaseDir),
C, rebar_app_info:dir(AppInfo1)),
S2 = rebar_state:apply_profiles(S1, Profiles),
S3 = rebar_state:apply_overrides(S2, Name),
AppInfo2 = rebar_app_info:state(AppInfo1, S3),
%% Dep may have plugins to install. Find and install here.
S4 = rebar_plugins:handle_plugins(rebar_state:get(S3, plugins, []), S3),
AppInfo3 = rebar_app_info:state(AppInfo2, S4),
{[AppInfo3 | Fetched], NewSeen, NewState}.
maybe_lock(Profile, AppInfo, Seen, State, Level) ->
case rebar_app_info:is_checkout(AppInfo) of
@ -386,14 +401,16 @@ handle_dep(State, DepsDir, AppInfo, Locks, Level) ->
AppInfo1 = rebar_app_info:state(AppInfo, S3),
%% Dep may have plugins to install. Find and install here.
State1 = rebar_plugins:handle_plugins(rebar_state:get(S3, plugins, []), State),
Deps = rebar_state:get(S3, deps, []),
S4 = rebar_plugins:handle_plugins(rebar_state:get(S3, plugins, []), S3),
AppInfo2 = rebar_app_info:state(AppInfo1, S4),
%% Upgrade lock level to be the level the dep will have in this dep tree
Deps = rebar_state:get(S4, deps, []),
NewLocks = [{DepName, Source, LockLevel+Level} ||
{DepName, Source, LockLevel} <- rebar_state:get(S3, {locks, default}, [])],
AppInfo2 = rebar_app_info:deps(AppInfo1, rebar_state:deps_names(Deps)),
{SrcDeps, PkgDeps} = parse_deps(DepsDir, Deps, S3, Locks, Level+1),
{AppInfo2, SrcDeps, PkgDeps, Locks++NewLocks, State1}.
{DepName, Source, LockLevel} <- rebar_state:get(S4, {locks, default}, [])],
AppInfo3 = rebar_app_info:deps(AppInfo2, rebar_state:deps_names(Deps)),
{SrcDeps, PkgDeps} = parse_deps(DepsDir, Deps, S4, Locks, Level+1),
{AppInfo3, SrcDeps, PkgDeps, Locks++NewLocks, State}.
-spec maybe_fetch(rebar_app_info:t(), atom(), boolean(),
sets:set(binary()), rebar_state:t()) -> {boolean(), rebar_app_info:t()}.

+ 2
- 1
test/mock_pkg_resource.erl 查看文件

@ -73,6 +73,7 @@ mock_vsn(_Opts) ->
%% into a `rebar.config' file to describe dependencies.
mock_download(Opts) ->
Deps = proplists:get_value(pkgdeps, Opts, []),
Config = proplists:get_value(config, Opts, []),
meck:expect(
?MOD, download,
fun (Dir, {pkg, AppBin, Vsn}, _) ->
@ -83,7 +84,7 @@ mock_download(Opts) ->
Dir, App, binary_to_list(Vsn),
[kernel, stdlib] ++ [element(1,D) || D <- AppDeps]
),
rebar_test_utils:create_config(Dir, [{deps, AppDeps}]),
rebar_test_utils:create_config(Dir, [{deps, AppDeps}]++Config),
TarApp = App++"-"++binary_to_list(Vsn)++".tar",
Tarball = filename:join([Dir, TarApp]),
Contents = filename:join([Dir, "contents.tar.gz"]),

+ 13
- 17
test/rebar_compile_SUITE.erl 查看文件

@ -410,17 +410,19 @@ compile_plugins(Config) ->
DepName = rebar_test_utils:create_random_name("dep1_"),
PluginName = rebar_test_utils:create_random_name("plugin1_"),
mock_git_resource:mock([{config, [{plugins, [
{list_to_atom(PluginName), Vsn}
]}]}]),
mock_pkg_resource:mock([
{pkgdeps, [{{iolist_to_binary(PluginName), iolist_to_binary(Vsn)}, []}]}
]),
Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}]),
mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Plugins)}]),
mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]},
{config, [{plugins, [
{list_to_atom(PluginName),
{git, "http://site.com/user/"++PluginName++".git",
{tag, Vsn}}}]}]}]),
RConfFile =
rebar_test_utils:create_config(AppDir,
[{deps, [
{list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
list_to_atom(DepName)
]}]),
{ok, RConf} = file:consult(RConfFile),
@ -498,16 +500,10 @@ complex_plugins(Config) ->
DepName3 = rebar_test_utils:create_random_name("dep3_"),
PluginName = rebar_test_utils:create_random_name("plugin1_"),
Plugin = {{PluginName, Vsn2}, [{list_to_atom(DepName2),
{git, "http://site.com/user/"++DepName2++".git", {tag, Vsn}}}]},
Dep2 = {{DepName2, Vsn},
[{list_to_atom(DepName3),
{git, "http://site.com/user/"++DepName3++".git", {tag, Vsn}}}]},
mock_git_resource:mock([{deps, [Plugin,
Dep2,
{{iolist_to_binary(DepName), iolist_to_binary(Vsn)}, []},
{{iolist_to_binary(DepName3), iolist_to_binary(Vsn)}, []}]}]),
Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn2, [{DepName2, Vsn,
[{DepName3, Vsn, []}]}]}
,{DepName, Vsn, []}]),
mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]),
RConfFile =
rebar_test_utils:create_config(AppDir,

正在加载...
取消
保存