Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

102 рядки
3.9 KiB

15 роки тому
15 роки тому
14 роки тому
14 роки тому
  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_app_utils).
  28. -export([find/2,
  29. find/3,
  30. is_app_src/1,
  31. app_src_to_app/2,
  32. validate_application_info/1,
  33. validate_application_info/2,
  34. format_error/1]).
  35. -include("rebar.hrl").
  36. -include_lib("providers/include/providers.hrl").
  37. %% ===================================================================
  38. %% Public API
  39. %% ===================================================================
  40. -spec find(binary(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error.
  41. find(Name, Apps) ->
  42. ec_lists:find(fun(App) -> rebar_app_info:name(App) =:= Name end, Apps).
  43. -spec find(binary(), binary(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error.
  44. find(Name, Vsn, Apps) ->
  45. ec_lists:find(fun(App) ->
  46. rebar_app_info:name(App) =:= Name
  47. andalso rebar_app_info:original_vsn(App) =:= Vsn
  48. end, Apps).
  49. is_app_src(Filename) ->
  50. %% If removing the extension .app.src yields a shorter name,
  51. %% this is an .app.src file.
  52. Filename =/= filename:rootname(Filename, ".app.src").
  53. app_src_to_app(OutDir, Filename) ->
  54. AppFile = filename:join([OutDir, "ebin", filename:basename(Filename, ".app.src") ++ ".app"]),
  55. filelib:ensure_dir(AppFile),
  56. AppFile.
  57. -spec validate_application_info(rebar_app_info:t()) -> boolean().
  58. validate_application_info(AppInfo) ->
  59. validate_application_info(AppInfo, rebar_app_info:app_details(AppInfo)).
  60. validate_application_info(AppInfo, AppDetail) ->
  61. EbinDir = rebar_app_info:ebin_dir(AppInfo),
  62. case rebar_app_info:app_file(AppInfo) of
  63. undefined ->
  64. false;
  65. AppFile ->
  66. case proplists:get_value(modules, AppDetail) of
  67. undefined ->
  68. ?PRV_ERROR({module_list, AppFile});
  69. List ->
  70. has_all_beams(EbinDir, List)
  71. end
  72. end.
  73. format_error(Error) ->
  74. io_lib:format("~p", [Error]).
  75. %% ===================================================================
  76. %% Internal functions
  77. %% ===================================================================
  78. -spec has_all_beams(file:filename_all(), list()) -> true | providers:error().
  79. has_all_beams(EbinDir, [Module | ModuleList]) ->
  80. BeamFile = filename:join([EbinDir,
  81. ec_cnv:to_list(Module) ++ ".beam"]),
  82. case filelib:is_file(BeamFile) of
  83. true ->
  84. has_all_beams(EbinDir, ModuleList);
  85. false ->
  86. ?PRV_ERROR({missing_module, Module})
  87. end;
  88. has_all_beams(_, []) ->
  89. true.