|
@ -191,42 +191,6 @@ processing_base_dir(State, Dir) -> |
|
|
AbsDir = filename:absname(Dir), |
|
|
AbsDir = filename:absname(Dir), |
|
|
AbsDir =:= rebar_state:get(State, base_dir). |
|
|
AbsDir =:= rebar_state:get(State, base_dir). |
|
|
|
|
|
|
|
|
%% @doc make a path absolute |
|
|
|
|
|
-spec make_absolute_path(file:filename()) -> file:filename(). |
|
|
|
|
|
make_absolute_path(Path) -> |
|
|
|
|
|
case filename:pathtype(Path) of |
|
|
|
|
|
absolute -> |
|
|
|
|
|
Path; |
|
|
|
|
|
relative -> |
|
|
|
|
|
{ok, Dir} = file:get_cwd(), |
|
|
|
|
|
filename:join([Dir, Path]); |
|
|
|
|
|
volumerelative -> |
|
|
|
|
|
Volume = hd(filename:split(Path)), |
|
|
|
|
|
{ok, Dir} = file:get_cwd(Volume), |
|
|
|
|
|
filename:join([Dir, Path]) |
|
|
|
|
|
end. |
|
|
|
|
|
|
|
|
|
|
|
%% @doc normalizing a path removes all of the `..' and the |
|
|
|
|
|
%% `.' segments it may contain. |
|
|
|
|
|
-spec make_normalized_path(file:filename()) -> file:filename(). |
|
|
|
|
|
make_normalized_path(Path) -> |
|
|
|
|
|
AbsPath = make_absolute_path(Path), |
|
|
|
|
|
Components = filename:split(AbsPath), |
|
|
|
|
|
make_normalized_path(Components, []). |
|
|
|
|
|
|
|
|
|
|
|
%% @private drops path fragments for normalization |
|
|
|
|
|
-spec make_normalized_path([string()], [string()]) -> file:filename(). |
|
|
|
|
|
make_normalized_path([], NormalizedPath) -> |
|
|
|
|
|
filename:join(lists:reverse(NormalizedPath)); |
|
|
|
|
|
make_normalized_path([H|T], NormalizedPath) -> |
|
|
|
|
|
case H of |
|
|
|
|
|
"." when NormalizedPath == [], T == [] -> make_normalized_path(T, ["."]); |
|
|
|
|
|
"." -> make_normalized_path(T, NormalizedPath); |
|
|
|
|
|
".." when NormalizedPath == [] -> make_normalized_path(T, [".."]); |
|
|
|
|
|
".." when hd(NormalizedPath) =/= ".." -> make_normalized_path(T, tl(NormalizedPath)); |
|
|
|
|
|
_ -> make_normalized_path(T, [H|NormalizedPath]) |
|
|
|
|
|
end. |
|
|
|
|
|
|
|
|
|
|
|
%% @doc take a source and a target path, and relativize the target path |
|
|
%% @doc take a source and a target path, and relativize the target path |
|
|
%% onto the source. |
|
|
%% onto the source. |
|
|
%% |
|
|
%% |
|
@ -239,8 +203,8 @@ make_normalized_path([H|T], NormalizedPath) -> |
|
|
%% ''' |
|
|
%% ''' |
|
|
-spec make_relative_path(file:filename(), file:filename()) -> file:filename(). |
|
|
-spec make_relative_path(file:filename(), file:filename()) -> file:filename(). |
|
|
make_relative_path(Source, Target) -> |
|
|
make_relative_path(Source, Target) -> |
|
|
AbsSource = make_normalized_path(Source), |
|
|
|
|
|
AbsTarget = make_normalized_path(Target), |
|
|
|
|
|
|
|
|
AbsSource = rebar_file_utils:normalized_path(Source), |
|
|
|
|
|
AbsTarget = rebar_file_utils:normalized_path(Target), |
|
|
do_make_relative_path(filename:split(AbsSource), filename:split(AbsTarget)). |
|
|
do_make_relative_path(filename:split(AbsSource), filename:split(AbsTarget)). |
|
|
|
|
|
|
|
|
%% @private based on fragments of paths, replace the number of common |
|
|
%% @private based on fragments of paths, replace the number of common |
|
@ -285,8 +249,8 @@ extra_src_dirs(Opts, Default) -> |
|
|
src_dirs(Type, Opts, Default) -> |
|
|
src_dirs(Type, Opts, Default) -> |
|
|
lists:usort([ |
|
|
lists:usort([ |
|
|
case D0 of |
|
|
case D0 of |
|
|
{D,_} -> normalize_relative_path(D); |
|
|
|
|
|
_ -> normalize_relative_path(D0) |
|
|
|
|
|
|
|
|
{D,_} -> rebar_file_utils:normalize_relative_path(D); |
|
|
|
|
|
_ -> rebar_file_utils:normalize_relative_path(D0) |
|
|
end || D0 <- raw_src_dirs(Type,Opts,Default)]). |
|
|
end || D0 <- raw_src_dirs(Type,Opts,Default)]). |
|
|
|
|
|
|
|
|
%% @private extracts the un-formatted src_dirs or extra_src_dirs |
|
|
%% @private extracts the un-formatted src_dirs or extra_src_dirs |
|
@ -299,10 +263,6 @@ raw_src_dirs(Type, Opts, Default) -> |
|
|
Dirs -> Dirs |
|
|
Dirs -> Dirs |
|
|
end. |
|
|
end. |
|
|
|
|
|
|
|
|
%% @private normalizes relative paths so that ./a/b/c/ => a/b/c |
|
|
|
|
|
normalize_relative_path(Path) -> |
|
|
|
|
|
make_normalized_path(filename:split(Path), []). |
|
|
|
|
|
|
|
|
|
|
|
%% @doc returns all the source directories (`src_dirs' and |
|
|
%% @doc returns all the source directories (`src_dirs' and |
|
|
%% `extra_src_dirs'). |
|
|
%% `extra_src_dirs'). |
|
|
-spec all_src_dirs(rebar_dict()) -> list(file:filename_all()). |
|
|
-spec all_src_dirs(rebar_dict()) -> list(file:filename_all()). |
|
|