Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

87 rader
3.3 KiB

15 år sedan
15 år sedan
15 år sedan
15 år sedan
  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. %% -------------------------------------------------------------------
  4. %%
  5. %% rebar: Erlang Build Tools
  6. %%
  7. %% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com)
  8. %%
  9. %% Permission is hereby granted, free of charge, to any person obtaining a copy
  10. %% of this software and associated documentation files (the "Software"), to deal
  11. %% in the Software without restriction, including without limitation the rights
  12. %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. %% copies of the Software, and to permit persons to whom the Software is
  14. %% furnished to do so, subject to the following conditions:
  15. %%
  16. %% The above copyright notice and this permission notice shall be included in
  17. %% all copies or substantial portions of the Software.
  18. %%
  19. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. %% THE SOFTWARE.
  26. %% -------------------------------------------------------------------
  27. -module(rebar_rel_utils).
  28. -export([is_rel_dir/0,
  29. is_rel_dir/1,
  30. get_reltool_release_info/1,
  31. get_rel_release_info/1,
  32. get_rel_release_info/2,
  33. get_previous_release_path/0]).
  34. -include("rebar.hrl").
  35. is_rel_dir() ->
  36. is_rel_dir(rebar_utils:get_cwd()).
  37. is_rel_dir(Dir) ->
  38. Fname = filename:join([Dir, "reltool.config"]),
  39. case filelib:is_regular(Fname) of
  40. true ->
  41. {true, Fname};
  42. false ->
  43. false
  44. end.
  45. %% Get release name and version from a reltool.config
  46. get_reltool_release_info(ReltoolFile) ->
  47. %% expect sys to be the first proplist in reltool.config
  48. case file:consult(ReltoolFile) of
  49. {ok, [{sys, Config}| _]} ->
  50. %% expect the first rel in the proplist to be the one you want
  51. {rel, Name, Ver, _} = proplists:lookup(rel, Config),
  52. {Name, Ver};
  53. _ ->
  54. ?ABORT("Failed to parse ~s~n", [ReltoolFile])
  55. end.
  56. %% Get release name and version from a rel file
  57. get_rel_release_info(RelFile) ->
  58. case file:consult(RelFile) of
  59. {ok, [{release, {Name, Ver}, _, _}]} ->
  60. {Name, Ver};
  61. _ ->
  62. ?ABORT("Failed to parse ~s~n", [RelFile])
  63. end.
  64. %% Get release name and version from a name and a path
  65. get_rel_release_info(Name, Path) ->
  66. [RelFile] = filelib:wildcard(filename:join([Path, "releases", "*",
  67. Name ++ ".rel"])),
  68. [BinDir|_] = re:replace(RelFile, Name ++ "\\.rel", ""),
  69. get_rel_release_info(filename:join([binary_to_list(BinDir),
  70. Name ++ ".rel"])).
  71. %% Get the previous release path from a global variable
  72. get_previous_release_path() ->
  73. case rebar_config:get_global(previous_release, false) of
  74. false ->
  75. ?ABORT("previous_release=PATH is required to "
  76. "create upgrade package~n", []);
  77. OldVerPath ->
  78. OldVerPath
  79. end.