diff options
author | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-07-14 23:44:47 +0200 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-07-23 13:17:11 +0200 |
commit | 252757c753e9ec5c5247a86eb635aee385d05ee1 (patch) | |
tree | a4d81e806bdfed018f0e5edf01aa4889d0a58896 /src/rebar_deps.erl | |
parent | 3c56fbab6f5d0b87ba21fac828899d20132d5066 (diff) | |
download | rebar-252757c753e9ec5c5247a86eb635aee385d05ee1.tar.gz |
Do not use application:set_env
Diffstat (limited to 'src/rebar_deps.erl')
-rw-r--r-- | src/rebar_deps.erl | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl index 1abdce7..72c7769 100644 --- a/src/rebar_deps.erl +++ b/src/rebar_deps.erl @@ -52,40 +52,41 @@ preprocess(Config, _) -> %% Side effect to set deps_dir globally for all dependencies from %% top level down. Means the root deps_dir is honoured or the default %% used globally since it will be set on the first time through here - set_global_deps_dir(Config, rebar_config:get_global(deps_dir, [])), + DepsDir = rebar_config:get_global(Config, deps_dir, []), + Config1 = set_global_deps_dir(Config, DepsDir), %% Get the list of deps for the current working directory and identify those %% deps that are available/present. - Deps = rebar_config:get_local(Config, deps, []), - {Config1, {AvailableDeps, MissingDeps}} = find_deps(Config, find, Deps), + Deps = rebar_config:get_local(Config1, deps, []), + {Config2, {AvailableDeps, MissingDeps}} = find_deps(Config1, find, Deps), ?DEBUG("Available deps: ~p\n", [AvailableDeps]), ?DEBUG("Missing deps : ~p\n", [MissingDeps]), %% Add available deps to code path - Config2 = update_deps_code_path(Config1, AvailableDeps), + Config3 = update_deps_code_path(Config2, AvailableDeps), %% If skip_deps=true, mark each dep dir as a skip_dir w/ the core so that %% the current command doesn't run on the dep dir. However, pre/postprocess %% WILL run (and we want it to) for transitivity purposes. - NewConfig = case rebar_config:get_global(skip_deps, false) of + NewConfig = case rebar_config:get_global(Config3, skip_deps, false) of "true" -> lists:foldl( fun(#dep{dir = Dir}, C) -> rebar_config:set_skip_dir(C, Dir) - end, Config2, AvailableDeps); + end, Config3, AvailableDeps); _ -> - Config2 + Config3 end, %% Return all the available dep directories for process {ok, NewConfig, dep_dirs(AvailableDeps)}. postprocess(Config, _) -> - case rebar_config:get_xconf(Config, ?MODULE) of - error -> + case rebar_config:get_xconf(Config, ?MODULE, undefined) of + undefined -> {ok, []}; - {ok, Dirs} -> + Dirs -> NewConfig = rebar_config:erase_xconf(Config, ?MODULE), {ok, NewConfig, Dirs} end. @@ -94,8 +95,8 @@ compile(Config, AppFile) -> 'check-deps'(Config, AppFile). %% set REBAR_DEPS_DIR and ERL_LIBS environment variables -setup_env(_Config) -> - {true, DepsDir} = get_deps_dir(), +setup_env(Config) -> + {true, DepsDir} = get_deps_dir(Config), %% include rebar's DepsDir in ERL_LIBS Separator = case os:type() of {win32, nt} -> @@ -149,7 +150,8 @@ setup_env(_Config) -> {Config1, Deps} = find_deps(Config, read, RawDeps), %% Update each dep - UpdatedDeps = [update_source(D) || D <- Deps, D#dep.source =/= undefined], + UpdatedDeps = [update_source(Config1, D) + || D <- Deps, D#dep.source =/= undefined], %% Add each updated dep to our list of dirs for post-processing. This yields %% the necessary transitivity of the deps @@ -157,7 +159,7 @@ setup_env(_Config) -> 'delete-deps'(Config, _) -> %% Delete all the available deps in our deps/ directory, if any - {true, DepsDir} = get_deps_dir(), + {true, DepsDir} = get_deps_dir(Config), Deps = rebar_config:get_local(Config, deps, []), {Config1, {AvailableDeps, _}} = find_deps(Config, find, Deps), _ = [delete_dep(D) @@ -183,17 +185,17 @@ setup_env(_Config) -> %% need all deps in same dir and should be the one set by the root rebar.config %% Sets a default if root config has no deps_dir set set_global_deps_dir(Config, []) -> - rebar_config:set_global(deps_dir, + rebar_config:set_global(Config, deps_dir, rebar_config:get_local(Config, deps_dir, "deps")); -set_global_deps_dir(_Config, _DepsDir) -> - ok. +set_global_deps_dir(Config, _DepsDir) -> + Config. -get_deps_dir() -> - get_deps_dir(""). +get_deps_dir(Config) -> + get_deps_dir(Config, ""). -get_deps_dir(App) -> - BaseDir = rebar_config:get_global(base_dir, []), - DepsDir = rebar_config:get_global(deps_dir, "deps"), +get_deps_dir(Config, App) -> + BaseDir = rebar_config:get_xconf(Config, base_dir, []), + DepsDir = rebar_config:get_global(Config, deps_dir, "deps"), {true, filename:join([BaseDir, DepsDir, App])}. dep_dirs(Deps) -> @@ -262,7 +264,7 @@ find_dep(Config, Dep) -> find_dep(Config, Dep, undefined) -> %% 'source' is undefined. If Dep is not satisfied locally, %% go ahead and find it amongst the lib_dir's. - case find_dep_in_dir(Config, Dep, get_deps_dir(Dep#dep.app)) of + case find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)) of {_Config1, {avail, _Dir}} = Avail -> Avail; {Config1, {missing, _}} -> @@ -272,7 +274,7 @@ find_dep(Config, Dep, _Source) -> %% _Source is defined. Regardless of what it is, we must find it %% locally satisfied or fetch it from the original source %% into the project's deps - find_dep_in_dir(Config, Dep, get_deps_dir(Dep#dep.app)). + find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)). find_dep_in_dir(Config, _Dep, {false, Dir}) -> {Config, {missing, Dir}}; @@ -365,7 +367,7 @@ use_source(Config, Dep, Count) -> false -> ?CONSOLE("Pulling ~p from ~p\n", [Dep#dep.app, Dep#dep.source]), require_source_engine(Dep#dep.source), - {true, TargetDir} = get_deps_dir(Dep#dep.app), + {true, TargetDir} = get_deps_dir(Config, Dep#dep.app), download_source(TargetDir, Dep#dep.source), use_source(Config, Dep#dep { dir = TargetDir }, Count-1) end. @@ -408,17 +410,17 @@ download_source(AppDir, {rsync, Url}) -> ok = filelib:ensure_dir(AppDir), rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s", [Url, AppDir]), []). -update_source(Dep) -> +update_source(Config, Dep) -> %% It's possible when updating a source, that a given dep does not have a %% VCS directory, such as when a source archive is built of a project, with %% all deps already downloaded/included. So, verify that the necessary VCS %% directory exists before attempting to do the update. - {true, AppDir} = get_deps_dir(Dep#dep.app), + {true, AppDir} = get_deps_dir(Config, Dep#dep.app), case has_vcs_dir(element(1, Dep#dep.source), AppDir) of true -> ?CONSOLE("Updating ~p from ~p\n", [Dep#dep.app, Dep#dep.source]), require_source_engine(Dep#dep.source), - update_source(AppDir, Dep#dep.source), + update_source1(AppDir, Dep#dep.source), Dep; false -> ?WARN("Skipping update for ~p: " @@ -426,29 +428,29 @@ update_source(Dep) -> Dep end. -update_source(AppDir, {git, Url}) -> - update_source(AppDir, {git, Url, {branch, "HEAD"}}); -update_source(AppDir, {git, Url, ""}) -> - update_source(AppDir, {git, Url, {branch, "HEAD"}}); -update_source(AppDir, {git, _Url, {branch, Branch}}) -> +update_source1(AppDir, {git, Url}) -> + update_source1(AppDir, {git, Url, {branch, "HEAD"}}); +update_source1(AppDir, {git, Url, ""}) -> + update_source1(AppDir, {git, Url, {branch, "HEAD"}}); +update_source1(AppDir, {git, _Url, {branch, Branch}}) -> ShOpts = [{cd, AppDir}], rebar_utils:sh("git fetch origin", ShOpts), rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), ShOpts); -update_source(AppDir, {git, _Url, {tag, Tag}}) -> +update_source1(AppDir, {git, _Url, {tag, Tag}}) -> ShOpts = [{cd, AppDir}], rebar_utils:sh("git fetch --tags origin", ShOpts), rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), ShOpts); -update_source(AppDir, {git, _Url, Refspec}) -> +update_source1(AppDir, {git, _Url, Refspec}) -> ShOpts = [{cd, AppDir}], rebar_utils:sh("git fetch origin", ShOpts), rebar_utils:sh(?FMT("git checkout -q ~s", [Refspec]), ShOpts); -update_source(AppDir, {svn, _Url, Rev}) -> +update_source1(AppDir, {svn, _Url, Rev}) -> rebar_utils:sh(?FMT("svn up -r ~s", [Rev]), [{cd, AppDir}]); -update_source(AppDir, {hg, _Url, Rev}) -> +update_source1(AppDir, {hg, _Url, Rev}) -> rebar_utils:sh(?FMT("hg pull -u -r ~s", [Rev]), [{cd, AppDir}]); -update_source(AppDir, {bzr, _Url, Rev}) -> +update_source1(AppDir, {bzr, _Url, Rev}) -> rebar_utils:sh(?FMT("bzr update -r ~s", [Rev]), [{cd, AppDir}]); -update_source(AppDir, {rsync, Url}) -> +update_source1(AppDir, {rsync, Url}) -> rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s",[Url,AppDir]),[]). %% =================================================================== |