浏览代码

Merge pull request #2074 from tsloughter/git-ref

add support for git ref and file content as app version
pull/2083/head
Fred Hebert 6 年前
提交者 GitHub
父节点
当前提交
3a16cf3763
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 3 个文件被更改,包括 36 次插入5 次删除
  1. +26
    -2
      src/rebar_git_resource.erl
  2. +2
    -1
      src/rebar_resource_v2.erl
  3. +8
    -2
      src/rebar_utils.erl

+ 26
- 2
src/rebar_git_resource.erl 查看文件

@ -236,7 +236,17 @@ git_vsn_fetch() ->
end.
make_vsn(AppInfo, _) ->
make_vsn_(rebar_app_info:dir(AppInfo)).
Dir = rebar_app_info:dir(AppInfo),
case rebar_app_info:original_vsn(AppInfo) of
{git, short} ->
git_ref(Dir, "--short");
{git, long} ->
git_ref(Dir, "");
_ ->
%% already parsed in rebar_utils to get here so we know it
%% is either for git or "git"
make_vsn_(Dir)
end.
make_vsn_(Dir) ->
case collect_default_refcount(Dir) of
@ -248,6 +258,19 @@ make_vsn_(Dir) ->
%% Internal functions
git_ref(Dir, Arg) ->
case rebar_utils:sh("git rev-parse " ++ Arg ++ " HEAD",
[{use_stdout, false},
return_on_error,
{cd, Dir}]) of
{error, _} ->
?WARN("Getting ref of git repo failed in ~ts. "
"Falling back to version 0", [Dir]),
{plain, "0"};
{ok, String} ->
{plain, rebar_string:trim(String, both, "\n")}
end.
collect_default_refcount(Dir) ->
%% Get the tag timestamp and minimal ref from the system. The
%% timestamp is really important from an ordering perspective.
@ -256,7 +279,8 @@ collect_default_refcount(Dir) ->
return_on_error,
{cd, Dir}]) of
{error, _} ->
?WARN("Getting log of git dependency failed in ~ts. Falling back to version 0.0.0", [rebar_dir:get_cwd()]),
?WARN("Getting log of git repo failed in ~ts. "
"Falling back to version 0.0.0", [Dir]),
{plain, "0.0.0"};
{ok, String} ->
RawRef = rebar_string:trim(String, both, "\n"),

+ 2
- 1
src/rebar_resource_v2.erl 查看文件

@ -101,7 +101,8 @@ needs_update(AppInfo, State) ->
resource_run(needs_update, rebar_app_info:source(AppInfo), [AppInfo], State).
%% this is a special case since it is used for project apps as well, not just deps
make_vsn(AppInfo, VcsType, State) ->
make_vsn(AppInfo, Vsn, State) ->
VcsType = case Vsn of {T, _} -> T; T -> T end,
Resources = rebar_state:resources(State),
case is_resource_type(VcsType, Resources) of
true ->

+ 8
- 2
src/rebar_utils.erl 查看文件

@ -729,7 +729,7 @@ vcs_vsn(AppInfo, Vcs, State) ->
{plain, VsnString} ->
VsnString;
{cmd, CmdString} ->
vcs_vsn_invoke(CmdString, rebar_app_info:dir(AppInfo));
cmd_vsn_invoke(CmdString, rebar_app_info:dir(AppInfo));
unknown ->
?ABORT("vcs_vsn: Unknown vsn format: ~p", [Vcs]);
{error, Reason} ->
@ -743,8 +743,14 @@ vcs_vsn_cmd(AppInfo, VCS, State) when VCS =:= semver ; VCS =:= "semver" ->
vcs_vsn_cmd(AppInfo, git, State);
vcs_vsn_cmd(_AppInfo, {cmd, _Cmd}=Custom, _) ->
Custom;
vcs_vsn_cmd(AppInfo, {file, File}, _) ->
Path = filename:join(rebar_app_info:dir(AppInfo), File),
{ok, Vsn} = file:read_file(Path),
{plain, to_list(rebar_string:trim(Vsn))};
vcs_vsn_cmd(AppInfo, VCS, State) when is_atom(VCS) ->
rebar_resource_v2:make_vsn(AppInfo, VCS, State);
vcs_vsn_cmd(AppInfo, {VCS, _}=V, State) when is_atom(VCS) ->
rebar_resource_v2:make_vsn(AppInfo, V, State);
vcs_vsn_cmd(AppInfo, VCS, State) when is_list(VCS) ->
try list_to_existing_atom(VCS) of
AVCS ->
@ -759,7 +765,7 @@ vcs_vsn_cmd(AppInfo, VCS, State) when is_list(VCS) ->
vcs_vsn_cmd(_, _, _) ->
unknown.
vcs_vsn_invoke(Cmd, Dir) ->
cmd_vsn_invoke(Cmd, Dir) ->
{ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
rebar_string:trim(VsnString, trailing, "\n").

正在加载...
取消
保存