Merge pull request #4299 from zmstone/chore-build-refine-build-scripts

chore(build) add more enterprise build support
This commit is contained in:
Zaiming Shi 2021-03-07 07:12:47 +01:00 committed by GitHub
commit cf169661e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 35 deletions

View File

@ -27,6 +27,13 @@
%% NOTE: This version number should be manually bumped for each release %% NOTE: This version number should be manually bumped for each release
-define(EMQX_RELEASE, "4.3-beta.1"). -ifndef(EMQX_ENTERPRISE).
-define(EMQX_RELEASE, {opensource, "4.3-beta.1"}).
-else.
-endif.
-endif. -endif.

View File

@ -6,7 +6,13 @@ set -euo pipefail
# ensure dir # ensure dir
cd -P -- "$(dirname -- "$0")" cd -P -- "$(dirname -- "$0")"
RELEASE="$(grep -E 'define.+EMQX_RELEASE,' include/emqx_release.hrl | cut -d '"' -f2)" if [ -f EMQX_ENTERPRISE ]; then
EDITION='enterprise'
else
EDITION='opensource'
fi
RELEASE="$(grep -E "define.+EMQX_RELEASE.+${EDITION}" include/emqx_release.hrl | cut -d '"' -f2)"
if [ -d .git ] && ! git describe --tags --match "${RELEASE}" --exact >/dev/null 2>&1; then if [ -d .git ] && ! git describe --tags --match "${RELEASE}" --exact >/dev/null 2>&1; then
SUFFIX="-$(git rev-parse HEAD | cut -b1-8)" SUFFIX="-$(git rev-parse HEAD | cut -b1-8)"

View File

@ -102,17 +102,18 @@ test_compile_opts() ->
]. ].
profiles() -> profiles() ->
Vsn = get_vsn(),
[ {'emqx', [ {erl_opts, prod_compile_opts()} [ {'emqx', [ {erl_opts, prod_compile_opts()}
, {relx, relx('emqx')} , {relx, relx(Vsn, cloud, bin)}
]} ]}
, {'emqx-pkg', [ {erl_opts, prod_compile_opts()} , {'emqx-pkg', [ {erl_opts, prod_compile_opts()}
, {relx, relx('emqx-pkg')} , {relx, relx(Vsn, cloud, pkg)}
]} ]}
, {'emqx-edge', [ {erl_opts, prod_compile_opts()} , {'emqx-edge', [ {erl_opts, prod_compile_opts()}
, {relx, relx('emqx-edge')} , {relx, relx(Vsn, edge, bin)}
]} ]}
, {'emqx-edge-pkg', [ {erl_opts, prod_compile_opts()} , {'emqx-edge-pkg', [ {erl_opts, prod_compile_opts()}
, {relx, relx('emqx-edge-pkg')} , {relx, relx(Vsn, edge, pkg)}
]} ]}
, {check, [ {erl_opts, test_compile_opts()} , {check, [ {erl_opts, test_compile_opts()}
]} ]}
@ -121,41 +122,30 @@ profiles() ->
, {erl_opts, test_compile_opts() ++ erl_opts_i()} , {erl_opts, test_compile_opts() ++ erl_opts_i()}
, {extra_src_dirs, [{"test", [{recursive,true}]}]} , {extra_src_dirs, [{"test", [{recursive,true}]}]}
]} ]}
]. ] ++ ee_profiles(Vsn).
relx(Profile) -> %% RelType: cloud (full size) | edge (slim size)
Vsn = get_vsn(), %% PkgType: bin | pkg
relx(Vsn, RelType, PkgType) ->
[ {include_src,false} [ {include_src,false}
, {include_erts, true} , {include_erts, true}
, {extended_start_script,false} , {extended_start_script,false}
, {generate_start_script,false} , {generate_start_script,false}
, {sys_config,false} , {sys_config,false}
, {vm_args,false} , {vm_args,false}
] ++ do_relx(Profile, Vsn). , {release, {emqx, Vsn}, relx_apps(RelType)}
, {overlay, relx_overlay(RelType)}
do_relx('emqx', Vsn) -> , {overlay_vars, [ {built_on_arch, rebar_utils:get_arch()}
[ {release, {emqx, Vsn}, relx_apps(cloud)} , overlay_vars_rel(RelType)
, {overlay, relx_overlay(cloud)} , overlay_vars_pkg(PkgType)
, {overlay_vars, overlay_vars(["vars/vars-cloud.config","vars/vars-bin.config"])} ]}
];
do_relx('emqx-pkg', Vsn) ->
[ {release, {emqx, Vsn}, relx_apps(cloud)}
, {overlay, relx_overlay(cloud)}
, {overlay_vars, overlay_vars(["vars/vars-cloud.config","vars/vars-pkg.config"])}
];
do_relx('emqx-edge', Vsn) ->
[ {release, {emqx, Vsn}, relx_apps(edge)}
, {overlay, relx_overlay(edge)}
, {overlay_vars, overlay_vars(["vars/vars-edge.config","vars/vars-bin.config"])}
];
do_relx('emqx-edge-pkg', Vsn) ->
[ {release, {emqx, Vsn}, relx_apps(edge)}
, {overlay, relx_overlay(edge)}
, {overlay_vars, overlay_vars(["vars/vars-edge.config","vars/vars-pkg.config"])}
]. ].
overlay_vars(Files) -> overlay_vars_rel(cloud) -> "vars/vars-cloud.config";
[{built_on_arch, rebar_utils:get_arch()} | Files]. overlay_vars_rel(edge) -> "vars/vars-edge.config".
overlay_vars_pkg(bin) -> "vars/vars-bin.config";
overlay_vars_pkg(pkg) -> "vars/vars-pkg.config".
relx_apps(ReleaseType) -> relx_apps(ReleaseType) ->
[ kernel [ kernel
@ -204,9 +194,9 @@ relx_plugin_apps(ReleaseType) ->
, emqx_recon , emqx_recon
, emqx_rule_engine , emqx_rule_engine
, emqx_sasl , emqx_sasl
, emqx_telemetry
, emqx_modules , emqx_modules
] ]
++ [emqx_telemetry || not is_enterprise()]
++ relx_plugin_apps_per_rel(ReleaseType) ++ relx_plugin_apps_per_rel(ReleaseType)
++ relx_plugin_apps_enterprise(is_enterprise()) ++ relx_plugin_apps_enterprise(is_enterprise())
++ relx_plugin_apps_extra(). ++ relx_plugin_apps_extra().
@ -400,3 +390,7 @@ coveralls() ->
list_dir(Dir) -> list_dir(Dir) ->
{ok, Names} = file:list_dir(Dir), {ok, Names} = file:list_dir(Dir),
[list_to_atom(Name) || Name <- Names, filelib:is_dir(filename:join([Dir, Name]))]. [list_to_atom(Name) || Name <- Names, filelib:is_dir(filename:join([Dir, Name]))].
%% ==== Enterprise supports below ==================================================================
ee_profiles(_Vsn) -> [].

View File

@ -64,16 +64,20 @@ print_vsn() ->
-ifdef(TEST). -ifdef(TEST).
%% When testing, the 'cover' compiler stripps aways compile info %% When testing, the 'cover' compiler stripps aways compile info
get_release() -> ?EMQX_RELEASE. get_release() -> release_in_macro().
-else. -else.
%% Otherwise print the build number, %% Otherwise print the build number,
%% which may have a git commit in its suffix. %% which may have a git commit in its suffix.
get_release() -> get_release() ->
{_, Vsn} = lists:keyfind(emqx_vsn, 1, ?MODULE:module_info(compile)), {_, Vsn} = lists:keyfind(emqx_vsn, 1, ?MODULE:module_info(compile)),
?EMQX_RELEASE ++ _ = Vsn, %% assert VsnStr = release_in_macro(),
1 = string:str(Vsn, VsnStr), %% assert
Vsn. Vsn.
-endif. -endif.
release_in_macro() ->
element(2, ?EMQX_RELEASE).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Autocluster %% Autocluster
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------