diff options
| author | Fred Hebert <mononcqc@ferd.ca> | 2019-05-12 19:17:22 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-12 19:17:22 -0400 | 
| commit | 3a16cf3763c198e9167ec11a146e25334adc82f5 (patch) | |
| tree | 034492a364d91c64b142f2d2d7ecf56801fdb83a /src | |
| parent | cbe3292b52802a8ef7b39a40287d1cd8019f46a1 (diff) | |
| parent | 67026e08916578a03ae5637284ad5eb6818a3c7f (diff) | |
Merge pull request #2074 from tsloughter/git-ref
add support for git ref and file content as app version
Diffstat (limited to 'src')
| -rw-r--r-- | src/rebar_git_resource.erl | 28 | ||||
| -rw-r--r-- | src/rebar_resource_v2.erl | 3 | ||||
| -rw-r--r-- | src/rebar_utils.erl | 10 | 
3 files changed, 36 insertions, 5 deletions
| diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index ac1316b..4e81c05 100644 --- a/src/rebar_git_resource.erl +++ b/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"), diff --git a/src/rebar_resource_v2.erl b/src/rebar_resource_v2.erl index b7ee760..537b5f0 100644 --- a/src/rebar_resource_v2.erl +++ b/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 -> diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index f1e440a..c920e46 100644 --- a/src/rebar_utils.erl +++ b/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"). | 
