diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar3.erl | 8 | ||||
-rw-r--r-- | src/rebar_app_info.erl | 11 | ||||
-rw-r--r-- | src/rebar_core.erl | 20 | ||||
-rw-r--r-- | src/rebar_dir.erl | 35 | ||||
-rw-r--r-- | src/rebar_prv_common_test.erl | 7 | ||||
-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 |
10 files changed, 138 insertions, 171 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl index f6a2b78..368ba68 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, @@ -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, 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..b82bfc0 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -41,7 +41,7 @@ process_command(State, Command) -> {error, io_lib:format("Command ~p not found", [Command])}; CommandProvider -> Profile = providers:profile(CommandProvider), - State1 = rebar_state:current_profile(State, Profile), + State1 = rebar_state:apply_profiles(State, [Profile]), Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(), case Command of do -> @@ -49,8 +49,8 @@ process_command(State, Command) -> _ -> 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 +60,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 +75,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_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_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)}. |