Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

254 wiersze
7.7 KiB

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