Browse Source

only build invalid (not built) source deps and project apps

pull/3/head
Tristan Sloughter 10 years ago
parent
commit
8c5f312d90
6 changed files with 85 additions and 66 deletions
  1. +51
    -46
      src/rebar_app_discover.erl
  2. +11
    -2
      src/rebar_app_info.erl
  3. +4
    -3
      src/rebar_prv_compile.erl
  4. +13
    -7
      src/rebar_prv_install_deps.erl
  5. +5
    -7
      src/rebar_topo.erl
  6. +1
    -1
      test/rebar_install_deps_SUITE.erl

+ 51
- 46
src/rebar_app_discover.erl View File

@ -3,7 +3,9 @@
-export([do/2,
find_unbuilt_apps/1,
find_apps/1,
find_apps/2]).
find_apps/2,
find_app/2,
validate_application_info/1]).
do(State, LibDirs) ->
BaseDir = rebar_state:dir(State),
@ -50,51 +52,54 @@ find_apps(LibDirs) ->
find_apps(LibDirs, Validate) ->
lists:filtermap(fun(AppDir) ->
AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])),
AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])),
case AppFile of
[File] ->
AppInfo = create_app_info(AppDir, File),
AppInfo1 = rebar_app_info:app_file(AppInfo, File),
AppInfo2 = case AppSrcFile of
[F] ->
rebar_app_info:app_file_src(AppInfo1, F);
[] ->
AppInfo1
end,
case Validate of
valid ->
case validate_application_info(AppInfo2) of
true ->
{true, AppInfo2};
false ->
false
end;
invalid ->
case validate_application_info(AppInfo2) of
false ->
{true, AppInfo2};
true ->
false
end;
all ->
{true, AppInfo2}
end;
[] ->
case AppSrcFile of
[File] ->
case Validate of
V when V =:= invalid ; V =:= all ->
AppInfo = create_app_info(AppDir, File),
{true, rebar_app_info:app_file_src(AppInfo, File)};
valid ->
false
end;
[] ->
false
end
end
end, all_app_dirs(LibDirs)).
find_app(AppDir, Validate)
end, all_app_dirs(LibDirs)).
find_app(AppDir, Validate) ->
AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])),
AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])),
case AppFile of
[File] ->
AppInfo = create_app_info(AppDir, File),
AppInfo1 = rebar_app_info:app_file(AppInfo, File),
AppInfo2 = case AppSrcFile of
[F] ->
rebar_app_info:app_file_src(AppInfo1, F);
[] ->
AppInfo1
end,
case Validate of
valid ->
case validate_application_info(AppInfo2) of
true ->
{true, AppInfo2};
false ->
false
end;
invalid ->
case validate_application_info(AppInfo2) of
false ->
{true, AppInfo2};
true ->
false
end;
all ->
{true, AppInfo2}
end;
[] ->
case AppSrcFile of
[File] ->
case Validate of
V when V =:= invalid ; V =:= all ->
AppInfo = create_app_info(AppDir, File),
{true, rebar_app_info:app_file_src(AppInfo, File)};
valid ->
false
end;
[] ->
false
end
end.
app_dir(AppFile) ->
filename:join(lists:droplast(filename:split(filename:dirname(AppFile)))).

+ 11
- 2
src/rebar_app_info.erl View File

@ -5,6 +5,7 @@
new/2,
new/3,
new/4,
discover/1,
name/1,
name/2,
config/1,
@ -82,6 +83,14 @@ new(AppName, Vsn, Dir, Deps) ->
dir=Dir,
deps=Deps}}.
%% @doc discover a complete version of the app info with all fields set.
-spec discover(file:name()) ->
{ok, t()}.
discover(Dir) ->
{true, AppInfo} = rebar_app_discover:find_app(Dir, all),
{ok, AppInfo}.
-spec name(t()) -> atom().
name(#app_info_t{name=Name}) ->
Name.
@ -175,8 +184,8 @@ source(#app_info_t{source=Source}) ->
Source.
-spec valid(t()) -> boolean().
valid(#app_info_t{dir=Dir, valid=undefined}) ->
true;
valid(AppInfo=#app_info_t{valid=undefined}) ->
rebar_app_discover:validate_application_info(AppInfo);
valid(#app_info_t{valid=Valid}) ->
Valid.

+ 4
- 3
src/rebar_prv_compile.erl View File

@ -29,13 +29,14 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error().
do(State) ->
Apps = rebar_state:project_apps(State),
ProjectApps = rebar_state:project_apps(State),
Deps = rebar_state:get(State, deps_to_build, []),
lists:foreach(fun(AppInfo) ->
C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(AppInfo)),
_AppInfo1 = build(S, AppInfo)
end, Apps),
build(S, AppInfo)
end, Deps++ProjectApps),
rebar_lock:create(State),
{ok, State}.

+ 13
- 7
src/rebar_prv_install_deps.erl View File

@ -138,12 +138,19 @@ handle_deps(State, Deps) ->
end, S)
end,
FinalDeps = ordsets:union([ordsets:from_list(ProjectApps)
,rebar_state:src_deps(State2)
Source = ProjectApps ++ ordsets:to_list(rebar_state:src_deps(State2)),
AllDeps = ordsets:union([ordsets:from_list(ProjectApps)
,ordsets:to_list(rebar_state:src_deps(State2))
,ordsets:from_list(Solved)]),
%% Sort all apps to build order
{ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(FinalDeps)),
{ok, rebar_state:project_apps(State2, Sort)}.
State3 = rebar_state:set(State2, all_deps, AllDeps),
{ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)),
{ok, rebar_state:set(State3, deps_to_build, lists:dropwhile(fun is_valid/1, Sort) -- ProjectApps)}.
-spec is_valid(rebar_app_info:t()) -> boolean().
is_valid(App) ->
rebar_app_info:valid(App).
-spec package_to_app(file:name(), dict:dict(), binary(), binary()) -> rebar_app_info:t().
package_to_app(DepsDir, Packages, Name, Vsn) ->
@ -205,9 +212,8 @@ parse_deps(DepsDir, Deps) ->
(Name, {SrcDepsAcc, BinaryDepsAcc}) when is_atom(Name) ->
{SrcDepsAcc, [ec_cnv:to_binary(Name) | BinaryDepsAcc]};
({Name, _, Source}, {SrcDepsAcc, BinaryDepsAcc}) ->
{ok, Dep} = rebar_app_info:new(Name),
Dep1 = rebar_app_info:source(
rebar_app_info:dir(Dep, get_deps_dir(DepsDir, Name)), Source),
{ok, Dep} = rebar_app_info:discover(get_deps_dir(DepsDir, Name)),
Dep1 = rebar_app_info:source(Dep, Source),
{ordsets:add_element(Dep1, SrcDepsAcc), BinaryDepsAcc}
end, {ordsets:new(), []}, Deps).

+ 5
- 7
src/rebar_topo.erl View File

@ -91,15 +91,13 @@ format_error({cycle, Pairs}) ->
%%====================================================================
-spec names_to_apps([atom()], [rebar_app_info:t()]) -> [rebar_app_info:t()].
names_to_apps(Names, Apps) ->
[find_app_by_name(Name, Apps) || Name <- Names].
[element(2, App) || App <- [find_app_by_name(Name, Apps) || Name <- Names], App =/= error].
-spec find_app_by_name(atom(), [rebar_app_info:t()]) -> rebar_app_info:t().
-spec find_app_by_name(atom(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error.
find_app_by_name(Name, Apps) ->
{ok, App1} =
ec_lists:find(fun(App) ->
rebar_app_info:name(App) =:= Name
end, Apps),
App1.
ec_lists:find(fun(App) ->
rebar_app_info:name(App) =:= Name
end, Apps).
-spec apps_to_pairs([rebar_app_info:t()]) -> [pair()].
apps_to_pairs(Apps) ->

+ 1
- 1
test/rebar_install_deps_SUITE.erl View File

@ -31,7 +31,7 @@ init_per_testcase(_, Config) ->
[{apps, AppsDir}, {state, State} | Config].
all() ->
[built_basic_app].
[build_basic_app].
build_basic_app(Config) ->
AppDir = proplists:get_value(apps, Config),

Loading…
Cancel
Save