|
|
@ -26,21 +26,8 @@ |
|
|
|
%% ------------------------------------------------------------------- |
|
|
|
-module(rebar_utils). |
|
|
|
|
|
|
|
-export([base_dir/1, |
|
|
|
deps_dir/1, |
|
|
|
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, |
|
|
|
|
|
|
|
droplast/1, |
|
|
|
-export([droplast/1, |
|
|
|
filtermap/2, |
|
|
|
get_cwd/0, |
|
|
|
is_arch/1, |
|
|
|
sh/2, |
|
|
|
sh_send/3, |
|
|
@ -49,7 +36,6 @@ |
|
|
|
escript_foldl/3, |
|
|
|
find_files/2, |
|
|
|
find_files/3, |
|
|
|
ensure_dir/1, |
|
|
|
beam_to_mod/1, |
|
|
|
beam_to_mod/2, |
|
|
|
erl_to_mod/1, |
|
|
@ -61,10 +47,6 @@ |
|
|
|
deprecated/4, |
|
|
|
delayed_halt/1, |
|
|
|
erl_opts/1, |
|
|
|
src_dirs/1, |
|
|
|
ebin_dir/0, |
|
|
|
processing_base_dir/1, |
|
|
|
processing_base_dir/2, |
|
|
|
indent/1, |
|
|
|
cleanup_code_path/1]). |
|
|
|
|
|
|
@ -79,63 +61,9 @@ |
|
|
|
%% Public API |
|
|
|
%% ==================================================================== |
|
|
|
|
|
|
|
-spec base_dir(rebar_state:t()) -> file:filename_all(). |
|
|
|
base_dir(State) -> |
|
|
|
rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR). |
|
|
|
|
|
|
|
-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). |
|
|
|
|
|
|
|
-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)). |
|
|
|
|
|
|
|
-spec lib_dirs(rebar_state:t()) -> file:filename_all(). |
|
|
|
lib_dirs(State) -> |
|
|
|
rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_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. |
|
|
|
|
|
|
|
global_config_dir(State) -> |
|
|
|
Home = home_dir(), |
|
|
|
rebar_state:get(State, global_rebar_dir, filename:join(Home, ?CONFIG_DIR)). |
|
|
|
|
|
|
|
droplast(L) -> |
|
|
|
lists:reverse(tl(lists:reverse(L))). |
|
|
|
|
|
|
|
get_cwd() -> |
|
|
|
{ok, Dir} = file:get_cwd(), |
|
|
|
Dir. |
|
|
|
|
|
|
|
filtermap(F, [Hd|Tail]) -> |
|
|
|
case F(Hd) of |
|
|
|
true -> |
|
|
@ -171,7 +99,7 @@ wordsize() -> |
|
|
|
|
|
|
|
sh_send(Command0, String, Options0) -> |
|
|
|
?INFO("sh_send info:\n\tcwd: ~p\n\tcmd: ~s < ~s\n", |
|
|
|
[get_cwd(), Command0, String]), |
|
|
|
[rebar_dir:get_cwd(), Command0, String]), |
|
|
|
?DEBUG("\topts: ~p\n", [Options0]), |
|
|
|
|
|
|
|
DefaultOptions = [use_stdout, abort_on_error], |
|
|
@ -197,7 +125,7 @@ sh_send(Command0, String, Options0) -> |
|
|
|
%% Val = string() | false |
|
|
|
%% |
|
|
|
sh(Command0, Options0) -> |
|
|
|
?DEBUG("sh info:\n\tcwd: ~p\n\tcmd: ~s\n", [get_cwd(), Command0]), |
|
|
|
?DEBUG("sh info:\n\tcwd: ~p\n\tcmd: ~s\n", [rebar_dir:get_cwd(), Command0]), |
|
|
|
?DEBUG("\topts: ~p\n", [Options0]), |
|
|
|
|
|
|
|
DefaultOptions = [{use_stdout, false}, debug_and_abort_on_error], |
|
|
@ -227,18 +155,6 @@ find_files(Dir, Regex, Recursive) -> |
|
|
|
filelib:fold_files(Dir, Regex, Recursive, |
|
|
|
fun(F, Acc) -> [F | Acc] end, []). |
|
|
|
|
|
|
|
%% TODO: filelib:ensure_dir/1 corrected in R13B04. Remove when we drop |
|
|
|
%% support for OTP releases older than R13B04. |
|
|
|
ensure_dir(Path) -> |
|
|
|
case filelib:ensure_dir(Path) of |
|
|
|
ok -> |
|
|
|
ok; |
|
|
|
{error,eexist} -> |
|
|
|
ok; |
|
|
|
Error -> |
|
|
|
Error |
|
|
|
end. |
|
|
|
|
|
|
|
find_executable(Name) -> |
|
|
|
case os:find_executable(Name) of |
|
|
|
false -> false; |
|
|
@ -324,23 +240,6 @@ erl_opts(Config) -> |
|
|
|
[debug_info|Opts] |
|
|
|
end. |
|
|
|
|
|
|
|
-spec src_dirs([string()]) -> [file:filename(), ...]. |
|
|
|
src_dirs([]) -> |
|
|
|
["src"]; |
|
|
|
src_dirs(SrcDirs) -> |
|
|
|
SrcDirs. |
|
|
|
|
|
|
|
ebin_dir() -> |
|
|
|
filename:join(get_cwd(), "ebin"). |
|
|
|
|
|
|
|
processing_base_dir(State) -> |
|
|
|
Cwd = rebar_utils:get_cwd(), |
|
|
|
processing_base_dir(State, Cwd). |
|
|
|
|
|
|
|
processing_base_dir(State, Dir) -> |
|
|
|
AbsDir = filename:absname(Dir), |
|
|
|
AbsDir =:= rebar_state:get(State, base_dir). |
|
|
|
|
|
|
|
%% ==================================================================== |
|
|
|
%% Internal functions |
|
|
|
%% ==================================================================== |
|
|
|