25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

238 satır
7.1 KiB

10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
  1. -module(rebar_app_info).
  2. -export([new/1,
  3. new/2,
  4. new/3,
  5. new/4,
  6. discover/1,
  7. name/1,
  8. name/2,
  9. config/1,
  10. config/2,
  11. app_file_src/1,
  12. app_file_src/2,
  13. app_file/1,
  14. app_file/2,
  15. app_details/1,
  16. app_details/2,
  17. original_vsn/1,
  18. original_vsn/2,
  19. ebin_dir/1,
  20. applications/1,
  21. applications/2,
  22. profiles/1,
  23. profiles/2,
  24. deps/1,
  25. deps/2,
  26. dep_level/1,
  27. dep_level/2,
  28. dir/1,
  29. dir/2,
  30. source/1,
  31. source/2,
  32. state/1,
  33. state/2,
  34. valid/1,
  35. valid/2]).
  36. -export_type([t/0]).
  37. -record(app_info_t, {name :: binary(),
  38. app_file_src :: file:filename_all() | undefined,
  39. app_file :: file:filename_all() | undefined,
  40. config :: rebar_state:t() | undefined,
  41. original_vsn :: binary() | string() | undefined,
  42. app_details=[] :: list(),
  43. applications=[] :: list(),
  44. deps=[] :: list(),
  45. profiles=[default] :: atom(),
  46. dep_level=0 :: integer(),
  47. dir :: file:name(),
  48. source :: string() | tuple() | undefined,
  49. state :: rebar_state:t() | undefined,
  50. valid :: boolean()}).
  51. %%============================================================================
  52. %% types
  53. %%============================================================================
  54. -type t() :: record(app_info_t).
  55. %%============================================================================
  56. %% API
  57. %% ============================================================================
  58. %% @doc Build a new, empty, app info value. This is not of a lot of use and you
  59. %% probably wont be doing this much.
  60. -spec new(atom() | binary() | string()) ->
  61. {ok, t()}.
  62. new(AppName) ->
  63. {ok, #app_info_t{name=ec_cnv:to_binary(AppName)}}.
  64. -spec new(atom() | binary() | string(), binary() | string()) ->
  65. {ok, t()}.
  66. new(AppName, Vsn) ->
  67. {ok, #app_info_t{name=ec_cnv:to_binary(AppName),
  68. original_vsn=Vsn}}.
  69. %% @doc build a complete version of the app info with all fields set.
  70. -spec new(atom() | binary() | string(), binary() | string(), file:name()) ->
  71. {ok, t()}.
  72. new(AppName, Vsn, Dir) ->
  73. {ok, #app_info_t{name=ec_cnv:to_binary(AppName),
  74. original_vsn=Vsn,
  75. dir=Dir}}.
  76. %% @doc build a complete version of the app info with all fields set.
  77. -spec new(atom() | binary() | string(), binary() | string(), file:name(), list()) ->
  78. {ok, t()}.
  79. new(AppName, Vsn, Dir, Deps) ->
  80. {ok, #app_info_t{name=ec_cnv:to_binary(AppName),
  81. original_vsn=Vsn,
  82. dir=Dir,
  83. deps=Deps}}.
  84. %% @doc discover a complete version of the app info with all fields set.
  85. -spec discover(file:filename_all()) -> {ok, t()} | not_found.
  86. discover(Dir) ->
  87. case rebar_app_discover:find_app(Dir, all) of
  88. {true, AppInfo} ->
  89. {ok, AppInfo};
  90. false ->
  91. not_found
  92. end.
  93. -spec name(t()) -> binary().
  94. name(#app_info_t{name=Name}) ->
  95. Name.
  96. -spec name(t(), atom() | binary() | string()) -> t().
  97. name(AppInfo=#app_info_t{}, AppName) ->
  98. AppInfo#app_info_t{name=ec_cnv:to_binary(AppName)}.
  99. -spec config(t()) -> rebar_state:t().
  100. config(#app_info_t{config=Config}) ->
  101. Config.
  102. -spec config(t(), rebar_state:t()) -> t().
  103. config(AppInfo=#app_info_t{}, Config) ->
  104. AppInfo#app_info_t{config=Config}.
  105. -spec app_file_src(t()) -> file:filename_all() | undefined.
  106. app_file_src(#app_info_t{app_file_src=undefined, dir=Dir, name=Name}) ->
  107. AppFileSrc = filename:join([ec_cnv:to_list(Dir), "src", ec_cnv:to_list(Name)++".app.src"]),
  108. case filelib:is_file(AppFileSrc) of
  109. true ->
  110. AppFileSrc;
  111. false ->
  112. undefined
  113. end;
  114. app_file_src(#app_info_t{app_file_src=AppFileSrc}) ->
  115. ec_cnv:to_list(AppFileSrc).
  116. -spec app_file_src(t(), file:filename_all()) -> t().
  117. app_file_src(AppInfo=#app_info_t{}, AppFileSrc) ->
  118. AppInfo#app_info_t{app_file_src=ec_cnv:to_list(AppFileSrc)}.
  119. -spec app_file(t()) -> file:filename_all() | undefined.
  120. app_file(#app_info_t{app_file=undefined, dir=Dir, name=Name}) ->
  121. AppFile = filename:join([ec_cnv:to_list(Dir), "ebin", ec_cnv:to_list(Name)++".app"]),
  122. case filelib:is_file(AppFile) of
  123. true ->
  124. AppFile;
  125. false ->
  126. undefined
  127. end;
  128. app_file(#app_info_t{app_file=AppFile}) ->
  129. AppFile.
  130. -spec app_file(t(), file:filename_all()) -> t().
  131. app_file(AppInfo=#app_info_t{}, AppFile) ->
  132. AppInfo#app_info_t{app_file=AppFile}.
  133. -spec app_details(t()) -> list().
  134. app_details(#app_info_t{app_details=AppDetails}) ->
  135. AppDetails.
  136. -spec app_details(t(), list()) -> t().
  137. app_details(AppInfo=#app_info_t{}, AppDetails) ->
  138. AppInfo#app_info_t{app_details=AppDetails}.
  139. -spec original_vsn(t()) -> string().
  140. original_vsn(#app_info_t{original_vsn=Vsn}) ->
  141. Vsn.
  142. -spec original_vsn(t(), string()) -> t().
  143. original_vsn(AppInfo=#app_info_t{}, Vsn) ->
  144. AppInfo#app_info_t{original_vsn=Vsn}.
  145. -spec applications(t()) -> list().
  146. applications(#app_info_t{applications=Applications}) ->
  147. Applications.
  148. -spec applications(t(), list()) -> t().
  149. applications(AppInfo=#app_info_t{}, Applications) ->
  150. AppInfo#app_info_t{applications=Applications}.
  151. -spec profiles(t()) -> list().
  152. profiles(#app_info_t{profiles=Profiles}) ->
  153. Profiles.
  154. -spec profiles(t(), list()) -> t().
  155. profiles(AppInfo=#app_info_t{}, Profiles) ->
  156. AppInfo#app_info_t{profiles=Profiles}.
  157. -spec deps(t()) -> list().
  158. deps(#app_info_t{deps=Deps}) ->
  159. Deps.
  160. -spec deps(t(), list()) -> t().
  161. deps(AppInfo=#app_info_t{}, Deps) ->
  162. AppInfo#app_info_t{deps=Deps}.
  163. dep_level(AppInfo=#app_info_t{}, Level) ->
  164. AppInfo#app_info_t{dep_level=Level}.
  165. dep_level(#app_info_t{dep_level=Level}) ->
  166. Level.
  167. -spec dir(t()) -> file:name().
  168. dir(#app_info_t{dir=Dir}) ->
  169. Dir.
  170. -spec dir(t(), file:name()) -> t().
  171. dir(AppInfo=#app_info_t{}, Dir) ->
  172. AppInfo#app_info_t{dir=Dir}.
  173. -spec ebin_dir(t()) -> file:name().
  174. ebin_dir(#app_info_t{dir=Dir}) ->
  175. filename:join(Dir, "ebin").
  176. -spec source(t(), string() | tuple()) -> t().
  177. source(AppInfo=#app_info_t{}, Source) ->
  178. AppInfo#app_info_t{source=Source}.
  179. -spec source(t()) -> string() | tuple().
  180. source(#app_info_t{source=Source}) ->
  181. Source.
  182. -spec state(t(), rebar_state:t() | undefined) -> t().
  183. state(AppInfo=#app_info_t{}, State) ->
  184. AppInfo#app_info_t{state=State}.
  185. -spec state(t()) -> rebar_state:t() | undefined.
  186. state(#app_info_t{state=State}) ->
  187. State.
  188. -spec valid(t()) -> boolean().
  189. valid(AppInfo=#app_info_t{valid=undefined}) ->
  190. case rebar_app_discover:validate_application_info(AppInfo) of
  191. true ->
  192. true;
  193. _ ->
  194. false
  195. end;
  196. valid(#app_info_t{valid=Valid}) ->
  197. Valid.
  198. -spec valid(t(), boolean()) -> t().
  199. valid(AppInfo=#app_info_t{}, Valid) ->
  200. AppInfo#app_info_t{valid=Valid}.