Преглед изворни кода

verify checked out dep is the same as specified in the config and update if not

pull/3/head
Tristan Sloughter пре 10 година
родитељ
комит
35d1afd2f6
5 измењених фајлова са 79 додато и 12 уклоњено
  1. +17
    -3
      src/rebar_fetch.erl
  2. +36
    -1
      src/rebar_git_resource.erl
  3. +21
    -6
      src/rebar_prv_install_deps.erl
  4. +4
    -1
      src/rebar_resource.erl
  5. +1
    -1
      src/rebar_utils.erl

+ 17
- 3
src/rebar_fetch.erl Прегледај датотеку

@ -8,7 +8,8 @@
-module(rebar_fetch).
-export([lock_source/2,
download_source/2]).
download_source/2,
needs_update/2]).
-include("rebar.hrl").
@ -36,6 +37,8 @@ download_source(AppDir, Source) ->
ec_file:mkdir_p(AppDir1),
case Module:download(TmpDir, Source) of
{ok, _} ->
code:del_path(filename:absname(filename:join(AppDir1, "ebin"))),
ec_file:remove(filename:absname(AppDir1), [recursive]),
ok = ec_file:copy(TmpDir, filename:absname(AppDir1), [recursive]),
true;
{tarball, File} ->
@ -43,17 +46,28 @@ download_source(AppDir, Source) ->
,compressed]),
BaseName = filename:basename(AppDir1),
[FromDir] = filelib:wildcard(filename:join(TmpDir, BaseName++"-*")),
ok = ec_file:copy(FromDir, AppDir1, [recursive]),
code:del_path(filename:absname(filename:join(AppDir1, "ebin"))),
ec_file:remove(filename:absname(AppDir1), [recursive]),
ok = ec_file:copy(FromDir, filename:absname(AppDir1), [recursive]),
true
end
end.
-spec needs_update(file:filename_all(), rebar_resource:resource()) -> boolean() | {error, string()}.
needs_update(AppDir, Source) ->
case get_resource_type(Source) of
{error, _}=Error ->
Error;
Module ->
Module:needs_update(AppDir, Source)
end.
get_resource_type({Type, Location, _}) ->
case lists:keyfind(Type, 1, ?RESOURCES) of
false ->
case code:which(Type) of
non_existing ->
{error, io_lib:format("Cannot fetch dependency ~s.~n"
{error, io_lib:format("Cannot handle dependency ~s.~n"
" No module for resource type ~p", [Location, Type])};
_ ->
Type

+ 36
- 1
src/rebar_git_resource.erl Прегледај датотеку

@ -5,7 +5,8 @@
-behaviour(rebar_resource).
-export([lock/2
,download/2]).
,download/2
,needs_update/2]).
-include("rebar.hrl").
@ -15,6 +16,40 @@ lock(AppDir, {git, Url, _}) ->
,both, $\n),
{git, Url, {ref, Ref}}.
needs_update(Dir, {git, Url, {tag, Tag}}) ->
{ok, CurrentUrl} = rebar_utils:sh(?FMT("git config --get remote.origin.url", []),
[{cd, Dir}]),
{ok, Current} = rebar_utils:sh(?FMT("git describe --tags --exact-match", []),
[{cd, Dir}]),
Current1 = string:strip(string:strip(Current, both, $\n), both, $\r),
CurrentUrl1 = string:strip(string:strip(CurrentUrl, both, $\n), both, $\r),
?DEBUG("Comparing git tag ~s with ~s and url ~s with ~s~n", [Tag, Current1, Url, CurrentUrl1]),
not ((Current1 =:= Tag) andalso (CurrentUrl1 =:= Url));
needs_update(Dir, {git, Url, {branch, Branch}}) ->
{ok, CurrentUrl} = rebar_utils:sh(?FMT("git config --get remote.origin.url", []),
[{cd, Dir}]),
{ok, Current} = rebar_utils:sh(?FMT("git symbolic-ref -q --short HEAD", []),
[{cd, Dir}]),
Current1 = string:strip(string:strip(Current, both, $\n), both, $\r),
CurrentUrl1 = string:strip(string:strip(CurrentUrl, both, $\n), both, $\r),
?DEBUG("Comparing git branch ~s with ~s and url ~s with ~s~n", [Branch, Current1, Url, CurrentUrl1]),
not ((Current1 =:= Branch) andalso (CurrentUrl1 =:= Url));
needs_update(Dir, {git, Url, Ref}) ->
case Ref of
{ref, Ref1} ->
Ref1;
Ref1 ->
Ref1
end,
{ok, CurrentUrl} = rebar_utils:sh(?FMT("git config --get remote.origin.url", []),
[{cd, Dir}]),
{ok, Current} = rebar_utils:sh(?FMT("git rev-parse -q HEAD", []),
[{cd, Dir}]),
Current1 = string:strip(string:strip(Current, both, $\n), both, $\r),
CurrentUrl1 = string:strip(string:strip(CurrentUrl, both, $\n), both, $\r),
?DEBUG("Comparing git ref ~s with ~s and url ~s with ~s~n", [Ref1, Current1, Url, CurrentUrl1]),
not ((Current1 =:= Ref1) andalso (CurrentUrl1 =:= Url)).
download(Dir, {git, Url}) ->
?WARN("WARNING: It is recommended to use {branch, Name}, {tag, Tag} or {ref, Ref}, otherwise updating the dep may not work as expected.~n", []),
download(Dir, {git, Url, {branch, "HEAD"}});

+ 21
- 6
src/rebar_prv_install_deps.erl Прегледај датотеку

@ -86,7 +86,7 @@ do(State) ->
end
catch
_:Reason ->
Reason
{error, Reason}
end.
-spec format_error(any(), rebar_state:t()) -> {iolist(), rebar_state:t()}.
@ -267,15 +267,30 @@ maybe_fetch(AppInfo, Update, Seen) ->
?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]),
Source = rebar_app_info:source(AppInfo),
case rebar_fetch:download_source(AppDir, Source) of
{error, _}=Error ->
throw(Error);
{error, Reason} ->
throw(Reason);
Result ->
Result
end;
_ ->
io:format("Was ~p seen: ~p~n", [rebar_app_info:name(AppInfo)
,sets:is_element(rebar_app_info:name(AppInfo), Seen)]),
false
case sets:is_element(rebar_app_info:name(AppInfo), Seen) of
true ->
false;
false ->
Source = rebar_app_info:source(AppInfo),
case rebar_fetch:needs_update(AppDir, Source) of
true ->
?INFO("Updating ~s~n", [rebar_app_info:name(AppInfo)]),
case rebar_fetch:download_source(AppDir, Source) of
{error, Reason} ->
throw(Reason);
Result ->
Result
end;
false ->
false
end
end
end
end.

+ 4
- 1
src/rebar_resource.erl Прегледај датотеку

@ -23,7 +23,8 @@
-spec behaviour_info(atom()) -> [{atom(), arity()}] | undefined.
behaviour_info(callbacks) ->
[{lock, 2},
{download, 2}];
{download, 2},
{needs_update,2}];
behaviour_info(_) ->
undefined.
@ -32,5 +33,7 @@ behaviour_info(_) ->
-callback lock(file:filename_all(), tuple()) -> rebar_resource:resource().
-callback download(file:filename_all(), tuple()) ->
{tarball, file:filename_all()} | {ok, any()} | {error, any()}.
-callback needs_update(file:filename_all(), tuple()) ->
{tarball, file:filename_all()} | {ok, any()} | {error, any()}.
-endif.

+ 1
- 1
src/rebar_utils.erl Прегледај датотеку

@ -135,7 +135,7 @@ sh(Command0, Options0) ->
?DEBUG("sh info:\n\tcwd: ~p\n\tcmd: ~s\n", [get_cwd(), Command0]),
?DEBUG("\topts: ~p\n", [Options0]),
DefaultOptions = [use_stdout, abort_on_error],
DefaultOptions = [{use_stdout, false}, abort_on_error],
Options = [expand_sh_flag(V)
|| V <- proplists:compact(Options0 ++ DefaultOptions)],

Loading…
Откажи
Сачувај