You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.2 KiB

  1. -module(rebar_app_info).
  2. -export([new/0,
  3. new/3,
  4. name/1,
  5. name/2,
  6. config/1,
  7. config/2,
  8. app_file_src/1,
  9. app_file_src/2,
  10. app_file/1,
  11. app_file/2,
  12. app_details/1,
  13. app_details/2,
  14. original_vsn/1,
  15. original_vsn/2,
  16. ebin_dir/1,
  17. dir/1,
  18. dir/2]).
  19. -export_type([t/0]).
  20. -record(app_info_t, {name :: atom(),
  21. app_file_src :: file:name() | undefined,
  22. app_file :: file:name(),
  23. config :: rebar_config:config() | undefined,
  24. original_vsn :: string(),
  25. app_details :: list(),
  26. dir :: file:name(),
  27. source :: string() | undefined}).
  28. %%============================================================================
  29. %% types
  30. %%============================================================================
  31. -opaque t() :: record(app_info_t).
  32. %%============================================================================
  33. %% API
  34. %% ============================================================================
  35. %% @doc Build a new, empty, app info value. This is not of a lot of use and you
  36. %% probably wont be doing this much.
  37. -spec new() -> {ok, t()}.
  38. new() ->
  39. {ok, #app_info_t{}}.
  40. %% @doc build a complete version of the app info with all fields set.
  41. -spec new(atom(), string(), file:name()) ->
  42. {ok, t()}.
  43. new(AppName, Vsn, Dir)
  44. when erlang:is_atom(AppName) ->
  45. {ok, #app_info_t{name=AppName,
  46. original_vsn=Vsn,
  47. dir=Dir}}.
  48. -spec name(t()) -> atom().
  49. name(#app_info_t{name=Name}) ->
  50. Name.
  51. -spec name(t(), atom()) -> t().
  52. name(AppInfo=#app_info_t{}, AppName)
  53. when erlang:is_atom(AppName) ->
  54. AppInfo#app_info_t{name=AppName}.
  55. -spec config(t()) -> rebar_config:confg().
  56. config(#app_info_t{config=Config}) ->
  57. Config.
  58. -spec config(t(), rebar_config:confg()) -> t().
  59. config(AppInfo=#app_info_t{}, Config) ->
  60. AppInfo#app_info_t{config=Config}.
  61. -spec app_file_src(t()) -> file:name().
  62. app_file_src(#app_info_t{app_file_src=AppFileSrc}) ->
  63. AppFileSrc.
  64. -spec app_file_src(t(), file:name()) -> t().
  65. app_file_src(AppInfo=#app_info_t{}, AppFileSrc) ->
  66. AppInfo#app_info_t{app_file_src=AppFileSrc}.
  67. -spec app_file(t()) -> file:name().
  68. app_file(#app_info_t{app_file=AppFile}) ->
  69. AppFile.
  70. -spec app_file(t(), file:name()) -> t().
  71. app_file(AppInfo=#app_info_t{}, AppFile) ->
  72. AppInfo#app_info_t{app_file=AppFile}.
  73. -spec app_details(t()) -> list().
  74. app_details(#app_info_t{app_details=AppDetails}) ->
  75. AppDetails.
  76. -spec app_details(t(), list()) -> t().
  77. app_details(AppInfo=#app_info_t{}, AppDetails) ->
  78. AppInfo#app_info_t{app_details=AppDetails}.
  79. -spec original_vsn(t()) -> string().
  80. original_vsn(#app_info_t{original_vsn=Vsn}) ->
  81. Vsn.
  82. -spec original_vsn(t(), string()) -> string().
  83. original_vsn(AppInfo=#app_info_t{}, Vsn) ->
  84. AppInfo#app_info_t{original_vsn=Vsn}.
  85. -spec dir(t()) -> file:name().
  86. dir(#app_info_t{dir=Dir}) ->
  87. Dir.
  88. -spec dir(t(), file:name()) -> t().
  89. dir(AppInfo=#app_info_t{}, Dir) ->
  90. AppInfo#app_info_t{dir=Dir}.
  91. -spec ebin_dir(t()) -> file:name().
  92. ebin_dir(#app_info_t{dir=Dir}) ->
  93. filename:join(Dir, "ebin").