diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-08-26 22:13:04 -0500 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-08-31 21:40:51 -0500 |
commit | 98752aab9390137d7cba0b70e0c1c08b9ca308d4 (patch) | |
tree | f815700a5f2bc25091127b6ef116f5c6a4493de2 /src | |
parent | c5825978a0d6e1ad6e870b61f032490bc427aa21 (diff) |
wip: move state into app_info
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_app_discover.erl | 3 | ||||
-rw-r--r-- | src/rebar_app_info.erl | 240 | ||||
-rw-r--r-- | src/rebar_app_utils.erl | 36 | ||||
-rw-r--r-- | src/rebar_dir.erl | 32 | ||||
-rw-r--r-- | src/rebar_erlc_compiler.erl | 97 | ||||
-rw-r--r-- | src/rebar_hooks.erl | 43 | ||||
-rw-r--r-- | src/rebar_otp_app.erl | 16 | ||||
-rw-r--r-- | src/rebar_plugins.erl | 21 | ||||
-rw-r--r-- | src/rebar_prv_clean.erl | 8 | ||||
-rw-r--r-- | src/rebar_prv_common_test.erl | 6 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 16 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 33 | ||||
-rw-r--r-- | src/rebar_utils.erl | 28 |
13 files changed, 420 insertions, 159 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 5a25a9e..bc66c1f 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -89,12 +89,13 @@ merge_deps(AppInfo, State) -> AppState2 = rebar_state:set(AppState1, artifacts, []), AppInfo1 = rebar_app_info:state(AppInfo, AppState2), + AppInfo2 = rebar_app_info:opts(AppInfo1, rebar_state:opts(AppState2)), State1 = lists:foldl(fun(Profile, StateAcc) -> handle_profile(Profile, Name, AppState1, StateAcc) end, State, lists:reverse(CurrentProfiles)), - {AppInfo1, State1}. + {AppInfo2, State1}. handle_profile(Profile, Name, AppState, State) -> TopParsedDeps = rebar_state:get(State, {parsed_deps, Profile}, {[], []}), diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index bb5104e..ef8f69d 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -5,6 +5,7 @@ new/3, new/4, new/5, + update_opts/3, discover/1, name/1, name/2, @@ -35,6 +36,13 @@ dir/2, out_dir/1, out_dir/2, + default/1, + default/2, + opts/1, + opts/2, + get/2, + get/3, + set/3, resource_type/1, resource_type/2, source/1, @@ -47,9 +55,20 @@ is_checkout/1, is_checkout/2, valid/1, - valid/2]). + valid/2, + + has_all_artifacts/1, + + apply_overrides/2, + add_to_profile/3, + apply_profiles/2, + deduplicate/1, + do_deduplicate/2, + merge_opts/3, + merge_opts/2]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -export_type([t/0]). @@ -64,6 +83,8 @@ applications=[] :: list(), deps=[] :: list(), profiles=[default] :: [atom()], + default=dict:new() :: rebar_dict(), + opts=dict:new() :: rebar_dict(), dep_level=0 :: integer(), dir :: file:name(), out_dir :: file:name(), @@ -125,6 +146,36 @@ new(Parent, AppName, Vsn, Dir, Deps) -> out_dir=ec_cnv:to_list(Dir), deps=Deps}}. +update_opts(AppInfo, Opts, Config) -> + LockDeps = case resource_type(AppInfo) of + pkg -> + Deps = deps(AppInfo), + [{{locks, default}, Deps}, {{deps, default}, Deps}]; + _ -> + deps_from_config(dir(AppInfo), Config) + end, + + Plugins = proplists:get_value(plugins, Config, []), + Terms = LockDeps++[{{plugins, default}, Plugins} | Config], + true = rebar_config:verify_config_format(Terms), + LocalOpts = dict:from_list(Terms), + + NewOpts = merge_opts(LocalOpts, Opts), + + AppInfo#app_info_t{opts=NewOpts + ,default=NewOpts}. + +deps_from_config(Dir, Config) -> + case rebar_config:consult_lock_file(filename:join(Dir, ?LOCK_FILE)) of + [D] -> + %% We want the top level deps only from the lock file. + %% This ensures deterministic overrides for configs. + Deps = [X || X <- D, element(3, X) =:= 0], + [{{locks, default}, D}, {{deps, default}, Deps}]; + _ -> + [{{deps, default}, proplists:get_value(deps, Config, [])}] + end. + %% @doc discover a complete version of the app info with all fields set. -spec discover(file:filename_all()) -> {ok, t()} | not_found. discover(Dir) -> @@ -151,6 +202,34 @@ config(#app_info_t{config=Config}) -> config(AppInfo=#app_info_t{}, Config) -> AppInfo#app_info_t{config=Config}. +opts(#app_info_t{opts=Opts}) -> + Opts. + +opts(AppInfo, Opts) -> + AppInfo#app_info_t{opts=Opts}. + +default(#app_info_t{default=Default}) -> + Default. + +default(AppInfo, Default) -> + AppInfo#app_info_t{default=Default}. + +get(AppInfo, Key) -> + {ok, Value} = dict:find(Key, AppInfo#app_info_t.opts), + Value. + +get(AppInfo, Key, Default) -> + case dict:find(Key, AppInfo#app_info_t.opts) of + {ok, Value} -> + Value; + error -> + Default + end. + +-spec set(t(), any(), any()) -> t(). +set(AppInfo=#app_info_t{opts=Opts}, Key, Value) -> + AppInfo#app_info_t{opts = dict:store(Key, Value, Opts)}. + -spec app_file_src(t()) -> file:filename_all() | undefined. app_file_src(#app_info_t{app_file_src=undefined, dir=Dir, name=Name}) -> AppFileSrc = filename:join([ec_cnv:to_list(Dir), "src", ec_cnv:to_list(Name)++".app.src"]), @@ -338,9 +417,9 @@ is_checkout(#app_info_t{is_checkout=IsCheckout}) -> IsCheckout. -spec valid(t()) -> boolean(). -valid(AppInfo=#app_info_t{valid=undefined, state=State}) -> +valid(AppInfo=#app_info_t{valid=undefined}) -> case rebar_app_utils:validate_application_info(AppInfo) =:= true - andalso rebar_state:has_all_artifacts(State) =:= true of + andalso has_all_artifacts(AppInfo) =:= true of true -> true; _ -> @@ -352,3 +431,158 @@ valid(#app_info_t{valid=Valid}) -> -spec valid(t(), boolean()) -> t(). valid(AppInfo=#app_info_t{}, Valid) -> AppInfo#app_info_t{valid=Valid}. + +-spec has_all_artifacts(#app_info_t{}) -> true | {false, file:filename()}. +has_all_artifacts(AppInfo) -> + Artifacts = rebar_app_info:get(AppInfo, artifacts, []), + Dir = dir(AppInfo), + all(Dir, Artifacts). + +all(_, []) -> + true; +all(Dir, [File|Artifacts]) -> + case filelib:is_regular(filename:join(Dir, File)) of + false -> + ?DEBUG("Missing artifact ~s", [filename:join(Dir, File)]), + {false, File}; + true -> + all(Dir, Artifacts) + end. + +%%%%% + +apply_overrides(AppInfo, Name) -> + Overrides = rebar_app_info:get(AppInfo, overrides, []), + %Name = binary_to_atom(AppName, utf8), + + %% Inefficient. We want the order we get here though. + AppInfo1 = lists:foldl(fun({override, O}, AppInfoAcc) -> + lists:foldl(fun({deps, Value}, AppInfoAcc1) -> + rebar_app_info:set(AppInfoAcc1, {deps,default}, Value); + ({Key, Value}, AppInfoAcc1) -> + rebar_app_info:set(AppInfoAcc1, Key, Value) + end, AppInfoAcc, O); + (_, AppInfoAcc) -> + AppInfoAcc + end, AppInfo, Overrides), + + AppInfo2 = lists:foldl(fun({override, N, O}, AppInfoAcc) when N =:= Name -> + lists:foldl(fun({deps, Value}, AppInfoAcc1) -> + rebar_app_info:set(AppInfoAcc1, {deps,default}, Value); + ({Key, Value}, AppInfoAcc1) -> + rebar_app_info:set(AppInfoAcc1, Key, Value) + end, AppInfoAcc, O); + (_, AppInfoAcc) -> + AppInfoAcc + end, AppInfo1, Overrides), + + AppInfo3 = lists:foldl(fun({add, N, O}, AppInfoAcc) when N =:= Name -> + lists:foldl(fun({deps, Value}, AppInfoAcc1) -> + OldValue = rebar_app_info:get(AppInfoAcc1, {deps,default}, []), + rebar_app_info:set(AppInfoAcc1, {deps,default}, Value++OldValue); + ({Key, Value}, AppInfoAcc1) -> + OldValue = rebar_app_info:get(AppInfoAcc1, Key, []), + rebar_app_info:set(AppInfoAcc1, Key, Value++OldValue) + end, AppInfoAcc, O); + (_, AppInfoAcc) -> + AppInfoAcc + end, AppInfo2, Overrides), + + Opts = opts(AppInfo3), + AppInfo3#app_info_t{default=Opts}. + +add_to_profile(AppInfo, Profile, KVs) when is_atom(Profile), is_list(KVs) -> + Profiles = rebar_app_info:get(AppInfo, profiles, []), + ProfileOpts = dict:from_list(proplists:get_value(Profile, Profiles, [])), + NewOpts = merge_opts(Profile, dict:from_list(KVs), ProfileOpts), + NewProfiles = [{Profile, dict:to_list(NewOpts)}|lists:keydelete(Profile, 1, Profiles)], + rebar_app_info:set(AppInfo, profiles, NewProfiles). + +apply_profiles(AppInfo, Profile) when not is_list(Profile) -> + apply_profiles(AppInfo, [Profile]); +apply_profiles(AppInfo, [default]) -> + AppInfo; +apply_profiles(AppInfo=#app_info_t{default = Defaults, profiles=CurrentProfiles}, Profiles) -> + AppliedProfiles = case Profiles of + %% Head of list global profile is special, only for use by rebar3 + %% It does not clash if a user does `rebar3 as global...` but when + %% it is the head we must make sure not to prepend `default` + [global | _] -> + Profiles; + _ -> + deduplicate(CurrentProfiles ++ Profiles) + end, + + ConfigProfiles = rebar_app_info:get(AppInfo, profiles, []), + + NewOpts = + lists:foldl(fun(default, OptsAcc) -> + OptsAcc; + (Profile, OptsAcc) -> + case proplists:get_value(Profile, ConfigProfiles, []) of + OptsList when is_list(OptsList) -> + ProfileOpts = dict:from_list(OptsList), + merge_opts(Profile, ProfileOpts, OptsAcc); + Other -> + throw(?PRV_ERROR({profile_not_list, Profile, Other})) + end + end, Defaults, AppliedProfiles), + AppInfo#app_info_t{profiles = AppliedProfiles, opts=NewOpts}. + +deduplicate(Profiles) -> + do_deduplicate(lists:reverse(Profiles), []). + +do_deduplicate([], Acc) -> + Acc; +do_deduplicate([Head | Rest], Acc) -> + case lists:member(Head, Acc) of + true -> do_deduplicate(Rest, Acc); + false -> do_deduplicate(Rest, [Head | Acc]) + end. + +merge_opts(Profile, NewOpts, OldOpts) -> + Opts = merge_opts(NewOpts, OldOpts), + + Opts2 = case dict:find(plugins, NewOpts) of + {ok, Value} -> + dict:store({plugins, Profile}, Value, Opts); + error -> + Opts + end, + + case dict:find(deps, NewOpts) of + {ok, Value2} -> + dict:store({deps, Profile}, Value2, Opts2); + error -> + Opts2 + end. + +merge_opts(NewOpts, OldOpts) -> + dict:merge(fun(deps, _NewValue, OldValue) -> + OldValue; + ({deps, _}, NewValue, _OldValue) -> + NewValue; + (plugins, NewValue, _OldValue) -> + NewValue; + ({plugins, _}, NewValue, _OldValue) -> + NewValue; + (profiles, NewValue, OldValue) -> + dict:to_list(merge_opts(dict:from_list(NewValue), dict:from_list(OldValue))); + (_Key, NewValue, OldValue) when is_list(NewValue) -> + case io_lib:printable_list(NewValue) of + true when NewValue =:= [] -> + case io_lib:printable_list(OldValue) of + true -> + NewValue; + false -> + OldValue + end; + true -> + NewValue; + false -> + rebar_utils:tup_umerge(rebar_utils:tup_sort(NewValue) + ,rebar_utils:tup_sort(OldValue)) + end; + (_Key, NewValue, _OldValue) -> + NewValue + end, NewOpts, OldOpts). diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index a7c78f5..07c262a 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -158,25 +158,27 @@ pkg_to_app(Parent, DepsDir, AppName, PkgName, PkgVsn, IsLock, State) -> dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State) -> CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, Name)), BaseDir = rebar_state:get(State, base_dir, []), - {ok, App1} = case rebar_app_info:discover(CheckoutsDir) of - {ok, App} -> - {ok, rebar_app_info:is_checkout(App, true)}; - not_found -> - Dir = ec_cnv:to_list(filename:join(DepsDir, Name)), - case rebar_app_info:discover(Dir) of - {ok, App} -> - {ok, rebar_app_info:parent(App, Parent)}; - not_found -> - rebar_app_info:new(Parent, Name, Vsn, Dir, []) - end - end, - C = rebar_config:consult(rebar_app_info:dir(App1)), - S = rebar_state:new(rebar_state:new(), C, App1), + {ok, AppInfo} = case rebar_app_info:discover(CheckoutsDir) of + {ok, App} -> + {ok, rebar_app_info:is_checkout(App, true)}; + not_found -> + Dir = ec_cnv:to_list(filename:join(DepsDir, Name)), + case rebar_app_info:discover(Dir) of + {ok, App} -> + {ok, rebar_app_info:parent(App, Parent)}; + not_found -> + rebar_app_info:new(Parent, Name, Vsn, Dir, []) + end + end, + C = rebar_config:consult(rebar_app_info:dir(AppInfo)), + AppInfo0 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C), + AppInfo1 = rebar_app_info:apply_overrides(AppInfo0, Name), Overrides = rebar_state:get(State, overrides, []), ParentOverrides = rebar_state:overrides(State), - S1 = rebar_state:set(rebar_state:overrides(S, ParentOverrides++Overrides), base_dir, BaseDir), - App2 = rebar_app_info:state(App1, S1), - rebar_app_info:is_lock(rebar_app_info:source(App2, Source), IsLock). + S1 = rebar_state:set(rebar_state:overrides(State, ParentOverrides++Overrides), base_dir, BaseDir), + %AppInfo2 = rebar_app_info:state(AppInfo1, S1), + AppInfo3 = rebar_app_info:opts(AppInfo1, rebar_state:opts(S1)), + rebar_app_info:is_lock(rebar_app_info:source(AppInfo3, Source), IsLock). format_error({missing_package, Package}) -> io_lib:format("Package not found in registry: ~s", [Package]); diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 7af94ea..af6696e 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -129,34 +129,34 @@ do_make_relative_path(Source, Target) -> Base = lists:duplicate(max(length(Target) - 1, 0), ".."), filename:join(Base ++ Source). --spec src_dirs(rebar_state:t()) -> list(file:filename_all()). +-spec src_dirs(rebar_app_info:t()) -> list(file:filename_all()). src_dirs(State) -> src_dirs(State, []). --spec src_dirs(rebar_state:t(), list(file:filename_all())) -> list(file:filename_all()). -src_dirs(State, Default) -> - ErlOpts = rebar_utils:erl_opts(State), +-spec src_dirs(rebar_app_info:t(), list(file:filename_all())) -> list(file:filename_all()). +src_dirs(AppInfo, Default) -> + ErlOpts = rebar_utils:erl_opts(AppInfo), Vs = proplists:get_all_values(src_dirs, ErlOpts), - case lists:append([rebar_state:get(State, src_dirs, []) | Vs]) of + case lists:append([rebar_utils:get(AppInfo, src_dirs, []) | Vs]) of [] -> Default; Dirs -> Dirs end. --spec extra_src_dirs(rebar_state:t()) -> list(file:filename_all()). -extra_src_dirs(State) -> extra_src_dirs(State, []). +-spec extra_src_dirs(rebar_app_info:t()) -> list(file:filename_all()). +extra_src_dirs(AppInfo) -> extra_src_dirs(AppInfo, []). --spec extra_src_dirs(rebar_state:t(), list(file:filename_all())) -> list(file:filename_all()). -extra_src_dirs(State, Default) -> - ErlOpts = rebar_utils:erl_opts(State), +-spec extra_src_dirs(rebar_app_info:t(), list(file:filename_all())) -> list(file:filename_all()). +extra_src_dirs(AppInfo, Default) -> + ErlOpts = rebar_utils:erl_opts(AppInfo), Vs = proplists:get_all_values(extra_src_dirs, ErlOpts), - case lists:append([rebar_state:get(State, extra_src_dirs, []) | Vs]) of + case lists:append([rebar_utils:get(AppInfo, extra_src_dirs, []) | Vs]) of [] -> Default; Dirs -> Dirs end. --spec all_src_dirs(rebar_state:t()) -> list(file:filename_all()). -all_src_dirs(State) -> all_src_dirs(State, [], []). +-spec all_src_dirs(rebar_app_info:t()) -> list(file:filename_all()). +all_src_dirs(AppInfo) -> all_src_dirs(AppInfo, [], []). --spec all_src_dirs(rebar_state:t(), list(file:filename_all()), list(file:filename_all())) -> +-spec all_src_dirs(rebar_app_info:t(), list(file:filename_all()), list(file:filename_all())) -> list(file:filename_all()). -all_src_dirs(State, SrcDefault, ExtraDefault) -> - src_dirs(State, SrcDefault) ++ extra_src_dirs(State, ExtraDefault). +all_src_dirs(AppInfo, SrcDefault, ExtraDefault) -> + src_dirs(AppInfo, SrcDefault) ++ extra_src_dirs(AppInfo, ExtraDefault). diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 90193da..69b5f29 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -26,7 +26,7 @@ %% ------------------------------------------------------------------- -module(rebar_erlc_compiler). --export([compile/2, +-export([compile/1, compile/3, clean/2]). @@ -80,31 +80,32 @@ %% 'old_inets'}]}. %% --spec compile(rebar_state:t(), file:name()) -> 'ok'. -compile(Config, Dir) -> - compile(Config, Dir, filename:join([Dir, "ebin"])). +-spec compile(rebar_app_info:t()) -> 'ok'. +compile(AppInfo) -> + Dir = ec_cnv:to_list(rebar_app_info:out_dir(AppInfo)), + compile(rebar_app_info:opts(AppInfo), Dir, filename:join([Dir, "ebin"])). --spec compile(rebar_state:t(), file:name(), file:name()) -> 'ok'. -compile(Config, Dir, OutDir) -> - rebar_base_compiler:run(Config, - check_files(rebar_state:get( - Config, xrl_first_files, [])), +-spec compile(rebar_app_info:t(), file:name(), file:name()) -> 'ok'. +compile(AppInfo, Dir, OutDir) -> + rebar_base_compiler:run(AppInfo, + check_files(rebar_utils:get( + AppInfo, xrl_first_files, [])), filename:join(Dir, "src"), ".xrl", filename:join(Dir, "src"), ".erl", fun compile_xrl/3), - rebar_base_compiler:run(Config, - check_files(rebar_state:get( - Config, yrl_first_files, [])), + rebar_base_compiler:run(AppInfo, + check_files(rebar_utils:get( + AppInfo, yrl_first_files, [])), filename:join(Dir, "src"), ".yrl", filename:join(Dir, "src"), ".erl", fun compile_yrl/3), - rebar_base_compiler:run(Config, - check_files(rebar_state:get( - Config, mib_first_files, [])), + rebar_base_compiler:run(AppInfo, + check_files(rebar_utils:get( + AppInfo, mib_first_files, [])), filename:join(Dir, "mibs"), ".mib", filename:join([Dir, "priv", "mibs"]), ".bin", fun compile_mib/3), - doterl_compile(Config, Dir, OutDir). + doterl_compile(AppInfo, Dir, OutDir). --spec clean(rebar_state:t(), file:filename()) -> 'ok'. -clean(_Config, AppDir) -> +-spec clean(rebar_app_info:t(), file:filename()) -> 'ok'. +clean(_AppInfo, AppDir) -> MibFiles = rebar_utils:find_files(filename:join(AppDir, "mibs"), ?RE_PREFIX".*\\.mib\$"), MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles], rebar_file_utils:delete_each( @@ -133,17 +134,17 @@ clean(_Config, AppDir) -> %% Internal functions %% =================================================================== --spec doterl_compile(rebar_state:t(), file:filename(), file:filename()) -> ok. +-spec doterl_compile(rebar_app_info:t(), file:filename(), file:filename()) -> ok. doterl_compile(State, Dir, ODir) -> ErlOpts = rebar_utils:erl_opts(State), doterl_compile(State, Dir, ODir, [], ErlOpts). -doterl_compile(Config, Dir, OutDir, MoreSources, ErlOpts) -> +doterl_compile(AppInfo, Dir, OutDir, MoreSources, ErlOpts) -> ?DEBUG("erl_opts ~p", [ErlOpts]), %% Support the src_dirs option allowing multiple directories to %% contain erlang source. This might be used, for example, should %% eunit tests be separated from the core application source. - SrcDirs = [filename:join(Dir, X) || X <- rebar_dir:all_src_dirs(Config, ["src"], [])], + SrcDirs = [filename:join(Dir, X) || X <- rebar_dir:all_src_dirs(AppInfo, ["src"], [])], AllErlFiles = gather_src(SrcDirs, []) ++ MoreSources, %% Make sure that ebin/ exists and is on the path @@ -155,7 +156,7 @@ doterl_compile(Config, Dir, OutDir, MoreSources, ErlOpts) -> G = init_erlcinfo(proplists:get_all_values(i, ErlOpts), AllErlFiles, Dir, OutDir), NeededErlFiles = needed_files(G, ErlOpts, Dir, OutDir1, AllErlFiles), - {ErlFirstFiles, ErlOptsFirst} = erl_first_files(Config, ErlOpts, Dir, NeededErlFiles), + {ErlFirstFiles, ErlOptsFirst} = erl_first_files(AppInfo, ErlOpts, Dir, NeededErlFiles), {DepErls, OtherErls} = lists:partition( fun(Source) -> digraph:in_degree(G, Source) > 0 end, [File || File <- NeededErlFiles, not lists:member(File, ErlFirstFiles)]), @@ -165,7 +166,7 @@ doterl_compile(Config, Dir, OutDir, MoreSources, ErlOpts) -> ?DEBUG("Files to compile first: ~p", [FirstErls]), try rebar_base_compiler:run( - Config, FirstErls, OtherErls, + AppInfo, FirstErls, OtherErls, fun(S, C) -> ErlOpts1 = case lists:member(S, ErlFirstFiles) of true -> ErlOptsFirst; @@ -182,8 +183,8 @@ doterl_compile(Config, Dir, OutDir, MoreSources, ErlOpts) -> %% Get files which need to be compiled first, i.e. those specified in erl_first_files %% and parse_transform options. Also produce specific erl_opts for these first %% files, so that yet to be compiled parse transformations are excluded from it. -erl_first_files(Config, ErlOpts, Dir, NeededErlFiles) -> - ErlFirstFilesConf = rebar_state:get(Config, erl_first_files, []), +erl_first_files(AppInfo, ErlOpts, Dir, NeededErlFiles) -> + ErlFirstFilesConf = rebar_utils:get(AppInfo, erl_first_files, []), NeededSrcDirs = lists:usort(lists:map(fun filename:dirname/1, NeededErlFiles)), %% NOTE: order of files here is important! ErlFirstFiles = @@ -402,9 +403,9 @@ expand_file_names(Files, Dirs) -> end, Files). --spec internal_erl_compile(rebar_state:t(), file:filename(), file:filename(), +-spec internal_erl_compile(rebar_app_info:t(), file:filename(), file:filename(), file:filename(), list()) -> ok | {ok, any()} | {error, any(), any()}. -internal_erl_compile(Config, Dir, Module, OutDir, ErlOpts) -> +internal_erl_compile(AppInfo, Dir, Module, OutDir, ErlOpts) -> Target = target_base(OutDir, Module) ++ ".beam", ok = filelib:ensure_dir(Target), Opts = [{outdir, filename:dirname(Target)}] ++ ErlOpts ++ @@ -413,23 +414,23 @@ internal_erl_compile(Config, Dir, Module, OutDir, ErlOpts) -> {ok, _Mod} -> ok; {ok, _Mod, Ws} -> - rebar_base_compiler:ok_tuple(Config, Module, Ws); + rebar_base_compiler:ok_tuple(AppInfo, Module, Ws); {error, Es, Ws} -> - rebar_base_compiler:error_tuple(Config, Module, Es, Ws, Opts) + rebar_base_compiler:error_tuple(AppInfo, Module, Es, Ws, Opts) end. target_base(OutDir, Source) -> filename:join(OutDir, filename:basename(Source, ".erl")). -spec compile_mib(file:filename(), file:filename(), - rebar_state:t()) -> 'ok'. -compile_mib(Source, Target, Config) -> - Dir = rebar_state:dir(Config), + rebar_app_info:t()) -> 'ok'. +compile_mib(Source, Target, AppInfo) -> + Dir = filename:dirname(Target), ok = filelib:ensure_dir(Target), ok = filelib:ensure_dir(filename:join([Dir, "include", "dummy.hrl"])), - Opts = [{outdir, filename:join([Dir, "priv", "mibs"])} - ,{i, [filename:join([Dir, "priv", "mibs"])]}] ++ - rebar_state:get(Config, mib_opts, []), + Opts = [{outdir, Dir} + ,{i, [Dir]}] ++ + rebar_utils:get(AppInfo, mib_opts, []), case snmpc:compile(Source, Opts) of {ok, _} -> @@ -450,21 +451,21 @@ compile_mib(Source, Target, Config) -> end. -spec compile_xrl(file:filename(), file:filename(), - rebar_state:t()) -> 'ok'. -compile_xrl(Source, Target, Config) -> - Opts = [{scannerfile, Target} | rebar_state:get(Config, xrl_opts, [])], - compile_xrl_yrl(Config, Source, Target, Opts, leex). + rebar_app_info:t()) -> 'ok'. +compile_xrl(Source, Target, AppInfo) -> + Opts = [{scannerfile, Target} | rebar_utils:get(AppInfo, xrl_opts, [])], + compile_xrl_yrl(AppInfo, Source, Target, Opts, leex). -spec compile_yrl(file:filename(), file:filename(), - rebar_state:t()) -> 'ok'. -compile_yrl(Source, Target, Config) -> - Opts = [{parserfile, Target} | rebar_state:get(Config, yrl_opts, [])], - compile_xrl_yrl(Config, Source, Target, Opts, yecc). + rebar_app_info:t()) -> 'ok'. +compile_yrl(Source, Target, AppInfo) -> + Opts = [{parserfile, Target} | rebar_utils:get(AppInfo, yrl_opts, [])], + compile_xrl_yrl(AppInfo, Source, Target, Opts, yecc). --spec compile_xrl_yrl(rebar_state:t(), file:filename(), +-spec compile_xrl_yrl(rebar_app_info:t(), file:filename(), file:filename(), list(), module()) -> 'ok'. -compile_xrl_yrl(Config, Source, Target, Opts, Mod) -> - Dir = rebar_state:dir(Config), +compile_xrl_yrl(AppInfo, Source, Target, Opts, Mod) -> + Dir = filename:dirname(Target), Opts1 = [{includefile, filename:join(Dir, I)} || {includefile, I} <- Opts, filename:pathtype(I) =:= relative], case needs_compile(Source, Target) of @@ -473,9 +474,9 @@ compile_xrl_yrl(Config, Source, Target, Opts, Mod) -> {ok, _} -> ok; {ok, _Mod, Ws} -> - rebar_base_compiler:ok_tuple(Config, Source, Ws); + rebar_base_compiler:ok_tuple(AppInfo, Source, Ws); {error, Es, Ws} -> - rebar_base_compiler:error_tuple(Config, Source, + rebar_base_compiler:error_tuple(AppInfo, Source, Es, Ws, Opts1) end; false -> diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index 857336c..c5f8b88 100644 --- a/src/rebar_hooks.erl +++ b/src/rebar_hooks.erl @@ -1,30 +1,34 @@ -module(rebar_hooks). -export([run_all_hooks/5 + ,run_all_hooks/6 ,format_error/1]). -include("rebar.hrl"). -include_lib("providers/include/providers.hrl"). +run_all_hooks(Dir, Type, Command, Providers, State) -> + run_all_hooks(Dir, Type, Command, Providers, element(2,rebar_app_info:new(noen)), State). + -spec run_all_hooks(file:filename_all(), pre | post, atom() | {atom(), atom()} | string(), - [providers:t()], rebar_state:t()) -> ok. -run_all_hooks(Dir, Type, Command, Providers, State) -> - run_provider_hooks(Dir, Type, Command, Providers, State), - run_hooks(Dir, Type, Command, State). + [providers:t()], rebar_app_info:t(), rebar_state:t()) -> ok. +run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) -> + run_provider_hooks(Dir, Type, Command, Providers, AppInfo, State), + run_hooks(Dir, Type, Command, AppInfo, State). -run_provider_hooks(Dir, Type, Command, Providers, State) -> - case rebar_state:get(State, provider_hooks, []) of +run_provider_hooks(Dir, Type, Command, Providers, AppInfo, State) -> + case rebar_app_info:get(AppInfo, provider_hooks, [])++rebar_state:get(State, provider_hooks, []) of [] -> ok; AllHooks -> TypeHooks = proplists:get_value(Type, AllHooks, []), - run_provider_hooks(Dir, Type, Command, Providers, TypeHooks, State) + run_provider_hooks(Dir, Type, Command, Providers, TypeHooks, AppInfo, State) end. -run_provider_hooks(_Dir, _Type, _Command, _Providers, [], _State) -> +run_provider_hooks(_Dir, _Type, _Command, _Providers, [], _AppInfo, _State) -> ok; -run_provider_hooks(Dir, Type, Command, Providers, TypeHooks, State) -> +run_provider_hooks(Dir, Type, Command, Providers, TypeHooks, _AppInfo, State) -> PluginDepsPaths = rebar_state:code_paths(State, all_plugin_deps), code:add_pathsa(PluginDepsPaths), Providers1 = rebar_state:providers(State), @@ -67,16 +71,16 @@ format_error({bad_provider, Type, Command, Name}) -> %% ERL = ERLANG_ROOT_DIR/bin/erl %% ERLC = ERLANG_ROOT_DIR/bin/erl %% -run_hooks(Dir, pre, Command, State) -> - run_hooks(Dir, pre_hooks, Command, State); -run_hooks(Dir, post, Command, State) -> - run_hooks(Dir, post_hooks, Command, State); -run_hooks(Dir, Type, Command, State) -> - case rebar_state:get(State, Type, []) of +run_hooks(Dir, pre, Command, AppInfo, State) -> + run_hooks(Dir, pre_hooks, Command, AppInfo, State); +run_hooks(Dir, post, Command, AppInfo, State) -> + run_hooks(Dir, post_hooks, Command, AppInfo, State); +run_hooks(Dir, Type, Command, AppInfo, State) -> + case rebar_app_info:get(AppInfo, Type, []) of [] -> ok; Hooks -> - Env = create_env(State), + Env = create_env(State, AppInfo), lists:foreach(fun({_, C, _}=Hook) when C =:= Command -> apply_hook(Dir, Env, Hook); ({C, _}=Hook) when C =:= Command -> @@ -97,8 +101,9 @@ apply_hook(Dir, Env, {Command, Hook}) -> Msg = lists:flatten(io_lib:format("Hook for ~p failed!~n", [Command])), rebar_utils:sh(Hook, [use_stdout, {cd, Dir}, {env, Env}, {abort_on_error, Msg}]). -create_env(State) -> - BaseDir = rebar_state:dir(State), +create_env(State, AppInfo) -> + Opts = rebar_app_info:opts(AppInfo), + BaseDir = rebar_dir:base_dir(State), [ {"REBAR_DEPS_DIR", filename:absname(rebar_dir:deps_dir(State))}, {"REBAR_BUILD_DIR", filename:absname(rebar_dir:base_dir(State))}, @@ -109,7 +114,7 @@ create_env(State) -> {"REBAR_GLOBAL_CACHE_DIR", filename:absname(rebar_dir:global_cache_dir(State))}, {"REBAR_TEMPLATE_DIR", filename:absname(rebar_dir:template_dir(State))}, {"REBAR_APP_DIRS", join_dirs(BaseDir, rebar_dir:lib_dirs(State))}, - {"REBAR_SRC_DIRS", join_dirs(BaseDir, rebar_dir:all_src_dirs(State))}, + {"REBAR_SRC_DIRS", join_dirs(BaseDir, rebar_dir:all_src_dirs(Opts))}, {"ERLANG_ERTS_VER", erlang:system_info(version)}, {"ERLANG_ROOT_DIR", code:root_dir()}, {"ERLANG_LIB_DIR_erl_interface", code:lib_dir(erl_interface)}, diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index 507da70..c1d90bc 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -106,7 +106,7 @@ preprocess(State, AppInfo, AppSrcFile) -> %% substitute. Note that we include the list of modules available in %% ebin/ and update the app data accordingly. OutDir = rebar_app_info:out_dir(AppInfo), - AppVars = load_app_vars(State) ++ [{modules, ebin_modules(State, AppInfo, OutDir)}], + AppVars = load_app_vars(State) ++ [{modules, ebin_modules(AppInfo, OutDir)}], A1 = apply_app_vars(AppVars, AppData), %% AppSrcFile may contain instructions for generating a vsn number @@ -158,21 +158,21 @@ validate_name(AppName, File) -> ?PRV_ERROR({invalid_name, File, AppName}) end. -ebin_modules(State, App, Dir) -> +ebin_modules(AppInfo, Dir) -> Beams = lists:sort(rebar_utils:beams(filename:join(Dir, "ebin"))), - ExtraDirs = extra_dirs(State), - F = fun(Beam) -> not in_extra_dir(App, Beam, ExtraDirs) end, + ExtraDirs = extra_dirs(AppInfo), + F = fun(Beam) -> not in_extra_dir(AppInfo, Beam, ExtraDirs) end, Filtered = lists:filter(F, Beams), [rebar_utils:beam_to_mod(N) || N <- Filtered]. extra_dirs(State) -> - Extras = rebar_dir:extra_src_dirs(State), - SrcDirs = rebar_dir:src_dirs(State, ["src"]), + Extras = rebar_dir:extra_src_dirs(rebar_app_info:opts(State)), + SrcDirs = rebar_dir:src_dirs(rebar_app_info:opts(State), ["src"]), %% remove any dirs that are defined in `src_dirs` from `extra_src_dirs` Extras -- SrcDirs. -in_extra_dir(App, Beam, Dirs) -> - lists:any(fun(Dir) -> lists:prefix(filename:join([rebar_app_info:out_dir(App), Dir]), +in_extra_dir(AppInfo, Beam, Dirs) -> + lists:any(fun(Dir) -> lists:prefix(filename:join([rebar_app_info:out_dir(AppInfo), Dir]), beam_src(Beam)) end, Dirs). diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 6c2daef..752514c 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -4,7 +4,7 @@ -module(rebar_plugins). -export([project_apps_install/1 - ,install/1 + ,install/2 ,handle_plugins/3 ,handle_plugins/4]). @@ -23,20 +23,19 @@ project_apps_install(State) -> Plugins = rebar_state:get(State, {plugins, Profile}, []), StateAcc1 = handle_plugins(Profile, Plugins, StateAcc), - lists:foldl(fun(App, StateAcc2) -> - AppDir = rebar_app_info:dir(App), - C = rebar_config:consult(AppDir), - S = rebar_state:new(rebar_state:new(), C, AppDir), - Plugins2 = rebar_state:get(S, {plugins, Profile}, []), + lists:foldl(fun(AppInfo, StateAcc2) -> + C = rebar_config:consult(rebar_app_info:dir(AppInfo)), + AppInfo0 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C), + Plugins2 = rebar_state:get(AppInfo0, {plugins, Profile}, []), handle_plugins(Profile, Plugins2, StateAcc2) end, StateAcc1, ProjectApps) end, State, Profiles). --spec install(rebar_state:t()) -> rebar_state:t(). -install(State) -> +-spec install(rebar_state:t(), rebar_app_info:t()) -> rebar_state:t(). +install(State, AppInfo) -> Profiles = rebar_state:current_profiles(State), lists:foldl(fun(Profile, StateAcc) -> - Plugins = rebar_state:get(State, {plugins, Profile}, []), + Plugins = rebar_app_info:get(AppInfo, {plugins, Profile}, []), handle_plugins(Profile, Plugins, StateAcc) end, State, Profiles). @@ -92,10 +91,10 @@ handle_plugin(Profile, Plugin, State, Upgrade) -> build_plugin(AppInfo, Apps, State) -> Providers = rebar_state:providers(State), - Providers1 = rebar_state:providers(rebar_app_info:state(AppInfo)), + %Providers1 = rebar_state:providers(rebar_app_info:state(AppInfo)), S = rebar_state:all_deps(rebar_app_info:state_or_new(State, AppInfo), Apps), S1 = rebar_state:set(S, deps_dir, ?DEFAULT_PLUGINS_DIR), - rebar_prv_compile:compile(S1, Providers++Providers1, AppInfo). + rebar_prv_compile:compile(S1, Providers, AppInfo). plugin_providers({Plugin, _, _, _}) when is_atom(Plugin) -> validate_plugin(Plugin); diff --git a/src/rebar_prv_clean.erl b/src/rebar_prv_clean.erl index f10d12b..1d1d4c7 100644 --- a/src/rebar_prv_clean.erl +++ b/src/rebar_prv_clean.erl @@ -50,9 +50,9 @@ do(State) -> clean_apps(EmptyState, Providers, DepApps), Cwd = rebar_dir:get_cwd(), - rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State), + rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, element(2,rebar_app_info:new(noen)), State), clean_apps(State, Providers, ProjectApps), - rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State), + rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, element(2,rebar_app_info:new(noen)), State), {ok, State}. @@ -70,9 +70,9 @@ clean_apps(State, Providers, Apps) -> S = rebar_app_info:state_or_new(State, AppInfo), ?INFO("Cleaning out ~s...", [rebar_app_info:name(AppInfo)]), - rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, S), + rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, S), rebar_erlc_compiler:clean(State, rebar_app_info:out_dir(AppInfo)), - rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, S) + rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo, S) end, Apps). handle_args(State) -> diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 25e9dad..aafc425 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -43,12 +43,12 @@ do(State) -> %% Run ct provider prehooks Providers = rebar_state:providers(State), Cwd = rebar_dir:get_cwd(), - rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State), + rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, element(2,rebar_app_info:new(noen)), State), try run_test(State) of {ok, State1} = Result -> %% Run ct provider posthooks - rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State1), + rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, element(2,rebar_app_info:new(noen)), State1), rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)), Result; ?PRV_ERROR(_) = Error -> @@ -307,7 +307,7 @@ copy(State, Dir) -> compile_dir(State, Dir) -> NewState = replace_src_dirs(State, [filename:absname(Dir)]), - ok = rebar_erlc_compiler:compile(NewState, rebar_dir:base_dir(State), Dir), + ok = rebar_erlc_compiler:compile(rebar_state:opts(NewState), rebar_dir:base_dir(State), Dir), ok = maybe_cover_compile(State, Dir), Dir. diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 74be7a6..072255d 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -52,7 +52,7 @@ do(State) -> {ok, ProjectApps1} = rebar_digraph:compile_order(ProjectApps), %% Run top level hooks *before* project apps compiled but *after* deps are - rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State), + rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, element(2,rebar_app_info:new(noen)), State), ProjectApps2 = build_apps(State, Providers, ProjectApps1), State2 = rebar_state:project_apps(State, ProjectApps2), @@ -60,7 +60,7 @@ do(State) -> ProjAppsPaths = [filename:join(rebar_app_info:out_dir(X), "ebin") || X <- ProjectApps2], State3 = rebar_state:code_paths(State2, all_deps, DepsPaths ++ ProjAppsPaths), - rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State2), + rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, element(2,rebar_app_info:new(noen)), State2), has_all_artifacts(State3), rebar_utils:cleanup_code_path(rebar_state:code_paths(State3, default) @@ -80,7 +80,7 @@ build_apps(State, Providers, Apps) -> build_app(State, Providers, AppInfo) -> AppDir = rebar_app_info:dir(AppInfo), OutDir = rebar_app_info:out_dir(AppInfo), - copy_app_dirs(State, AppDir, OutDir), + copy_app_dirs(AppInfo, AppDir, OutDir), S = rebar_app_info:state_or_new(State, AppInfo), S1 = rebar_state:all_deps(S, rebar_state:all_deps(State)), @@ -89,12 +89,12 @@ build_app(State, Providers, AppInfo) -> compile(State, Providers, AppInfo) -> ?INFO("Compiling ~s", [rebar_app_info:name(AppInfo)]), AppDir = rebar_app_info:dir(AppInfo), - rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, State), + rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State), - rebar_erlc_compiler:compile(State, ec_cnv:to_list(rebar_app_info:out_dir(AppInfo))), + rebar_erlc_compiler:compile(AppInfo), case rebar_otp_app:compile(State, AppInfo) of {ok, AppInfo1} -> - rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, State), + rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo, State), has_all_artifacts(State), AppInfo1; Error -> @@ -113,7 +113,7 @@ has_all_artifacts(State) -> true end. -copy_app_dirs(State, OldAppDir, AppDir) -> +copy_app_dirs(AppInfo, OldAppDir, AppDir) -> case ec_cnv:to_binary(filename:absname(OldAppDir)) =/= ec_cnv:to_binary(filename:absname(AppDir)) of true -> @@ -142,7 +142,7 @@ copy_app_dirs(State, OldAppDir, AppDir) -> end, %% link to src_dirs to be adjacent to ebin is needed for R15 use of cover/xref - SrcDirs = rebar_dir:all_src_dirs(State, ["src"], []), + SrcDirs = rebar_dir:all_src_dirs(rebar_app_info:opts(AppInfo), ["src"], []), [symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include"] ++ SrcDirs]; false -> ok diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index ca9344b..06033f6 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -254,28 +254,29 @@ handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) -> Profiles = rebar_state:current_profiles(State), Name = rebar_app_info:name(AppInfo), - %% Deps may be under a sub project app, find it and use its state if so - S = rebar_app_info:state(AppInfo), C = rebar_config:consult(rebar_app_info:dir(AppInfo)), - S1 = rebar_state:new(S, C, AppInfo), - S2 = rebar_state:apply_overrides(S1, Name), + AppInfo0 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C), + AppInfo1 = rebar_app_info:apply_overrides(AppInfo0, Name), - S3 = rebar_state:apply_profiles(S2, Profiles), - Plugins = rebar_state:get(S3, plugins, []), - S4 = rebar_state:set(S3, {plugins, Profile}, Plugins), + AppInfo2 = rebar_app_info:apply_profiles(AppInfo1, Profiles), + Plugins = rebar_app_info:get(AppInfo2, plugins, []), + AppInfo3 = rebar_app_info:set(AppInfo2, {plugins, Profile}, Plugins), - rebar_utils:check_min_otp_version(rebar_state:get(S4, minimum_otp_vsn, undefined)), - rebar_utils:check_blacklisted_otp_versions(rebar_state:get(S4, blacklisted_otp_vsns, [])), + rebar_utils:check_min_otp_version(rebar_app_info:get(AppInfo3, minimum_otp_vsn, undefined)), + rebar_utils:check_blacklisted_otp_versions(rebar_app_info:get(AppInfo3, blacklisted_otp_vsns, [])), %% Dep may have plugins to install. Find and install here. - S5 = rebar_plugins:install(S4), - AppInfo1 = rebar_app_info:state(AppInfo, S5), + _S = rebar_plugins:install(State, AppInfo3), + %% TODO: Plugin Providers?? + + %AppInfo1 = rebar_app_info:state(AppInfo, S5), + %AppInfo2 = rebar_app_info:opts(AppInfo1, rebar_state:opts(S5)), %% Upgrade lock level to be the level the dep will have in this dep tree - Deps = rebar_state:get(S5, {deps, default}, []), - AppInfo2 = rebar_app_info:deps(AppInfo1, rebar_state:deps_names(Deps)), - Deps1 = rebar_app_utils:parse_deps(Name, DepsDir, Deps, S5, Locks, Level+1), - {AppInfo2, Deps1, State}. + Deps = rebar_app_info:get(AppInfo3, {deps, default}, []), + AppInfo4 = rebar_app_info:deps(AppInfo3, rebar_state:deps_names(Deps)), + Deps1 = rebar_app_utils:parse_deps(Name, DepsDir, Deps, State, Locks, Level+1), + {AppInfo4, Deps1, State}. -spec maybe_fetch(rebar_app_info:t(), atom(), boolean(), sets:set(binary()), rebar_state:t()) -> {boolean(), rebar_app_info:t()}. @@ -420,4 +421,4 @@ warn_skip_deps(AppInfo, State) -> not_needs_compile(App) -> not(rebar_app_info:is_checkout(App)) andalso rebar_app_info:valid(App) - andalso rebar_state:has_all_artifacts(rebar_app_info:state(App)) =:= true. + andalso rebar_app_info:has_all_artifacts(App) =:= true. diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 02a2262..cf6e8e8 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -26,7 +26,10 @@ %% ------------------------------------------------------------------- -module(rebar_utils). --export([sort_deps/1, +-export([get/2, + get/3, + set/3, + sort_deps/1, droplast/1, filtermap/2, is_arch/1, @@ -80,6 +83,21 @@ %% Public API %% ==================================================================== +get(Opts, Key) -> + {ok, Value} = dict:find(Key, Opts), + Value. + +get(Opts, Key, Default) -> + case dict:find(Key, Opts) of + {ok, Value} -> + Value; + error -> + Default + end. + +set(Opts, Key, Value) -> + dict:store(Key, Value, Opts). + sort_deps(Deps) -> %% We need a sort stable, based on the name. So that for multiple deps on %% the same level with the same name, we keep the order the parents had. @@ -219,11 +237,11 @@ deprecated(Old, New, When) -> [Old, Old, New, Old, When]). %% @doc Return list of erl_opts --spec erl_opts(rebar_state:t()) -> list(). -erl_opts(Config) -> - RawErlOpts = filter_defines(rebar_state:get(Config, erl_opts, []), []), +-spec erl_opts(rebar_app_info:t()) -> list(). +erl_opts(AppInfo) -> + RawErlOpts = filter_defines(rebar_utils:get(AppInfo, erl_opts, []), []), Defines = [{d, list_to_atom(D)} || - D <- rebar_state:get(Config, defines, [])], + D <- rebar_utils:get(AppInfo, defines, [])], Opts = Defines ++ RawErlOpts, case proplists:is_defined(no_debug_info, Opts) of true -> |