summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar.erl9
-rw-r--r--src/rebar_core.erl2
-rw-r--r--src/rebar_deps.erl51
-rw-r--r--src/rebar_utils.erl24
4 files changed, 67 insertions, 19 deletions
diff --git a/src/rebar.erl b/src/rebar.erl
index 2fceb19..5a809d2 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -143,7 +143,7 @@ init_config({Options, _NonOptArgs}) ->
%% Keep track of how many operations we do, so we can detect bad commands
BaseConfig1 = rebar_config:set_xconf(BaseConfig, operations, 0),
%% Initialize vsn cache
- rebar_config:set_xconf(BaseConfig1, vsn_cache, dict:new()).
+ rebar_utils:init_vsn_cache(BaseConfig1).
init_config1(BaseConfig) ->
%% Determine the location of the rebar executable; important for pulling
@@ -284,7 +284,12 @@ help() ->
{"freebsd", compile, "c_src/freebsd_tweaks.sh"},
{eunit, "touch file2.out"},
{compile, "touch postcompile.out"}]}
- ]).
+ ]),
+ ?CONSOLE(
+ "Environment variables:~n"
+ " REBAR_DEPS_PREFER_LIBS to look for dependecies in system libs prior fetching.~n"
+ " REBAR_VSN_CACHE_FILE to load vsn cache from and save to specified file.~n"
+ "~n", []).
%%
%% Parse command line arguments using getopt and also filtering out any
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 0650430..6cc8d38 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -106,7 +106,7 @@ process_commands([Command | Rest], ParentConfig) ->
ParentConfig2),
%% Wipe out vsn cache to avoid invalid hits when
%% dependencies are updated
- rebar_config:set_xconf(ParentConfig3, vsn_cache, dict:new())
+ rebar_utils:init_vsn_cache(ParentConfig3)
catch
throw:rebar_abort ->
case rebar_config:get_xconf(ParentConfig1, keep_going, false) of
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl
index a6e5b27..995ce97 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -58,16 +58,19 @@ preprocess(Config, _) ->
%% used globally since it will be set on the first time through here
Config1 = set_shared_deps_dir(Config, get_shared_deps_dir(Config, [])),
+ %% Check whether user forced deps resolution via system wide libs
+ Config2 = set_deps_prefer_libs(Config1, get_deps_prefer_libs(Config1, undefined)),
+
%% Get the list of deps for the current working directory and identify those
%% deps that are available/present.
- Deps = rebar_config:get_local(Config1, deps, []),
- {Config2, {AvailableDeps, MissingDeps}} = find_deps(Config1, find, Deps),
+ Deps = rebar_config:get_local(Config2, deps, []),
+ {Config3, {AvailableDeps, MissingDeps}} = find_deps(Config2, find, Deps),
?DEBUG("Available deps: ~p\n", [AvailableDeps]),
?DEBUG("Missing deps : ~p\n", [MissingDeps]),
%% Add available deps to code path
- Config3 = update_deps_code_path(Config2, AvailableDeps),
+ Config4 = update_deps_code_path(Config3, AvailableDeps),
%% Filtering out 'raw' dependencies so that no commands other than
%% deps-related can be executed on their directories.
@@ -83,8 +86,8 @@ preprocess(Config, _) ->
fun(D, Acc) ->
rebar_config:set_skip_dir(Acc, D#dep.dir)
end,
- Config3,
- collect_deps(rebar_utils:get_cwd(), Config3)),
+ Config4,
+ collect_deps(rebar_utils:get_cwd(), Config4)),
%% Return the empty list, as we don't want anything processed before
%% us.
{ok, NewConfig, []};
@@ -97,12 +100,12 @@ preprocess(Config, _) ->
%% Also, if skip_deps=comma,separated,app,list, then only the given
%% dependencies are skipped.
NewConfig =
- case rebar_config:get_global(Config3, skip_deps, false) of
+ case rebar_config:get_global(Config4, skip_deps, false) of
"true" ->
lists:foldl(
fun(#dep{dir = Dir}, C) ->
rebar_config:set_skip_dir(C, Dir)
- end, Config3, AvailableDeps);
+ end, Config4, AvailableDeps);
Apps when is_list(Apps) ->
SkipApps = [list_to_atom(App) ||
App <- string:tokens(Apps, ",")],
@@ -112,9 +115,9 @@ preprocess(Config, _) ->
true -> rebar_config:set_skip_dir(C, Dir);
false -> C
end
- end, Config3, AvailableDeps);
+ end, Config4, AvailableDeps);
_ ->
- Config3
+ Config4
end,
%% Return all the available dep directories for process
@@ -254,7 +257,9 @@ info_help(Description) ->
" ~p~n"
" ~p~n"
"Valid command line options:~n"
- " deps_dir=\"deps\" (override default or rebar.config deps_dir)~n",
+ " deps_dir=\"deps\" (override default or rebar.config deps_dir)~n"
+ "Environment variables:~n"
+ " REBAR_DEPS_PREFER_LIBS to look for dependecies in system libs prior fetching.~n",
[
Description,
{deps_dir, "deps"},
@@ -302,6 +307,18 @@ set_shared_deps_dir(Config, _DepsDir) ->
get_shared_deps_dir(Config, Default) ->
rebar_config:get_xconf(Config, deps_dir, Default).
+set_deps_prefer_libs(Config, undefined) ->
+ DepsPreferLibs = case os:getenv("REBAR_DEPS_PREFER_LIBS") of
+ false -> false;
+ _ -> true
+ end,
+ rebar_config:set_xconf(Config, deps_prefer_libs, DepsPreferLibs);
+set_deps_prefer_libs(Config, _DepsPreferLibs) ->
+ Config.
+
+get_deps_prefer_libs(Config, Default) ->
+ rebar_config:get_xconf(Config, deps_prefer_libs, Default).
+
get_deps_dir(Config) ->
get_deps_dir(Config, "").
@@ -378,9 +395,15 @@ find_dep(Config, Dep) ->
%% e.g. {git, "https://github.com/mochi/mochiweb.git", "HEAD"}
%% Deps with a source must be found (or fetched) locally.
%% Those without a source may be satisfied from lib dir (get_lib_dir).
- find_dep(Config, Dep, Dep#dep.source).
-
-find_dep(Config, Dep, undefined) ->
+ DepsPreferLibs = get_deps_prefer_libs(Config, false),
+ Mode = case {Dep#dep.source, DepsPreferLibs} of
+ {undefined, _DepsPreferLibs} -> maybe_in_lib;
+ {_DepSource, true} -> maybe_in_lib;
+ {_DepSource, false} -> local_only
+ end,
+ find_dep(Config, Dep, Mode).
+
+find_dep(Config, Dep, maybe_in_lib) ->
%% '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(Config, Dep#dep.app)) of
@@ -389,7 +412,7 @@ find_dep(Config, Dep, undefined) ->
{Config1, {missing, _}} ->
find_dep_in_dir(Config1, Dep, get_lib_dir(Dep#dep.app))
end;
-find_dep(Config, Dep, _Source) ->
+find_dep(Config, Dep, local_only) ->
%% _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
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 64595a2..c3ebfe5 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -67,7 +67,9 @@
processing_base_dir/1,
processing_base_dir/2,
patch_env/2,
- cleanup_code_path/1
+ cleanup_code_path/1,
+ init_vsn_cache/1,
+ save_vsn_cache/1
]).
%% for internal use only
@@ -268,6 +270,23 @@ expand_env_variable(InStr, VarName, RawVarValue) ->
re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts)
end.
+init_vsn_cache(Config) ->
+ init_vsn_cache(Config, os:getenv("REBAR_VSN_CACHE_FILE")).
+init_vsn_cache(Config, false) ->
+ rebar_config:set_xconf(Config, vsn_cache, dict:new());
+init_vsn_cache(Config, CacheFile) ->
+ {ok, CacheList} = file:consult(CacheFile),
+ CacheDict = dict:from_list(CacheList),
+ rebar_config:set_xconf(Config, vsn_cache, CacheDict).
+
+save_vsn_cache(Config) ->
+ save_vsn_cache(Config, os:getenv("REBAR_VSN_CACHE_FILE")).
+save_vsn_cache(_Config, false) ->
+ ok;
+save_vsn_cache(Config, CacheFile) ->
+ file:write_file(CacheFile,
+ [io_lib:format("~p.~n", [X]) || X <- dict:to_list(rebar_config:get_xconf(Config, vsn_cache))]).
+
vcs_vsn(Config, Vsn, Dir) ->
Key = {Vsn, Dir},
Cache = rebar_config:get_xconf(Config, vsn_cache),
@@ -276,6 +295,7 @@ vcs_vsn(Config, Vsn, Dir) ->
VsnString = vcs_vsn_1(Vsn, Dir),
Cache1 = dict:store(Key, VsnString, Cache),
Config1 = rebar_config:set_xconf(Config, vsn_cache, Cache1),
+ save_vsn_cache(Config1),
{Config1, VsnString};
{ok, VsnString} ->
{Config, VsnString}
@@ -760,7 +780,7 @@ cross_sizeof(Arch, Type) ->
>>),
Cmd = Compiler ++ " -DTYPE=\""++Type++"\" " ++ TempFile,
ShOpts = [{use_stdout, false}, return_on_error],
- {ok, Res} = sh(Cmd, ShOpts),
+ {error, {_,Res}} = sh(Cmd, ShOpts),
ok = file:delete(TempFile),
case string:tokens(Res, ":") of
[_, Ln | _] ->