浏览代码

quick and dirty fix for proper dep compilatoin order

pull/3/head
Tristan Sloughter 10 年前
父节点
当前提交
901cea4671
共有 5 个文件被更改,包括 48 次插入30 次删除
  1. +2
    -0
      rebar.config
  2. +11
    -1
      src/rebar_app_info.erl
  3. +2
    -2
      src/rebar_prv_app_builder.erl
  4. +32
    -25
      src/rebar_prv_install_deps.erl
  5. +1
    -2
      src/rebar_prv_update.erl

+ 2
- 0
rebar.config 查看文件

@ -1,6 +1,8 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
{rebar_packages_url, "http://localhost:8080"}.
%% escript_incl_extra is for internal rebar-private use only.
%% Do not use outside rebar. Config interface is not stable.
{escript_incl_extra, [{"priv/templates/*", "."}]}.

+ 11
- 1
src/rebar_app_info.erl 查看文件

@ -16,7 +16,9 @@
original_vsn/2,
ebin_dir/1,
dir/1,
dir/2]).
dir/2,
source/1,
source/2]).
-export_type([t/0]).
@ -110,3 +112,11 @@ dir(AppInfo=#app_info_t{}, Dir) ->
-spec ebin_dir(t()) -> file:name().
ebin_dir(#app_info_t{dir=Dir}) ->
filename:join(Dir, "ebin").
-spec source(t(), string()) -> t().
source(AppInfo=#app_info_t{}, Source) ->
AppInfo#app_info_t{source=Source}.
-spec source(t()) -> string().
source(#app_info_t{source=Source}) ->
Source.

+ 2
- 2
src/rebar_prv_app_builder.erl 查看文件

@ -32,8 +32,6 @@ do(State) ->
Apps = rebar_state:apps_to_build(State),
lists:foreach(fun(AppInfo) ->
?INFO("Compiling ~s ~s~n", [rebar_app_info:name(AppInfo)
,rebar_app_info:original_vsn(AppInfo)]),
_AppInfo1 = build(State, AppInfo)
end, Apps),
@ -41,6 +39,8 @@ do(State) ->
{ok, State}.
build(State, AppInfo) ->
?INFO("Compiling ~s ~s~n", [rebar_app_info:name(AppInfo)
,rebar_app_info:original_vsn(AppInfo)]),
rebar_erlc_compiler:compile(State, rebar_app_info:dir(AppInfo)),
{ok, AppInfo1} = rebar_otp_app:compile(State, AppInfo),
AppInfo1.

+ 32
- 25
src/rebar_prv_install_deps.erl 查看文件

@ -74,7 +74,7 @@ do(State) ->
Deps ->
%% Split source deps form binary deps, needed to keep backwards compatibility
{SrcDeps, Goals} = parse_deps(Deps),
case update_src_deps(State, SrcDeps, Goals, []) of
case update_src_deps(State, SrcDeps, Goals, [], []) of
{State1, SrcDeps1, [], Locked} ->
{ok, rebar_state:set(State1, locks, Locked)};
{State1, SrcDeps1, Goals1, Locked} ->
@ -89,14 +89,14 @@ do(State) ->
,FmtVsn
,Link}}
end, Solved),
{State2, Deps1, Locked2} = update_deps(State1, M),
{State2, Deps1, _, Locked2} = update_deps(State1, M),
State3 = rebar_state:set(State2, locks, Locked++Locked2),
{ok, rebar_state:set(State3, goals, Goals1)}
end
end;
Locks ->
Locks1 = [new(Lock) || Lock <- Locks],
{State2, _, _} = update_deps(State, Locks1),
{State2, _, _, _} = update_deps(State, Locks1),
{ok, State2}
end.
@ -148,24 +148,39 @@ update_deps(State, Deps) ->
UnbuiltApps = rebar_app_discover:find_unbuilt_apps([DepsDir]),
FoundApps = rebar_app_discover:find_apps([DepsDir]),
download_missing_deps(State, DepsDir, FoundApps, Deps).
download_missing_deps(State, DepsDir, UnbuiltApps++FoundApps, Deps).
%% Find source deps to build and download
update_src_deps(State, Deps, Goals, Locked) ->
update_src_deps(State, Deps, Goals, SrcApps, Locked) ->
DepsDir = get_deps_dir(State),
%% Find available apps to fulfill dependencies
%% Should only have to do this once, not every iteration
%UnbuiltApps = rebar_app_discover:find_unbuilt_apps([DepsDir]),
UnbuiltApps = rebar_app_discover:find_unbuilt_apps([DepsDir]),
FoundApps = rebar_app_discover:find_apps([DepsDir]),
%% Resolve deps and their dependencies
{Deps1, NewGoals} = handle_src_deps(Deps, FoundApps, Goals),
case download_missing_deps(State, DepsDir, FoundApps, Deps1) of
{State1, [], []} ->
{State1, Deps1, NewGoals, Locked};
{State1, Missing, Locked1} ->
update_src_deps(State1, Missing, NewGoals, Locked1++Locked)
{Deps1, NewGoals} = handle_src_deps(Deps, UnbuiltApps++FoundApps, Goals),
case download_missing_deps(State, DepsDir, UnbuiltApps++FoundApps, Deps1) of
{State1, [], SrcApps1, []} ->
Locked1 = lists:map(fun(AppSrc) ->
Source = rebar_app_info:source(AppSrc),
Name = rebar_app_info:name(AppSrc),
C = rebar_config:consult(rebar_app_info:dir(AppSrc)),
S = rebar_state:new(rebar_state:new()
,C
,rebar_app_info:dir(AppSrc)),
TargetDir = get_deps_dir(DepsDir, Name),
Ref = rebar_fetch:current_ref(binary_to_list(TargetDir), Source),
AppInfo = rebar_prv_app_builder:build(S, AppSrc),
{Name
,ec_cnv:to_binary(rebar_app_info:original_vsn(AppInfo))
,erlang:setelement(3, Source, Ref)}
end, SrcApps1++SrcApps),
{State1, Deps1, NewGoals, Locked1++Locked};
{State1, Missing, SrcApps1, Locked1} ->
update_src_deps(State1, Missing, NewGoals, SrcApps1++SrcApps, Locked1++Locked)
end.
%% Collect deps of new deps
@ -185,28 +200,20 @@ download_missing_deps(State, DepsDir, Found, Deps) ->
Name =:= rebar_app_info:name(F)
end, Found)
end, Deps),
Locked = lists:map(fun(Dep=#dep{name=Name, source=Source}) ->
{SrcApps, Locked} = lists:foldl(fun(Dep=#dep{name=Name, source=Source}, {SrcAppsAcc, LockedAcc}) ->
TargetDir = get_deps_dir(DepsDir, Name),
?INFO("Fetching ~s ~s~n", [Name
,element(2, Source)]),
rebar_fetch:download_source(TargetDir, Source),
case rebar_app_discover:find_unbuilt_apps([TargetDir]) of
[AppSrc] ->
C = rebar_config:consult(rebar_app_info:dir(AppSrc)),
S = rebar_state:new(rebar_state:new()
,C
,rebar_app_info:dir(AppSrc)),
AppInfo = rebar_prv_app_builder:build(S, AppSrc),
Ref = rebar_fetch:current_ref(binary_to_list(TargetDir), Source),
{Name
,ec_cnv:to_binary(rebar_app_info:original_vsn(AppInfo))
,erlang:setelement(3, Source, Ref)};
{[rebar_app_info:source(AppSrc, Source) | SrcAppsAcc], LockedAcc};
[] ->
Source
{SrcAppsAcc, [Source | LockedAcc]}
end
end, Missing),
end, {[], []}, Missing),
{State, Missing, Locked}.
{State, Missing, lists:reverse(SrcApps), Locked}.
parse_deps(Deps) ->
lists:foldl(fun({Name, Vsn}, {SrcDepsAcc, GoalsAcc}) ->

+ 1
- 2
src/rebar_prv_update.erl 查看文件

@ -51,9 +51,8 @@ do(State) ->
{ok, State1};
[] ->
?INFO("Updating package index...", []),
?INFO("Updating package index...~n", []),
Url = url(State),
io:format("Url ~s~n", [Url]),
ec_file:mkdir_p(filename:join([os:getenv("HOME"), ".rebar"])),
PackagesFile = filename:join([os:getenv("HOME"), ".rebar", "packages"]),
{ok, RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile}, {sync, false}]),

正在加载...
取消
保存