Browse Source

only build unbuilt deps

pull/3/head
Tristan Sloughter 10 years ago
parent
commit
070689632b
7 changed files with 114 additions and 83 deletions
  1. +1
    -0
      include/rebar.hrl
  2. +83
    -12
      src/rebar_app_discover.erl
  3. +17
    -0
      src/rebar_app_info.erl
  4. +2
    -2
      src/rebar_base_compiler.erl
  5. +4
    -4
      src/rebar_core.erl
  6. +6
    -64
      src/rebar_deps.erl
  7. +1
    -1
      src/rebar_prv_app_discovery.erl

+ 1
- 0
include/rebar.hrl View File

@ -24,5 +24,6 @@
opts :: list()}). % The list of options that the task requires/understands opts :: list()}). % The list of options that the task requires/understands
-define(DEFAULT_LIB_DIRS, ["apps", "libs", "."]). -define(DEFAULT_LIB_DIRS, ["apps", "libs", "."]).
-define(DEFAULT_DEPS_DIRS, ["deps"]).
-define(DEFAULT_CONFIG_FILE, "rebar.config"). -define(DEFAULT_CONFIG_FILE, "rebar.config").
-define(LOCK_FILE, "rebar.lock"). -define(LOCK_FILE, "rebar.lock").

+ 83
- 12
src/rebar_app_discover.erl View File

@ -1,10 +1,12 @@
-module(rebar_app_discover). -module(rebar_app_discover).
-export([do/2, -export([do/2,
find_apps/1]).
find_unbuilt_apps/1,
find_apps/1,
find_apps/2]).
do(State, LibDirs) -> do(State, LibDirs) ->
Apps = find_apps(LibDirs),
Apps = find_apps(LibDirs, all),
lists:foldl(fun(AppInfo, StateAcc) -> lists:foldl(fun(AppInfo, StateAcc) ->
rebar_state:add_app(StateAcc, AppInfo) rebar_state:add_app(StateAcc, AppInfo)
end, State, Apps). end, State, Apps).
@ -37,27 +39,56 @@ app_dirs(LibDir) ->
[app_dir(File) || File <- Files] ++ Acc [app_dir(File) || File <- Files] ++ Acc
end, [], [Path1, Path2, Path3, Path4])). end, [], [Path1, Path2, Path3, Path4])).
find_unbuilt_apps(LibDirs) ->
find_apps(LibDirs, invalid).
find_apps(LibDirs) -> find_apps(LibDirs) ->
lists:map(fun(AppDir) ->
find_apps(LibDirs, valid).
find_apps(LibDirs, Validate) ->
lists:filtermap(fun(AppDir) ->
AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])), AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])),
AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])),
case AppFile of case AppFile of
[File] -> [File] ->
AppInfo = create_app_info(AppDir, File), AppInfo = create_app_info(AppDir, File),
AppInfo1 = rebar_app_info:app_file(AppInfo, File), AppInfo1 = rebar_app_info:app_file(AppInfo, File),
case AppSrcFile of
[F] ->
rebar_app_info:app_file_src(AppInfo1, F);
[] ->
AppInfo1
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; end;
[] -> [] ->
case AppSrcFile of case AppSrcFile of
[File] -> [File] ->
AppInfo = create_app_info(AppDir, File),
rebar_app_info:app_file_src(AppInfo, 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;
[] -> [] ->
error
false
end end
end end
end, all_app_dirs(LibDirs)). end, all_app_dirs(LibDirs)).
@ -80,6 +111,46 @@ create_app_info(AppDir, AppFile) ->
rebar_state:new() rebar_state:new()
end, end,
AppState1 = rebar_state:set(AppState, base_dir, AbsCwd), AppState1 = rebar_state:set(AppState, base_dir, AbsCwd),
AppInfo1 = rebar_app_info:config(AppInfo, AppState1),
AppInfo1 = rebar_app_info:config(
rebar_app_info:app_details(AppInfo, AppDetails), AppState1),
rebar_app_info:dir(AppInfo1, AppDir) rebar_app_info:dir(AppInfo1, AppDir)
end. end.
-spec validate_application_info(rebar_app_info:t()) -> boolean().
validate_application_info(AppInfo) ->
EbinDir = rebar_app_info:ebin_dir(AppInfo),
AppFile = rebar_app_info:app_file(AppInfo),
AppName = rebar_app_info:app_details(AppInfo),
AppDetail = rebar_app_info:app_details(AppInfo),
AppDir = filename:dirname(EbinDir),
case get_modules_list(AppFile, AppDetail) of
{ok, List} ->
has_all_beams(EbinDir, List);
_Error ->
false
end.
-spec get_modules_list(file:name(), proplists:proplist()) ->
{ok, list()} |
{warning, Reason::term()} |
{error, Reason::term()}.
get_modules_list(AppFile, AppDetail) ->
case proplists:get_value(modules, AppDetail) of
undefined ->
{warning, {invalid_app_file, AppFile}};
ModulesList ->
{ok, ModulesList}
end.
-spec has_all_beams(file:name(), list()) ->
ok | {error, Reason::term()}.
has_all_beams(EbinDir, [Module | ModuleList]) ->
BeamFile = filename:join([EbinDir,
list_to_binary(atom_to_list(Module) ++ ".beam")]),
case filelib:is_file(BeamFile) of
true ->
has_all_beams(EbinDir, ModuleList);
false ->
false
end;
has_all_beams(_, []) ->
true.

+ 17
- 0
src/rebar_app_info.erl View File

@ -10,8 +10,11 @@
app_file_src/2, app_file_src/2,
app_file/1, app_file/1,
app_file/2, app_file/2,
app_details/1,
app_details/2,
original_vsn/1, original_vsn/1,
original_vsn/2, original_vsn/2,
ebin_dir/1,
dir/1, dir/1,
dir/2]). dir/2]).
@ -22,6 +25,7 @@
app_file :: file:name(), app_file :: file:name(),
config :: rebar_config:config() | undefined, config :: rebar_config:config() | undefined,
original_vsn :: string(), original_vsn :: string(),
app_details :: list(),
dir :: file:name(), dir :: file:name(),
source :: string() | undefined}). source :: string() | undefined}).
@ -81,6 +85,14 @@ app_file(#app_info_t{app_file=AppFile}) ->
app_file(AppInfo=#app_info_t{}, AppFile) -> app_file(AppInfo=#app_info_t{}, AppFile) ->
AppInfo#app_info_t{app_file=AppFile}. AppInfo#app_info_t{app_file=AppFile}.
-spec app_details(t()) -> list().
app_details(#app_info_t{app_details=AppDetails}) ->
AppDetails.
-spec app_details(t(), list()) -> t().
app_details(AppInfo=#app_info_t{}, AppDetails) ->
AppInfo#app_info_t{app_details=AppDetails}.
-spec original_vsn(t()) -> string(). -spec original_vsn(t()) -> string().
original_vsn(#app_info_t{original_vsn=Vsn}) -> original_vsn(#app_info_t{original_vsn=Vsn}) ->
Vsn. Vsn.
@ -92,6 +104,11 @@ original_vsn(AppInfo=#app_info_t{}, Vsn) ->
-spec dir(t()) -> file:name(). -spec dir(t()) -> file:name().
dir(#app_info_t{dir=Dir}) -> dir(#app_info_t{dir=Dir}) ->
Dir. Dir.
-spec dir(t(), file:name()) -> t(). -spec dir(t(), file:name()) -> t().
dir(AppInfo=#app_info_t{}, Dir) -> dir(AppInfo=#app_info_t{}, Dir) ->
AppInfo#app_info_t{dir=Dir}. AppInfo#app_info_t{dir=Dir}.
-spec ebin_dir(t()) -> file:name().
ebin_dir(#app_info_t{dir=Dir}) ->
filename:join(Dir, "ebin").

+ 2
- 2
src/rebar_base_compiler.erl View File

@ -173,11 +173,11 @@ compile_queue(Config, Pids, Targets) ->
{compiled, Source, Warnings} -> {compiled, Source, Warnings} ->
report(Warnings), report(Warnings),
?CONSOLE("Compiled ~s\n", [Source]),
?INFO("Compiled ~s\n", [Source]),
compile_queue(Config, Pids, Targets); compile_queue(Config, Pids, Targets);
{compiled, Source} -> {compiled, Source} ->
?CONSOLE("Compiled ~s\n", [Source]),
?INFO("Compiled ~s\n", [Source]),
compile_queue(Config, Pids, Targets); compile_queue(Config, Pids, Targets);
{skipped, Source} -> {skipped, Source} ->

+ 4
- 4
src/rebar_core.erl View File

@ -37,17 +37,17 @@
process_command(State, Command) -> process_command(State, Command) ->
true = rebar_utils:expand_code_path(), true = rebar_utils:expand_code_path(),
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS), LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
DepsDir = rebar_state:get(State, deps_dir, "deps"),
DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIRS),
_UpdatedCodePaths = update_code_path([DepsDir | LibDirs]), _UpdatedCodePaths = update_code_path([DepsDir | LibDirs]),
rebar_deps:setup_env(State), rebar_deps:setup_env(State),
State2 = rebar_app_discover:do(State, LibDirs),
TargetProviders = rebar_provider:get_target_providers(Command, State2),
TargetProviders = rebar_provider:get_target_providers(Command, State),
lists:foldl(fun(TargetProvider, Conf) -> lists:foldl(fun(TargetProvider, Conf) ->
Provider = rebar_provider:get_provider(TargetProvider, rebar_state:providers(Conf)), Provider = rebar_provider:get_provider(TargetProvider, rebar_state:providers(Conf)),
{ok, Conf1} = rebar_provider:do(Provider, Conf), {ok, Conf1} = rebar_provider:do(Provider, Conf),
Conf1 Conf1
end, State2, TargetProviders).
end, State, TargetProviders).
update_code_path([]) -> update_code_path([]) ->
no_change; no_change;

+ 6
- 64
src/rebar_deps.erl View File

@ -79,12 +79,13 @@ update_deps(Config, Deps) ->
DepsDir = get_deps_dir(Config), DepsDir = get_deps_dir(Config),
%% Find available apps to fulfill dependencies %% Find available apps to fulfill dependencies
UnbuiltApps = rebar_app_discover:find_unbuilt_apps([DepsDir]),
FoundApps = rebar_app_discover:find_apps([DepsDir]), FoundApps = rebar_app_discover:find_apps([DepsDir]),
%% Resolve deps and their dependencies %% Resolve deps and their dependencies
Deps1 = handle_deps(Deps, FoundApps),
Deps1 = handle_deps(Deps, UnbuiltApps++FoundApps),
case download_missing_deps(Config, DepsDir, FoundApps, Deps1) of
case download_missing_deps(Config, DepsDir, FoundApps, UnbuiltApps, Deps1) of
{Config1, []} -> {Config1, []} ->
{Config1, Deps1}; {Config1, Deps1};
{Config1, _} -> {Config1, _} ->
@ -106,12 +107,11 @@ handle_deps(Deps, Found) ->
element(1, A) =:= element(1, B) element(1, A) =:= element(1, B)
end, lists:usort(Deps), lists:usort(NewDeps1)). end, lists:usort(Deps), lists:usort(NewDeps1)).
download_missing_deps(Config, DepsDir, Found, Deps) ->
Apps = rebar_state:apps_to_build(Config),
download_missing_deps(Config, DepsDir, Found, Unbuilt, Deps) ->
Missing = lists:filter(fun(X) -> Missing = lists:filter(fun(X) ->
not lists:any(fun(F) -> not lists:any(fun(F) ->
element(1, X) =:= element(2, F) element(1, X) =:= element(2, F)
end, Found++Apps)
end, Found++Unbuilt)
end, Deps), end, Deps),
ec_plists:foreach(fun(X) -> ec_plists:foreach(fun(X) ->
TargetDir = get_deps_dir(DepsDir, element(1, X)), TargetDir = get_deps_dir(DepsDir, element(1, X)),
@ -125,7 +125,7 @@ download_missing_deps(Config, DepsDir, Found, Deps) ->
Config1 = lists:foldl(fun(X, ConfigAcc) -> Config1 = lists:foldl(fun(X, ConfigAcc) ->
TargetDir = get_deps_dir(DepsDir, element(1, X)), TargetDir = get_deps_dir(DepsDir, element(1, X)),
[AppSrc] = rebar_app_discover:find_apps([TargetDir]),
[AppSrc] = rebar_app_discover:find_unbuilt_apps([TargetDir]),
rebar_state:add_app(ConfigAcc, AppSrc) rebar_state:add_app(ConfigAcc, AppSrc)
end, Config, Missing), end, Config, Missing),
@ -161,64 +161,6 @@ get_deps_dir(DepsDir, App) ->
%% Internal functions %% Internal functions
%% =================================================================== %% ===================================================================
-spec gather_application_info(file:name(), file:filename()) ->
{ok, rebar_app_info:t()} |
{warning, Reason::term()} |
{error, Reason::term()}.
gather_application_info(EbinDir, File) ->
AppDir = filename:dirname(EbinDir),
case file:consult(File) of
{ok, [{application, AppName, AppDetail}]} ->
validate_application_info(EbinDir, File, AppName, AppDetail);
{error, Reason} ->
{warning, {unable_to_load_app, AppDir, Reason}};
_ ->
{warning, {invalid_app_file, File}}
end.
-spec validate_application_info(file:name(),
file:name(),
atom(),
proplists:proplist()) ->
{ok, list()} |
{warning, Reason::term()} |
{error, Reason::term()}.
validate_application_info(EbinDir, AppFile, AppName, AppDetail) ->
AppDir = filename:dirname(EbinDir),
case get_modules_list(AppFile, AppDetail) of
{ok, List} ->
has_all_beams(EbinDir, List);
Error ->
Error
end.
-spec get_modules_list(file:name(), proplists:proplist()) ->
{ok, list()} |
{warning, Reason::term()} |
{error, Reason::term()}.
get_modules_list(AppFile, AppDetail) ->
case proplists:get_value(modules, AppDetail) of
undefined ->
{warning, {invalid_app_file, AppFile}};
ModulesList ->
{ok, ModulesList}
end.
-spec has_all_beams(file:name(), list()) ->
ok | {error, Reason::term()}.
has_all_beams(EbinDir, [Module | ModuleList]) ->
BeamFile = filename:join([EbinDir,
list_to_binary(atom_to_list(Module) ++ ".beam")]),
case filelib:is_file(BeamFile) of
true ->
has_all_beams(EbinDir, ModuleList);
false ->
{warning, {missing_beam_file, Module, BeamFile}}
end;
has_all_beams(_, []) ->
ok.
info(help, 'deps') -> info(help, 'deps') ->
info_help("Display dependencies"). info_help("Display dependencies").

+ 1
- 1
src/rebar_prv_app_discovery.erl View File

@ -32,5 +32,5 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
do(State) -> do(State) ->
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS), LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
State1 = rebar_app_discover:do(State, ["deps" | LibDirs]),
State1 = rebar_app_discover:do(State, LibDirs),
{ok, State1}. {ok, State1}.

Loading…
Cancel
Save