diff options
| -rw-r--r-- | src/rebar_core.erl | 85 | ||||
| -rw-r--r-- | src/rebar_deps.erl | 101 | ||||
| -rw-r--r-- | src/rebar_erlc_compiler.erl | 1 | 
3 files changed, 113 insertions, 74 deletions
| diff --git a/src/rebar_core.erl b/src/rebar_core.erl index cd5df50..0279971 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -221,45 +221,52 @@ filter_flags([Item | Rest], Commands) ->  process_dir(Dir, ParentConfig, Commands) -> -    ok = file:set_cwd(Dir), -    Config = rebar_config:new(ParentConfig), - -    %% Save the current code path and then update it with -    %% lib_dirs. Children inherit parents code path, but we -    %% also want to ensure that we restore everything to pristine -    %% condition after processing this child -    CurrentCodePath = update_code_path(Config), - -    %% Get the list of processing modules and check each one against -    %% CWD to see if it's a fit -- if it is, use that set of modules -    %% to process this dir. -    {ok, AvailModuleSets} = application:get_env(rebar, modules), -    {DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets, Dir), - -    %% Get the list of modules for "any dir". This is a catch-all list of modules -    %% that are processed in addion to modules associated with this directory -    %% type. These any_dir modules are processed FIRST. -    {ok, AnyDirModules} = application:get_env(rebar, any_dir_modules), -    Modules = AnyDirModules ++ DirModules, - -    %% Give the modules a chance to tweak config and indicate if there -    %% are any other dirs that might need processing first. -    {UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []), -                                        preprocess, Config, ModuleSetFile, []), -    ?DEBUG("~s subdirs: ~p\n", [Dir, Dirs]), -    [process_dir(D, UpdatedConfig, Commands) || D <- Dirs], - -    %% Make sure the CWD is reset properly; processing subdirs may have caused it -    %% to change -    ok = file:set_cwd(Dir), - -    %% Finally, process the current working directory -    apply_commands(Commands, Modules, UpdatedConfig, ModuleSetFile), - -    %% Once we're all done processing, reset the code path to whatever -    %% the parent initialized it to -    restore_code_path(CurrentCodePath), -    ok. +    case filelib:is_dir(Dir) of +        false -> +            ?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]), +            ok; + +        true -> +            ok = file:set_cwd(Dir), +            Config = rebar_config:new(ParentConfig), + +            %% Save the current code path and then update it with +            %% lib_dirs. Children inherit parents code path, but we +            %% also want to ensure that we restore everything to pristine +            %% condition after processing this child +            CurrentCodePath = update_code_path(Config), + +            %% Get the list of processing modules and check each one against +            %% CWD to see if it's a fit -- if it is, use that set of modules +            %% to process this dir. +            {ok, AvailModuleSets} = application:get_env(rebar, modules), +            {DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets, Dir), + +            %% Get the list of modules for "any dir". This is a catch-all list of modules +            %% that are processed in addion to modules associated with this directory +            %% type. These any_dir modules are processed FIRST. +            {ok, AnyDirModules} = application:get_env(rebar, any_dir_modules), +            Modules = AnyDirModules ++ DirModules, + +            %% Give the modules a chance to tweak config and indicate if there +            %% are any other dirs that might need processing first. +            {UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []), +                                                preprocess, Config, ModuleSetFile, []), +            ?DEBUG("~s subdirs: ~p\n", [Dir, Dirs]), +            [process_dir(D, UpdatedConfig, Commands) || D <- Dirs], + +            %% Make sure the CWD is reset properly; processing subdirs may have caused it +            %% to change +            ok = file:set_cwd(Dir), + +            %% Finally, process the current working directory +            apply_commands(Commands, Modules, UpdatedConfig, ModuleSetFile), + +            %% Once we're all done processing, reset the code path to whatever +            %% the parent initialized it to +            restore_code_path(CurrentCodePath), +            ok +    end.  %%  %% Given a list of module sets from rebar.app and a directory, find diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl index 5ba0af3..3a8571c 100644 --- a/src/rebar_deps.erl +++ b/src/rebar_deps.erl @@ -29,39 +29,44 @@  -include("rebar.hrl").  -export([preprocess/2, -         distclean/2]). +         'get-deps'/2, +         'delete-deps'/2]).  %% ===================================================================  %% Public API  %% ===================================================================  preprocess(Config, _) -> -    %% Get the directory where we will place downloaded deps. Take steps -    %% to ensure that if we're doing a multi-level build, all the deps will -    %% wind up in a single directory; avoiding potential pain from having -    %% multiple copies of the same dep scattered throughout the source tree. -    %% -    %% The first definition of deps_dir is the one we use; we also fully -    %% qualify it to ensure everyone sees it properly. -    case rebar_config:get_all(Config, deps_dir) of -        [] -> -            DepsDir = filename:absname("deps"); -        AllDirs -> -            DepsDir = filename:absname(hd(lists:reverse(AllDirs))) -    end, - -    ?DEBUG("~s: Using deps dir: ~s\n", [rebar_utils:get_cwd(), DepsDir]), +    DepsDir = get_deps_dir(Config),      Config2 = rebar_config:set(Config, deps_dir, DepsDir), -    %% Process the list of local deps from the configuration -    case catch(process_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of -        Dirs when is_list(Dirs) -> -            {ok, Config2, Dirs}; +    %% Check for available deps, using the list of deps specified in our config. +    %% We use the directory from the list of tuples for deps with source information to +    %% update our list of directories to process. +    case catch(check_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of +        Deps when is_list(Deps) -> +            %% Walk all the deps and make sure they are available on the code path, +            %% if the application we're interested in actually exists there. +            ok = update_deps_code_path(Deps), +            {ok, Config2, [Dir || {Dir, _, _, _} <- Deps]}; +        {'EXIT', Reason} -> +            ?ABORT("Error while processing dependencies: ~p\n", [Reason]) +    end. + +'get-deps'(Config, _) -> +    DepsDir = get_deps_dir(Config), + +    %% Get a list of deps that need to be downloaded +    case catch(check_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of +        Deps when is_list(Deps) -> +            %% Now for each dependency tuple, pull it +            [use_source(Dir, App, VsnRegex, Source) || {Dir, App, VsnRegex, Source} <- Deps], +            ok;          {'EXIT', Reason} ->              ?ABORT("Error while processing dependencies: ~p\n", [Reason])      end. -distclean(Config, _) -> +'delete-deps'(Config, _) ->      %% Delete all the deps which we downloaded (or would have caused to be      %% downloaded).      DepsDir = rebar_config:get(Config, deps_dir, rebar_utils:get_cwd()), @@ -72,27 +77,54 @@ distclean(Config, _) ->  %% Internal functions  %% =================================================================== -process_deps([], Acc, _Dir) -> +get_deps_dir(Config) -> +    %% Get the directory where we will place downloaded deps. Take steps +    %% to ensure that if we're doing a multi-level build, all the deps will +    %% wind up in a single directory; avoiding potential pain from having +    %% multiple copies of the same dep scattered throughout the source tree. +    %% +    %% The first definition of deps_dir is the one we use; we also fully +    %% qualify it to ensure everyone sees it properly. +    case rebar_config:get_all(Config, deps_dir) of +        [] -> +            DepsDir = filename:absname("deps"); +        AllDirs -> +            DepsDir = filename:absname(hd(lists:reverse(AllDirs))) +    end, +    ?DEBUG("~s: Using deps dir: ~s\n", [rebar_utils:get_cwd(), DepsDir]), +    DepsDir. + +update_deps_code_path([]) -> +    ok; +update_deps_code_path([{AppDir, App, VsnRegex, _Source} | Rest]) -> +    case is_app_available(App, VsnRegex, AppDir) of +        true -> +            code:add_patha(filename:join(AppDir, ebin)); +        false -> +            ok +    end, +    update_deps_code_path(Rest). + +check_deps([], Acc, _Dir) ->      Acc; -process_deps([App | Rest], Acc, Dir) when is_atom(App) -> +check_deps([App | Rest], Acc, Dir) when is_atom(App) ->      require_app(App, ".*"), -    process_deps(Rest, Acc, Dir); -process_deps([{App, VsnRegex} | Rest], Acc, Dir) when is_atom(App) -> +    check_deps(Rest, Acc, Dir); +check_deps([{App, VsnRegex} | Rest], Acc, Dir) when is_atom(App) ->      require_app(App, VsnRegex), -    process_deps(Rest, Acc, Dir); -process_deps([{App, VsnRegex, Source} | Rest], Acc, Dir) -> +    check_deps(Rest, Acc, Dir); +check_deps([{App, VsnRegex, Source} | Rest], Acc, Dir) ->      case is_app_available(App, VsnRegex) of          true -> -            process_deps(Rest, Acc, Dir); +            check_deps(Rest, Acc, Dir);          false -> -            %% App may not be on the code path, or the version that is doesn't -            %% match our regex. Either way, we want to pull our revision into -            %% the deps dir and try to use that +            %% App is not on our code path OR the version that is available +            %% doesn't match our regex. Return a tuple containing the target dir +            %% and source information.              AppDir = filename:join(Dir, App), -            use_source(AppDir, App, VsnRegex, Source), -            process_deps(Rest, [AppDir | Acc], Dir) +            check_deps(Rest, [{AppDir, App, VsnRegex, Source} | Acc], Dir)      end; -process_deps([Other | _Rest], _Acc, _Dir) -> +check_deps([Other | _Rest], _Acc, _Dir) ->      ?ABORT("Invalid dependency specification ~p in ~s\n",             [Other, rebar_utils:get_cwd()]). @@ -170,6 +202,7 @@ is_app_available(App, VsnRegex, Path) ->      end.  use_source(AppDir, App, VsnRegex, Source) -> +    ?CONSOLE("Pulling ~p from ~p\n", [App, Source]),      use_source(AppDir, App, VsnRegex, Source, 3).  use_source(_AppDir, _App, _VsnRegex, Source, 0) -> diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 473fa20..0320380 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -226,7 +226,6 @@ compile_priority(File) ->          {error, _} ->              10; % couldn't parse the file, default priority          {ok, Trees} -> -            ?DEBUG("Computing priority of ~p\n", [File]),              F2 = fun({tree,arity_qualifier,_,                          {arity_qualifier,{tree,atom,_,behaviour_info},                              {tree,integer,_,1}}}, _) -> | 
