emqx_release.erl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2021-2022 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_release).
  17. -export([
  18. edition/0,
  19. description/0,
  20. version/0
  21. ]).
  22. -include("emqx_release.hrl").
  23. -define(EMQX_DESCS, #{
  24. ee => "EMQX Enterprise",
  25. ce => "EMQX"
  26. }).
  27. -define(EMQX_REL_VSNS, #{
  28. ee => ?EMQX_RELEASE_EE,
  29. ce => ?EMQX_RELEASE_CE
  30. }).
  31. %% @doc Return EMQX description.
  32. description() ->
  33. maps:get(edition(), ?EMQX_DESCS).
  34. %% @doc Return EMQX edition info.
  35. %% Read info from persistent_term at runtime.
  36. %% Or meck this function to run tests for another edition.
  37. -spec edition() -> ce | ee.
  38. -ifdef(EMQX_RELEASE_EDITION).
  39. edition() -> ?EMQX_RELEASE_EDITION.
  40. -else.
  41. edition() -> ce.
  42. -endif.
  43. %% @doc Return the release version.
  44. version() ->
  45. case lists:keyfind(emqx_vsn, 1, ?MODULE:module_info(compile)) of
  46. %% For TEST build or dependency build.
  47. false ->
  48. build_vsn();
  49. %% For emqx release build
  50. {_, Vsn} ->
  51. VsnStr = build_vsn(),
  52. case string:str(Vsn, VsnStr) of
  53. 1 ->
  54. ok;
  55. _ ->
  56. erlang:error(#{
  57. reason => version_mismatch,
  58. source => VsnStr,
  59. built_for => Vsn
  60. })
  61. end,
  62. Vsn
  63. end.
  64. build_vsn() ->
  65. maps:get(edition(), ?EMQX_REL_VSNS).