diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar.app.src | 3 | ||||
-rw-r--r-- | src/rebar3.erl | 19 | ||||
-rw-r--r-- | src/rebar_app_info.erl | 11 | ||||
-rw-r--r-- | src/rebar_core.erl | 30 | ||||
-rw-r--r-- | src/rebar_dir.erl | 35 | ||||
-rw-r--r-- | src/rebar_prv_as.erl | 52 | ||||
-rw-r--r-- | src/rebar_prv_common_test.erl | 7 | ||||
-rw-r--r-- | src/rebar_prv_do.erl | 12 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 108 | ||||
-rw-r--r-- | src/rebar_prv_lock.erl | 33 | ||||
-rw-r--r-- | src/rebar_prv_release.erl | 7 | ||||
-rw-r--r-- | src/rebar_prv_tar.erl | 7 | ||||
-rw-r--r-- | src/rebar_state.erl | 73 |
13 files changed, 207 insertions, 190 deletions
diff --git a/src/rebar.app.src b/src/rebar.app.src index 5ef2c2f..5f18321 100644 --- a/src/rebar.app.src +++ b/src/rebar.app.src @@ -22,7 +22,8 @@ {log_level, warn}, %% any_dir processing modules - {providers, [rebar_prv_clean, + {providers, [rebar_prv_as, + rebar_prv_clean, rebar_prv_deps, rebar_prv_dialyzer, rebar_prv_do, diff --git a/src/rebar3.erl b/src/rebar3.erl index f6a2b78..b325dc8 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -106,11 +106,11 @@ run_aux(State, GlobalPluginProviders, RawArgs) -> application:start(ssl), inets:start(), - State2 = case os:getenv("REBAR_DEFAULT_PROFILE") of + State2 = case os:getenv("REBAR_PROFILE") of false -> - rebar_state:current_profile(State, default); + State; Profile -> - State1 = rebar_state:current_profile(State, list_to_atom(Profile)), + State1 = rebar_state:apply_profiles(State, [list_to_atom(Profile)]), rebar_state:default(State1, rebar_state:opts(State1)) end, @@ -127,7 +127,7 @@ run_aux(State, GlobalPluginProviders, RawArgs) -> State5 = rebar_state:create_logic_providers(AllProviders, State4), {Task, Args} = parse_args(RawArgs), - rebar_core:process_command(rebar_state:command_args(State5, Args), list_to_atom(Task)). + rebar_core:process_command(rebar_state:command_args(State5, Args), Task). init_config() -> %% Initialize logging system @@ -143,7 +143,7 @@ init_config() -> Config1 = case rebar_config:consult_file(?LOCK_FILE) of [D] -> - [{locks, D} | Config]; + [{locks, D}, {{deps, default}, D} | Config]; _ -> Config end, @@ -177,10 +177,6 @@ init_config() -> %% Initialize vsn cache {PluginProviders, rebar_state:set(State1, vsn_cache, dict:new())}. -%% -%% Parse command line arguments using getopt and also filtering out any -%% key=value pairs. What's left is the list of commands to run -%% parse_args([]) -> parse_args(["help"]); parse_args([H | Rest]) when H =:= "-h" @@ -189,8 +185,8 @@ parse_args([H | Rest]) when H =:= "-h" parse_args([H | Rest]) when H =:= "-v" ; H =:= "--version" -> parse_args(["version" | Rest]); -parse_args([RawTask | RawRest]) -> - {RawTask, RawRest}. +parse_args([Task | RawRest]) -> + {list_to_atom(Task), RawRest}. set_options(State, {Options, NonOptArgs}) -> GlobalDefines = proplists:get_all_values(defines, Options), @@ -251,7 +247,6 @@ global_option_spec_list() -> [ %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg} {help, $h, "help", undefined, "Print this help."}, - %{verbose, $v, "verbose", integer, "Verbosity level (-v, -vv)."}, {version, $V, "version", undefined, "Show version information."}, %{config, $C, "config", string, "Rebar config file to use."}, {task, undefined, undefined, string, "Task to run."} diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index f790cd3..3854ea7 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -20,6 +20,8 @@ ebin_dir/1, applications/1, applications/2, + profile/1, + profile/2, deps/1, deps/2, dep_level/1, @@ -41,6 +43,7 @@ app_details=[] :: list(), applications=[] :: list(), deps=[] :: list(), + profile=default :: atom(), dep_level=0 :: integer(), dir :: file:name(), source :: string() | tuple() | undefined, @@ -166,6 +169,14 @@ applications(#app_info_t{applications=Applications}) -> applications(AppInfo=#app_info_t{}, Applications) -> AppInfo#app_info_t{applications=Applications}. +-spec profile(t()) -> list(). +profile(#app_info_t{profile=Profile}) -> + Profile. + +-spec profile(t(), list()) -> t(). +profile(AppInfo=#app_info_t{}, Profile) -> + AppInfo#app_info_t{profile=Profile}. + -spec deps(t()) -> list(). deps(#app_info_t{deps=Deps}) -> Deps. diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 21d008a..fa0e459 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -40,17 +40,19 @@ process_command(State, Command) -> not_found -> {error, io_lib:format("Command ~p not found", [Command])}; CommandProvider -> - Profile = providers:profile(CommandProvider), - State1 = rebar_state:current_profile(State, Profile), - Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(), case Command of - do -> - do(TargetProviders, State1); + Command when Command =:= do + ; Command =:= as -> + do(TargetProviders, State); _ -> + Profile = providers:profile(CommandProvider), + State1 = rebar_state:apply_profiles(State, [Profile]), + Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(), + case getopt:parse(Opts, rebar_state:command_args(State1)) of {ok, Args} -> - State3 = rebar_state:command_parsed_args(State1, Args), - do(TargetProviders, State3); + State2 = rebar_state:command_parsed_args(State1, Args), + do(TargetProviders, State2); {error, {invalid_option, Option}} -> {error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])} end @@ -60,13 +62,12 @@ process_command(State, Command) -> -spec do([{atom(), atom()}], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do([], State) -> {ok, State}; -do([{ProviderName, Profile} | Rest], State) -> - State1 = rebar_state:current_profile(State, Profile), +do([{ProviderName, _} | Rest], State) -> Provider = providers:get_provider(ProviderName - ,rebar_state:providers(State1)), - case providers:do(Provider, State1) of - {ok, State2} -> - do(Rest, State2); + ,rebar_state:providers(State)), + case providers:do(Provider, State) of + {ok, State1} -> + do(Rest, State1); {error, Error} -> {error, Error} end. @@ -76,8 +77,7 @@ update_code_path(State) -> LibDirs = rebar_dir:lib_dirs(State), DepsDir = rebar_dir:deps_dir(State), PluginsDir = rebar_dir:plugins_dir(State), - _UpdatedCodePaths = update_code_path_([DepsDir, PluginsDir | LibDirs]). - + _UpdatedCodePaths = update_code_path_(lists:usort([DepsDir, PluginsDir | LibDirs])). %% =================================================================== %% Internal functions diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index e692c65..58ce716 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -5,10 +5,6 @@ deps_dir/2, plugins_dir/1, lib_dirs/1, - profile_dir/1, - default_deps_dir/1, - default_profile_dir/1, - default_profile_deps/1, home_dir/0, global_config_dir/1, get_cwd/0, @@ -26,42 +22,25 @@ base_dir(State) -> -spec deps_dir(rebar_state:t()) -> file:filename_all(). deps_dir(State) -> - DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), - filename:join(profile_dir(State), DepsDir). + filename:join(base_dir(State), rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR)). -spec deps_dir(file:filename_all(), file:filename_all()) -> file:filename_all(). deps_dir(DepsDir, App) -> filename:join(DepsDir, App). --spec default_deps_dir(rebar_state:t()) -> file:filename_all(). -default_deps_dir(State) -> - DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), - filename:join([base_dir(State), "default", DepsDir]). - -spec plugins_dir(rebar_state:t()) -> file:filename_all(). plugins_dir(State) -> - filename:join(base_dir(State), rebar_state:get(State, plugins_dir, ?DEFAULT_PLUGINS_DIR)). + case lists:member(global, rebar_state:current_profiles(State)) of + true -> + filename:join([base_dir(State), global_config_dir(State), rebar_state:get(State, plugins_dir, ?DEFAULT_PLUGINS_DIR)]); + false -> + filename:join(base_dir(State), rebar_state:get(State, plugins_dir, ?DEFAULT_PLUGINS_DIR)) + end. -spec lib_dirs(rebar_state:t()) -> file:filename_all(). lib_dirs(State) -> rebar_state:get(State, project_app_dirs, ?DEFAULT_PROJECT_APP_DIRS). --spec default_profile_dir(rebar_state:t()) -> file:filename_all(). -default_profile_dir(State) -> - filename:join(base_dir(State), "default"). - -profile_dir(State) -> - case rebar_state:current_profile(State) of - global -> - global_config_dir(State); - Profile -> - filename:join(base_dir(State), atom_to_list(Profile)) - end. - --spec default_profile_deps(rebar_state:t()) -> file:filename_all(). -default_profile_deps(State) -> - filename:join(default_profile_dir(State), ?DEFAULT_DEPS_DIR). - home_dir() -> {ok, [[Home]]} = init:get_argument(home), Home. diff --git a/src/rebar_prv_as.erl b/src/rebar_prv_as.erl new file mode 100644 index 0000000..1ad22ed --- /dev/null +++ b/src/rebar_prv_as.erl @@ -0,0 +1,52 @@ +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et + +-module(rebar_prv_as). + +-behaviour(provider). + +-export([init/1, + do/1, + format_error/1]). + +-include("rebar.hrl"). + +-define(PROVIDER, as). +-define(DEPS, []). + +%% =================================================================== +%% Public API +%% =================================================================== + +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {bare, false}, + {deps, ?DEPS}, + {example, "rebar3 as <profile1>,<profile2>,... <task1>, <task2>, ..."}, + {short_desc, "Higher order provider for running multiple tasks in a sequence as a certain profiles."}, + {desc, ""}, + {opts, [{profile, undefined, undefined, string, "Profiles to run as."}]}])), + {ok, State1}. + +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. +do(State) -> + [Profile | Rest] = rebar_state:command_args(State), + Tasks = args_to_tasks(Rest), + Profiles = [list_to_atom(X) || X <- string:tokens(Profile, ",")], + State1 = rebar_state:apply_profiles(State, Profiles), + lists:foldl(fun(TaskArgs, {ok, StateAcc}) -> + [TaskStr | Args] = string:tokens(TaskArgs, " "), + Task = list_to_atom(TaskStr), + StateAcc1 = rebar_state:set(StateAcc, task, Task), + StateAcc2 = rebar_state:command_args(StateAcc1, Args), + rebar_core:process_command(StateAcc2, Task) + end, {ok, State1}, Tasks). + +-spec format_error(any()) -> iolist(). +format_error(Reason) -> + io_lib:format("~p", [Reason]). + +args_to_tasks(Args) -> + [string:strip(T) || T <- string:tokens(string:join(Args, " "), ",")]. diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 20d554e..4576d05 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -12,7 +12,7 @@ -include("rebar.hrl"). -define(PROVIDER, ct). --define(DEPS, [{install_deps, default}, compile]). +-define(DEPS, [compile]). %% =================================================================== %% Public API @@ -37,7 +37,6 @@ do(State) -> {Opts, _} = rebar_state:command_parsed_args(State), Opts1 = transform_opts(Opts), ok = create_dirs(Opts1), - expand_test_deps(filename:join(rebar_dir:profile_dir(State), ?DEFAULT_DEPS_DIR)), case handle_results(ct:run_test(Opts1)) of {error, Reason} -> {error, {?MODULE, Reason}}; @@ -51,10 +50,6 @@ format_error({failures_running_tests, FailedCount}) -> format_error({error_running_tests, Reason}) -> io_lib:format("Error running tests: ~p", [Reason]). -expand_test_deps(Dir) -> - Apps = filelib:wildcard(filename:join([Dir, "*", "ebin"])), - ok = code:add_pathsa(Apps). - ct_opts(State) -> DefaultTestDir = filename:join([rebar_state:dir(State), "test"]), DefaultLogsDir = filename:join([rebar_state:dir(State), "logs"]), diff --git a/src/rebar_prv_do.erl b/src/rebar_prv_do.erl index 10888eb..c2bbe2b 100644 --- a/src/rebar_prv_do.erl +++ b/src/rebar_prv_do.erl @@ -34,12 +34,12 @@ init(State) -> do(State) -> Tasks = args_to_tasks(rebar_state:command_args(State)), lists:foldl(fun(TaskArgs, {ok, StateAcc}) -> - [TaskStr | Args] = string:tokens(TaskArgs, " "), - Task = list_to_atom(TaskStr), - StateAcc1 = rebar_state:set(StateAcc, task, Task), - StateAcc2 = rebar_state:command_args(StateAcc1, Args), - rebar_core:process_command(StateAcc2, Task) - end, {ok, State}, Tasks). + [TaskStr | Args] = string:tokens(TaskArgs, " "), + Task = list_to_atom(TaskStr), + StateAcc1 = rebar_state:set(StateAcc, task, Task), + StateAcc2 = rebar_state:command_args(StateAcc1, Args), + rebar_core:process_command(StateAcc2, Task) + end, {ok, State}, Tasks). -spec format_error(any()) -> iolist(). format_error(Reason) -> diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 3728b70..0ebc1cd 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -35,15 +35,16 @@ -include("rebar.hrl"). -include_lib("providers/include/providers.hrl"). --export([handle_deps/2, - handle_deps/3]). +-export([handle_deps/3, + handle_deps/4]). -export_type([dep/0]). -define(PROVIDER, install_deps). -define(DEPS, [app_discovery]). --type src_dep() :: {atom(), string(), {atom(), string(), string()}}. +-type src_dep() :: {atom(), {atom(), string(), string()}} + | {atom(), string(), {atom(), string(), string()}}. -type pkg_dep() :: {atom(), binary()} | atom(). -type dep() :: src_dep() | pkg_dep(). @@ -66,19 +67,19 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - Profile = rebar_state:current_profile(State), - ?INFO("Verifying ~p dependencies...", [Profile]), - ProjectApps = rebar_state:project_apps(State), try - {ok, SrcApps, State1} = case {Profile, rebar_state:get(State, locks, [])} of - {default, []} -> - handle_deps(State, rebar_state:get(State, {deps, Profile}, [])); - {default, Locks} -> - handle_deps(State, Locks); - _ -> - %% If not the default profile, ignore locks file - handle_deps(State, rebar_state:get(State, {deps, Profile}, [])) - end, + ?INFO("Verifying dependencies...", []), + Profiles = rebar_state:current_profiles(State), + ProjectApps = rebar_state:project_apps(State), + + {SrcApps, State1} = + lists:foldl(fun(Profile, {SrcAppsAcc, StateAcc}) -> + {ok, NewSrcApps, NewState} = + handle_deps(Profile + ,StateAcc + ,rebar_state:get(StateAcc, {deps, Profile}, [])), + {NewSrcApps++SrcAppsAcc, NewState} + end, {[], State}, lists:reverse(Profiles)), Source = ProjectApps ++ SrcApps, case find_cycles(Source ++ rebar_state:all_deps(State1)) of @@ -119,24 +120,25 @@ format_error({cycles, Cycles}) -> format_error(Reason) -> io_lib:format("~p", [Reason]). --spec handle_deps(rebar_state:t(), list()) -> +-spec handle_deps(atom(), rebar_state:t(), list()) -> {ok, [rebar_app_info:t()], rebar_state:t()} | {error, string()}. -handle_deps(State, Deps) -> - handle_deps(State, Deps, false). +handle_deps(Profile, State, Deps) -> + handle_deps(Profile, State, Deps, false). --spec handle_deps(rebar_state:t(), list(), boolean() | {true, binary(), integer()}) +-spec handle_deps(atom(), rebar_state:t(), list(), boolean() | {true, binary(), integer()}) -> {ok, [rebar_app_info:t()], rebar_state:t()} | {error, string()}. -handle_deps(State, [], _) -> +handle_deps(_Profile, State, [], _) -> {ok, [], State}; -handle_deps(State, Deps, Update) -> +handle_deps(Profile, State, Deps, Update) -> %% Read in package index and dep graph {Packages, Graph} = rebar_packages:get_packages(State), %% Split source deps from pkg deps, needed to keep backwards compatibility DepsDir = rebar_dir:deps_dir(State), - {SrcDeps, PkgDeps} = parse_deps(State, DepsDir, Deps), + {SrcDeps, PkgDeps} = parse_deps(DepsDir, Deps), + %% Fetch transitive src deps {State1, SrcApps, PkgDeps1, Seen} = - update_src_deps(0, SrcDeps, PkgDeps, [], State, Update, sets:new()), + update_src_deps(Profile, 0, SrcDeps, PkgDeps, [], State, Update, sets:new()), {Solved, State2} = case PkgDeps1 of [] -> %% No pkg deps @@ -152,7 +154,7 @@ handle_deps(State, Deps, Update) -> [warn_skip_pkg(Pkg) || Pkg <- Discarded], Solution end, - update_pkg_deps(S, Packages, Update, Seen, State1) + update_pkg_deps(Profile, S, Packages, Update, Seen, State1) end, AllDeps = lists:ukeymerge(2 ,lists:ukeysort(2, SrcApps) @@ -166,7 +168,7 @@ handle_deps(State, Deps, Update) -> %% Internal functions %% =================================================================== -update_pkg_deps(Pkgs, Packages, Update, Seen, State) -> +update_pkg_deps(Profile, Pkgs, Packages, Update, Seen, State) -> %% Create app_info record for each pkg dep DepsDir = rebar_dir:deps_dir(State), {Solved, _, State1} @@ -174,8 +176,8 @@ update_pkg_deps(Pkgs, Packages, Update, Seen, State) -> AppInfo = package_to_app(DepsDir ,Packages ,Pkg), - {SeenAcc1, StateAcc1} = maybe_lock(AppInfo, SeenAcc, StateAcc), - case maybe_fetch(StateAcc1, AppInfo, Update, SeenAcc1) of + {SeenAcc1, StateAcc1} = maybe_lock(Profile, AppInfo, SeenAcc, StateAcc), + case maybe_fetch(AppInfo, Update, SeenAcc1) of true -> {[AppInfo | Acc], SeenAcc1, StateAcc1}; false -> @@ -184,9 +186,9 @@ update_pkg_deps(Pkgs, Packages, Update, Seen, State) -> end, {[], Seen, State}, Pkgs), {Solved, State1}. -maybe_lock(AppInfo, Seen, State) -> +maybe_lock(Profile, AppInfo, Seen, State) -> Name = rebar_app_info:name(AppInfo), - case rebar_state:current_profile(State) of + case Profile of default -> case sets:is_element(Name, Seen) of false -> @@ -213,8 +215,8 @@ package_to_app(DepsDir, Packages, {Name, Vsn}) -> rebar_app_info:source(AppInfo2, {pkg, Name, Vsn, Link}) end. --spec update_src_deps(non_neg_integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary())) -> {rebar_state:t(), list(), list(), sets:set(binary())}. -update_src_deps(Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen) -> +-spec update_src_deps(atom(), non_neg_integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary())) -> {rebar_state:t(), list(), list(), sets:set(binary())}. +update_src_deps(Profile, Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen) -> case lists:foldl(fun(AppInfo, {SrcDepsAcc, PkgDepsAcc, SrcAppsAcc, StateAcc, SeenAcc}) -> %% If not seen, add to list of locks to write out case sets:is_element(rebar_app_info:name(AppInfo), SeenAcc) of @@ -222,7 +224,7 @@ update_src_deps(Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen) -> warn_skip_deps(AppInfo), {SrcDepsAcc, PkgDepsAcc, SrcAppsAcc, StateAcc, SeenAcc}; false -> - {SeenAcc1, StateAcc1} = maybe_lock(AppInfo, SeenAcc, StateAcc), + {SeenAcc1, StateAcc1} = maybe_lock(Profile, AppInfo, SeenAcc, StateAcc), {SrcDepsAcc1, PkgDepsAcc1, SrcAppsAcc1, StateAcc2} = case Update of {true, UpdateName, UpdateLevel} -> @@ -235,7 +237,7 @@ update_src_deps(Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen) -> ,Level ,StateAcc1); _ -> - maybe_fetch(StateAcc, AppInfo, false, SeenAcc1), + maybe_fetch(AppInfo, false, SeenAcc1), handle_dep(AppInfo ,SrcDepsAcc ,PkgDepsAcc @@ -251,7 +253,7 @@ update_src_deps(Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen) -> {[], NewPkgDeps, NewSrcApps, State1, Seen1} -> {State1, NewSrcApps, NewPkgDeps, Seen1}; {NewSrcDeps, NewPkgDeps, NewSrcApps, State1, Seen1} -> - update_src_deps(Level+1, NewSrcDeps, NewPkgDeps, NewSrcApps, State1, Update, Seen1) + update_src_deps(Profile, Level+1, NewSrcDeps, NewPkgDeps, NewSrcApps, State1, Update, Seen1) end. handle_update(AppInfo, UpdateName, UpdateLevel, SrcDeps, PkgDeps, SrcApps, Level, State) -> @@ -261,7 +263,7 @@ handle_update(AppInfo, UpdateName, UpdateLevel, SrcDeps, PkgDeps, SrcApps, Level case UpdateLevel < DepLevel orelse Name =:= UpdateName of true -> - case maybe_fetch(State, AppInfo, true, []) of + case maybe_fetch(AppInfo, true, []) of true -> handle_dep(AppInfo ,SrcDeps @@ -290,27 +292,20 @@ handle_dep(AppInfo, SrcDeps, PkgDeps, SrcApps, Level, State) -> -spec handle_dep(rebar_state:t(), file:filename_all(), rebar_app_info:t()) -> {rebar_app_info:t(), [rebar_app_info:t()], [pkg_dep()]}. handle_dep(State, DepsDir, AppInfo) -> - Profile = rebar_state:current_profile(State), + Profiles = rebar_state:current_profiles(State), C = rebar_config:consult(rebar_app_info:dir(AppInfo)), S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(AppInfo)), - S1 = rebar_state:apply_profile(S, Profile), - Deps = case Profile of - default -> - rebar_state:get(S1, {deps, Profile}, []); - _ -> - rebar_state:get(S1, {deps, default}, []) ++ - rebar_state:get(S1, {deps, Profile}, []) - end, + S1 = rebar_state:apply_profiles(S, Profiles), + Deps = rebar_state:get(S1, deps, []), AppInfo1 = rebar_app_info:deps(AppInfo, rebar_state:deps_names(Deps)), - {SrcDeps, PkgDeps} = parse_deps(State, DepsDir, Deps), + {SrcDeps, PkgDeps} = parse_deps(DepsDir, Deps), {AppInfo1, SrcDeps, PkgDeps}. --spec maybe_fetch(rebar_state:t(), rebar_app_info:t(), boolean() | {true, binary(), integer()}, +-spec maybe_fetch(rebar_app_info:t(), boolean() | {true, binary(), integer()}, sets:set(binary())) -> boolean(). -maybe_fetch(State, AppInfo, Update, Seen) -> +maybe_fetch(AppInfo, Update, Seen) -> AppDir = ec_cnv:to_list(rebar_app_info:dir(AppInfo)), - DefaultProfileDeps = rebar_dir:default_profile_deps(State), - Apps = rebar_app_discover:find_apps(["_checkouts", DefaultProfileDeps], all), + Apps = rebar_app_discover:find_apps(["_checkouts"], all), case rebar_app_utils:find(rebar_app_info:name(AppInfo), Apps) of {ok, _} -> %% Don't fetch dep if it exists in the _checkouts dir @@ -360,28 +355,27 @@ maybe_fetch(State, AppInfo, Update, Seen) -> end end. --spec parse_deps(rebar_state:t(), binary(), list()) -> {[rebar_app_info:t()], [pkg_dep()]}. -parse_deps(State, DepsDir, Deps) -> +-spec parse_deps(binary(), list()) -> {[rebar_app_info:t()], [pkg_dep()]}. +parse_deps(DepsDir, Deps) -> lists:foldl(fun({Name, Vsn}, {SrcDepsAcc, PkgDepsAcc}) -> {SrcDepsAcc, [parse_goal(ec_cnv:to_binary(Name) ,ec_cnv:to_binary(Vsn)) | PkgDepsAcc]}; (Name, {SrcDepsAcc, PkgDepsAcc}) when is_atom(Name) -> {SrcDepsAcc, [ec_cnv:to_binary(Name) | PkgDepsAcc]}; ({Name, Source}, {SrcDepsAcc, PkgDepsAcc}) when is_tuple (Source) -> - Dep = new_dep(State, DepsDir, Name, [], Source), + Dep = new_dep(DepsDir, Name, [], Source), {[Dep | SrcDepsAcc], PkgDepsAcc}; ({Name, _Vsn, Source}, {SrcDepsAcc, PkgDepsAcc}) when is_tuple (Source) -> - Dep = new_dep(State, DepsDir, Name, [], Source), + Dep = new_dep(DepsDir, Name, [], Source), {[Dep | SrcDepsAcc], PkgDepsAcc}; ({Name, Source, Level}, {SrcDepsAcc, PkgDepsAcc}) when is_tuple (Source) , is_integer(Level) -> - Dep = new_dep(State, DepsDir, Name, [], Source), + Dep = new_dep(DepsDir, Name, [], Source), {[Dep | SrcDepsAcc], PkgDepsAcc} end, {[], []}, Deps). -new_dep(State, DepsDir, Name, Vsn, Source) -> - Dirs = [ec_cnv:to_list(filename:join(rebar_dir:default_profile_deps(State), Name)), - ec_cnv:to_list(filename:join(DepsDir, Name))], +new_dep(DepsDir, Name, Vsn, Source) -> + Dirs = [ec_cnv:to_list(filename:join(DepsDir, Name))], {ok, Dep} = case ec_lists:search(fun(Dir) -> rebar_app_info:discover(Dir) end, Dirs) of diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl index 9131777..2f26a7f 100644 --- a/src/rebar_prv_lock.erl +++ b/src/rebar_prv_lock.erl @@ -29,25 +29,20 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - case rebar_state:get(State, locks, []) of - [] -> - AllDeps = rebar_state:lock(State), - Locks = lists:map(fun(Dep) -> - Dir = rebar_app_info:dir(Dep), - Source = rebar_app_info:source(Dep), - - %% If source is tuple it is a source dep - %% e.g. {git, "git://github.com/ninenines/cowboy.git", "master"} - {rebar_app_info:name(Dep) - ,rebar_fetch:lock_source(Dir, Source) - ,rebar_app_info:dep_level(Dep)} - end, AllDeps), - Dir = rebar_state:dir(State), - file:write_file(filename:join(Dir, "rebar.lock"), io_lib:format("~p.~n", [Locks])), - {ok, rebar_state:set(State, locks, Locks)}; - _Locks -> - {ok, State} - end. + AllDeps = rebar_state:lock(State), + Locks = lists:map(fun(Dep) -> + Dir = rebar_app_info:dir(Dep), + Source = rebar_app_info:source(Dep), + + %% If source is tuple it is a source dep + %% e.g. {git, "git://github.com/ninenines/cowboy.git", "master"} + {rebar_app_info:name(Dep) + ,rebar_fetch:lock_source(Dir, Source) + ,rebar_app_info:dep_level(Dep)} + end, AllDeps), + Dir = rebar_state:dir(State), + file:write_file(filename:join(Dir, "rebar.lock"), io_lib:format("~p.~n", [Locks])), + {ok, State}. -spec format_error(any()) -> iolist(). format_error(Reason) -> diff --git a/src/rebar_prv_release.erl b/src/rebar_prv_release.erl index d382ab5..295d5b4 100644 --- a/src/rebar_prv_release.erl +++ b/src/rebar_prv_release.erl @@ -33,10 +33,9 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> Options = rebar_state:command_args(State), - DepsDir = rebar_dir:default_deps_dir(State), - ProfileDepsDir = rebar_dir:deps_dir(State), - LibDirs = lists:usort(rebar_utils:filtermap(fun ec_file:exists/1, [DepsDir, ProfileDepsDir])), - OutputDir = filename:join(rebar_dir:profile_dir(State), ?DEFAULT_RELEASE_DIR), + DepsDir = rebar_dir:deps_dir(State), + LibDirs = lists:usort(rebar_utils:filtermap(fun ec_file:exists/1, [DepsDir])), + OutputDir = filename:join(rebar_dir:base_dir(State), ?DEFAULT_RELEASE_DIR), AllOptions = string:join(["release" | Options], " "), try case rebar_state:get(State, relx, []) of diff --git a/src/rebar_prv_tar.erl b/src/rebar_prv_tar.erl index 0225e19..f9c261f 100644 --- a/src/rebar_prv_tar.erl +++ b/src/rebar_prv_tar.erl @@ -33,10 +33,9 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> Options = rebar_state:command_args(State), - DepsDir = rebar_dir:default_deps_dir(State), - ProfileDepsDir = rebar_dir:deps_dir(State), - LibDirs = lists:usort(rebar_utils:filtermap(fun ec_file:exists/1, [DepsDir, ProfileDepsDir])), - OutputDir = filename:join(rebar_dir:profile_dir(State), ?DEFAULT_RELEASE_DIR), + DepsDir = rebar_dir:deps_dir(State), + LibDirs = lists:usort(rebar_utils:filtermap(fun ec_file:exists/1, [DepsDir])), + OutputDir = filename:join(rebar_dir:base_dir(State), ?DEFAULT_RELEASE_DIR), AllOptions = string:join(["release", "tar" | Options], " "), case rebar_state:get(State, relx, []) of [] -> diff --git a/src/rebar_state.erl b/src/rebar_state.erl index b412c27..09becca 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -10,13 +10,12 @@ lock/1, lock/2, - current_profile/1, - current_profile/2, + current_profiles/1, command_args/1, command_args/2, command_parsed_args/1, command_parsed_args/2, - apply_profile/2, + apply_profiles/2, dir/1, dir/2, create_logic_providers/2, @@ -39,7 +38,7 @@ escript_path :: undefined | file:filename_all(), lock = [], - current_profile = default :: atom(), + current_profiles = [default] :: [atom()], command_args = [], command_parsed_args = [], @@ -60,7 +59,8 @@ new() -> -spec new(list()) -> t(). new(Config) when is_list(Config) -> - Opts = dict:from_list(Config), + Deps = proplists:get_value(deps, Config, []), + Opts = dict:from_list([{{deps, default}, Deps} | Config]), #state_t { dir = rebar_dir:get_cwd(), default = Opts, opts = Opts }. @@ -68,9 +68,10 @@ new(Config) when is_list(Config) -> -spec new(t() | atom(), list()) -> t(). new(Profile, Config) when is_atom(Profile) , is_list(Config) -> - Opts = dict:from_list(Config), + Deps = proplists:get_value(deps, Config, []), + Opts = dict:from_list([{{deps, default}, Deps} | Config]), #state_t { dir = rebar_dir:get_cwd(), - current_profile = Profile, + current_profiles = [Profile], default = Opts, opts = Opts }; new(ParentState=#state_t{}, Config) -> @@ -81,20 +82,19 @@ new(ParentState=#state_t{}, Config) -> -spec new(t(), list(), file:name()) -> t(). new(ParentState, Config, Dir) -> Opts = ParentState#state_t.opts, - LocalOpts = case rebar_config:consult_file(?LOCK_FILE) of + LocalOpts = case rebar_config:consult_file(filename:join(Dir, ?LOCK_FILE)) of [D] -> - dict:from_list([{locks, D} | Config]); + dict:from_list([{locks, D}, {{deps, default}, D} | Config]); _ -> - dict:from_list(Config) + D = proplists:get_value(deps, Config, []), + dict:from_list([{{deps, default}, D} | Config]) end, NewOpts = dict:merge(fun(_Key, Value1, _Value2) -> Value1 end, LocalOpts, Opts), - ProviderModules = [], - create_logic_providers(ProviderModules - ,ParentState#state_t{dir=Dir - ,opts=NewOpts - ,default=NewOpts}). + ParentState#state_t{dir=Dir + ,opts=NewOpts + ,default=NewOpts}. get(State, Key) -> {ok, Value} = dict:find(Key, State#state_t.opts), @@ -121,11 +121,8 @@ default(State, Opts) -> opts(#state_t{opts=Opts}) -> Opts. -current_profile(#state_t{current_profile=Profile}) -> - Profile. - -current_profile(State, Profile) -> - apply_profile(State#state_t{current_profile=Profile}, Profile). +current_profiles(#state_t{current_profiles=Profiles}) -> + Profiles. lock(#state_t{lock=Lock}) -> Lock. @@ -151,20 +148,22 @@ command_parsed_args(#state_t{command_parsed_args=CmdArgs}) -> command_parsed_args(State, CmdArgs) -> State#state_t{command_parsed_args=CmdArgs}. -%% Only apply profiles to the default profile -apply_profile(State=#state_t{default=Opts}, default) -> - Deps = rebar_state:get(State, deps, []), - Opts1 = dict:store({deps, default}, Deps, Opts), - State#state_t{opts=Opts1}; -apply_profile(State=#state_t{default=Opts}, Profile) -> +apply_profiles(State, Profile) when not is_list(Profile) -> + apply_profiles(State, [Profile]); +apply_profiles(State, [default]) -> + State; +apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Profiles) -> ConfigProfiles = rebar_state:get(State, profiles, []), - Deps = rebar_state:get(State, deps, []), - Opts1 = dict:store({deps, default}, Deps, Opts), - ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), - State#state_t{opts=merge_opts(Profile, ProfileOpts, Opts1)}. + NewOpts = lists:foldl(fun(default, OptsAcc) -> + OptsAcc; + (Profile, OptsAcc) -> + ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), + merge_opts(Profile, ProfileOpts, OptsAcc) + end, Opts, Profiles), + State#state_t{current_profiles=CurrentProfiles++Profiles, opts=NewOpts}. merge_opts(Profile, NewOpts, OldOpts) -> - Dict = dict:merge(fun(_Key, NewValue, OldValue) when is_list(NewValue) -> + Opts = dict:merge(fun(_Key, NewValue, OldValue) when is_list(NewValue) -> case io_lib:printable_list(NewValue) of true -> NewValue; @@ -176,15 +175,13 @@ merge_opts(Profile, NewOpts, OldOpts) -> (_Key, NewValue, _OldValue) -> NewValue end, NewOpts, OldOpts), - case dict:find(deps, NewOpts) of + {ok, Value} -> + dict:store({deps, Profile}, Value, Opts); error -> - dict:store({deps, Profile}, [], Dict); - {ok, Deps} -> - dict:store({deps, Profile}, Deps, Dict) + Opts end. - dir(#state_t{dir=Dir}) -> Dir. @@ -212,8 +209,8 @@ project_apps(State=#state_t{project_apps=Apps}, App) -> deps_to_build(#state_t{deps_to_build=Apps}) -> Apps. -deps_to_build(State=#state_t{}, NewApps) when is_list(NewApps) -> - State#state_t{deps_to_build=NewApps}; +deps_to_build(State=#state_t{deps_to_build=Apps}, NewApps) when is_list(NewApps) -> + State#state_t{deps_to_build=Apps++NewApps}; deps_to_build(State=#state_t{deps_to_build=Apps}, App) -> State#state_t{deps_to_build=lists:keystore(rebar_app_info:name(App), 2, Apps, App)}. |