Просмотр исходного кода

refactor(rebar.config): make use of rebar.config.erl

Zaiming Shi 5 лет назад
Родитель
Сommit
8fe889dd14
3 измененных файлов с 191 добавлено и 194 удалено
  1. 27 176
      rebar.config
  2. 164 0
      rebar.config.erl
  3. 0 18
      rebar.config.script

+ 27 - 176
rebar.config

@@ -1,73 +1,38 @@
+%% This config file is the very basic config to compile emqx
+%% This allows emqx to be used as a dependency for other applications
+%% such as emqx module/plugin develpments and tests.
+
+%% With the help of EMQ's rebar3 fork, the config is extended
+%% with rebar.config.erl module. Final result is written to
+%% rebar.config.rendered if environment DEBUG is set.
+
 {minimum_otp_vsn, "21.3"}.
-{plugins,[ {relup_helper,{git,"https://github.com/emqx/relup_helper", {branch,"master"}}}
-         , {coveralls, {git, "https://github.com/emqx/coveralls-erl", {branch, "github"}}}
-         ]}.
-{edge_relx_overlay,[]}.
-{edoc_opts,[{preprocess,true}]}.
-{erl_opts,[warn_unused_vars,warn_shadow_vars,warn_unused_import,
-           warn_obsolete_guard,no_debug_info,compressed]}.
+{edoc_opts, [{preprocess,true}]}.
+{erl_opts, [warn_unused_vars,warn_shadow_vars,warn_unused_import,
+            warn_obsolete_guard,no_debug_info,compressed]}.
+
 {overrides,[{add,[{erl_opts,[no_debug_info,compressed,deterministic,
                              {parse_transform,mod_vsn}]}]}]}.
+
 {xref_checks,[undefined_function_calls,undefined_functions,locals_not_used,
-              deprecated_function_calls,warnings_as_errors,
-              deprecated_functions]}.
-{dialyzer, [{warnings, [unmatched_returns, error_handling, race_conditions]}
-           ]}.
-{cover_enabled,true}.
-{cover_opts,[verbose]}.
-{cover_export_enabled,true}.
-{provider_hooks,[{pre,[{release,{relup_helper,gen_appups}}]},
-                 {post,[{release,{relup_helper,otp_vsn}},
-                        {release,{relup_helper,untar}}]}]}.
-{post_hooks,[]}.
-{erl_first_files, ["src/emqx_logger.erl"]}.
+              deprecated_function_calls,warnings_as_errors, deprecated_functions]}.
 
-"${COVERALL_CONFIGS}".
+{dialyzer, [{warnings, [unmatched_returns, error_handling, race_conditions]}]}.
 
-{deps, ["${BASIC_DEPS}"]}.
+{cover_enabled, true}.
+{cover_opts, [verbose]}.
+{cover_export_enabled, true}.
 
-{profiles,
-    [{'emqx',
-        [{relx,
-             ["${BASIC_RELX_PARAMS}",
-              {release, {emqx, "${GIT_DESC}"}, ["${BASIC_RELX_APPS}", "${CLOUD_RELX_APPS}"]},
-              {overlay, ["${BASIC_OVERLAYS}", "${CLOUD_OVERLAYS}"]},
-              {overlay_vars,["vars/vars-cloud.config","vars/vars-bin.config"]}]}]},
-     {'emqx-pkg',
-         [{relx,
-              ["${BASIC_RELX_PARAMS}",
-               {release, {emqx, "${GIT_DESC}"}, ["${BASIC_RELX_APPS}", "${CLOUD_RELX_APPS}"]},
-               {overlay, ["${BASIC_OVERLAYS}", "${CLOUD_OVERLAYS}"]},
-               {overlay_vars,["vars/vars-cloud.config","vars/vars-pkg.config"]}]}]},
-     {'emqx-edge',
-         [{relx,
-              ["${BASIC_RELX_PARAMS}",
-               {release, {emqx, "${GIT_DESC}"}, ["${BASIC_RELX_APPS}"]},
-               {overlay, ["${BASIC_OVERLAYS}", "${EDGE_OVERLAYS}"]},
-               {overlay_vars,["vars/vars-edge.config","vars/vars-bin.config"]}]}]},
-     {'emqx-edge-pkg',
-         [{relx,
-              ["${BASIC_RELX_PARAMS}",
-               {release, {emqx, "${GIT_DESC}"}, ["${BASIC_RELX_APPS}"]},
-               {overlay, ["${BASIC_OVERLAYS}", "${EDGE_OVERLAYS}"]},
-               {overlay_vars,["vars/vars-edge.config","vars/vars-pkg.config"]}]}]},
-     {test,
-        [{deps,
-          [ {bbmustache, "1.10.0"},
-            {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.0"}}},
-            {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "1.3.0"}}},
-            meck
-          ]},
-          {erl_opts, [debug_info]}
-        ]}
-    ]}.
+{provider_hooks,[{pre,[{release,{relup_helper,gen_appups}}]},
+                 {post,[{release,{relup_helper,otp_vsn}},
+                 {release,{relup_helper,untar}}
+                ]}]}.
+
+{post_hooks,[]}.
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%% Placeholders
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-{placeholders, [
+{erl_first_files, ["src/emqx_logger.erl"]}.
 
-  {"BASIC_DEPS", elems,
+{deps,
     [ {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.8.0"}}}
     , {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}
     , {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.7.1"}}}
@@ -83,118 +48,4 @@
     , {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.0"}}}
     , {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.2"}}}
     , {getopt, "1.0.1"}
-    ]
-  },
-
-  {"BASIC_RELX_PARAMS", elems,
-    [ {include_src,false}
-    , {extended_start_script,false}
-    , {generate_start_script,false}
-    , {sys_config,false}
-    , {vm_args,false}
-    ]
-  },
-
-  {"BASIC_RELX_APPS", elems,
-    [ kernel
-    , sasl
-    , crypto
-    , public_key
-    , asn1
-    , syntax_tools
-    , ssl
-    , os_mon
-    , inets
-    , compiler
-    , runtime_tools
-    , cuttlefish
-    , emqx
-    , {mnesia, load}
-    , {ekka, load}
-    , {emqx_retainer, load}
-    , {emqx_management, load}
-    , {emqx_dashboard, load}
-    , {emqx_bridge_mqtt, load}
-    , {emqx_sn, load}
-    , {emqx_coap, load}
-    , {emqx_stomp, load}
-    , {emqx_auth_http, load}
-    , {emqx_auth_mysql, load}
-    , {emqx_auth_jwt, load}
-    , {emqx_auth_mnesia, load}
-    , {emqx_web_hook, load}
-    , {emqx_recon, load}
-    , {emqx_rule_engine, load}
-    , {emqx_sasl, load}
-    , {emqx_telemetry, load}
-    ]
-  },
-
-  {"CLOUD_RELX_APPS", elems,
-    [ {emqx_lwm2m, load}
-    , {emqx_auth_ldap, load}
-    , {emqx_auth_pgsql, load}
-    , {emqx_auth_redis, load}
-    , {emqx_auth_mongo, load}
-    , {emqx_lua_hook, load}
-    , {emqx_exhook, load}
-    , {emqx_exproto, load}
-    , {emqx_prometheus, load}
-    , {emqx_psk_file, load}
-    , {emqx_plugin_template, load}
-    , {observer, load}
-    , luerl
-    , xmerl
-    ]
-  },
-
-  {"BASIC_OVERLAYS", elems,
-    [ {mkdir,"etc/"}
-    , {mkdir,"etc/emqx.d/"}
-    , {mkdir,"log/"}
-    , {mkdir,"data/"}
-    , {mkdir,"data/mnesia"}
-    , {mkdir,"data/configs"}
-    , {mkdir,"data/scripts"}
-    , {template, "data/loaded_plugins.tmpl", "data/loaded_plugins"}
-    , {template, "data/loaded_modules.tmpl", "data/loaded_modules"}
-    , {template,"data/emqx_vars","releases/emqx_vars"}
-    , {copy,"_build/default/lib/cuttlefish/cuttlefish","bin/"}
-    , {copy,"bin/*","bin/"}
-    , {template,"etc/*.conf","etc/"}
-    , {template,"etc/emqx.d/*.conf","etc/emqx.d/"}
-    , {copy,"priv/emqx.schema","releases/{{rel_vsn}}/"}
-    , {copy, "etc/certs","etc/"}
-    , "${RELUP_OVERLAYS}"
-    ]
-  },
-
-  {"RELUP_OVERLAYS", elems,
-    [ {copy,"bin/emqx.cmd","bin/emqx.cmd-{{rel_vsn}}"}
-    , {copy,"bin/emqx_ctl.cmd","bin/emqx_ctl.cmd-{{rel_vsn}}"}
-    , {copy,"bin/emqx","bin/emqx-{{rel_vsn}}"}
-    , {copy,"bin/emqx_ctl","bin/emqx_ctl-{{rel_vsn}}"}
-    , {copy,"bin/install_upgrade.escript", "bin/install_upgrade.escript-{{rel_vsn}}"}
-    , {copy,"bin/nodetool","bin/nodetool-{{rel_vsn}}"}
-    , {copy,"_build/default/lib/cuttlefish/cuttlefish","bin/cuttlefish-{{rel_vsn}}"}
-    ]
-  },
-
-  {"CLOUD_OVERLAYS", elems,
-    [ {template,"etc/emqx_cloud.d/*.conf","etc/emqx.d/"}
-    , {template,"etc/emqx_cloud.d/vm.args","etc/vm.args"}
-    ]
-  },
-
-  {"EDGE_OVERLAYS", elems,
-    [ {template,"etc/emqx_edge.d/*.conf","etc/emqx.d/"}
-    , {template,"etc/emqx_edge.d/vm.args.edge","etc/vm.args"}
-    ]
-  },
-
-  {"GIT_DESC", var, fun mod_project:get_vsn/1},
-
-  {"COVERALL_CONFIGS", elems, fun mod_project:coveralls_configs/1}
-
-]}.
-
+    ]}.

+ 164 - 0
rebar.config.erl

@@ -0,0 +1,164 @@
+-module('rebar.config').
+
+-export([do/2]).
+
+do(_Dir, CONFIG) ->
+    maybe_dump(CONFIG ++ config()).
+
+config() ->
+    [ {plugins, plugins()}
+    , {profiles, profiles()}
+    ].
+
+plugins() ->
+    [ {relup_helper,{git,"https://github.com/emqx/relup_helper", {branch,"master"}}}
+    ].
+
+test_deps() ->
+    [ {bbmustache, "1.10.0"}
+    , {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.0"}}}
+    , {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "1.3.0"}}}
+    , meck
+    ].
+
+profiles() ->
+    [ {'emqx',          [{relx, relx('emqx')}]}
+    , {'emqx-pkg',      [{relx, relx('emqx-pkg')}]}
+    , {'emqx-edge',     [{relx, relx('emqx-edge')}]}
+    , {'emqx-edge-pkg', [{relx, relx('emqx-edge-pkg')}]}
+    , {test,            [{deps, test_deps()}, {erl_opts, [debug_info]}]}
+    ].
+
+relx(Profile) ->
+    Vsn = get_vsn(),
+    [ {include_src,false}
+    , {extended_start_script,false}
+    , {generate_start_script,false}
+    , {sys_config,false}
+    , {vm_args,false}
+    ] ++ do_relx(Profile, Vsn).
+
+do_relx('emqx', Vsn) ->
+    [ {release, {emqx, Vsn}, relx_apps(cloud)}
+    , {overlay, relx_overlay(cloud)}
+    , {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,["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,["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,["vars/vars-edge.config","vars/vars-pkg.config"]}
+    ].
+
+relx_apps(ReleaseType) ->
+    [ kernel
+    , sasl
+    , crypto
+    , public_key
+    , asn1
+    , syntax_tools
+    , ssl
+    , os_mon
+    , inets
+    , compiler
+    , runtime_tools
+    , cuttlefish
+    , emqx
+    , {mnesia, load}
+    , {ekka, load}
+    , {emqx_retainer, load}
+    , {emqx_management, load}
+    , {emqx_dashboard, load}
+    , {emqx_bridge_mqtt, load}
+    , {emqx_sn, load}
+    , {emqx_coap, load}
+    , {emqx_stomp, load}
+    , {emqx_auth_http, load}
+    , {emqx_auth_mysql, load}
+    , {emqx_auth_jwt, load}
+    , {emqx_auth_mnesia, load}
+    , {emqx_web_hook, load}
+    , {emqx_recon, load}
+    , {emqx_rule_engine, load}
+    , {emqx_sasl, load}
+    , {emqx_telemetry, load}
+    ] ++ do_relx_apps(ReleaseType).
+
+do_relx_apps(cloud) ->
+    [ {emqx_lwm2m, load}
+    , {emqx_auth_ldap, load}
+    , {emqx_auth_pgsql, load}
+    , {emqx_auth_redis, load}
+    , {emqx_auth_mongo, load}
+    , {emqx_lua_hook, load}
+    , {emqx_exhook, load}
+    , {emqx_exproto, load}
+    , {emqx_prometheus, load}
+    , {emqx_psk_file, load}
+    , {emqx_plugin_template, load}
+    , {observer, load}
+    , luerl
+    , xmerl
+    ];
+do_relx_apps(_) ->
+    [].
+
+relx_overlay(ReleaseType) ->
+    [ {mkdir,"etc/"}
+    , {mkdir,"etc/emqx.d/"}
+    , {mkdir,"log/"}
+    , {mkdir,"data/"}
+    , {mkdir,"data/mnesia"}
+    , {mkdir,"data/configs"}
+    , {mkdir,"data/scripts"}
+    , {template, "data/loaded_plugins.tmpl", "data/loaded_plugins"}
+    , {template, "data/loaded_modules.tmpl", "data/loaded_modules"}
+    , {template,"data/emqx_vars","releases/emqx_vars"}
+    , {copy,"_build/default/lib/cuttlefish/cuttlefish","bin/"}
+    , {copy,"bin/*","bin/"}
+    , {template,"etc/*.conf","etc/"}
+    , {template,"etc/emqx.d/*.conf","etc/emqx.d/"}
+    , {copy,"priv/emqx.schema","releases/{{rel_vsn}}/"}
+    , {copy, "etc/certs","etc/"}
+    , {copy,"bin/emqx.cmd","bin/emqx.cmd-{{rel_vsn}}"}
+    , {copy,"bin/emqx_ctl.cmd","bin/emqx_ctl.cmd-{{rel_vsn}}"}
+    , {copy,"bin/emqx","bin/emqx-{{rel_vsn}}"}
+    , {copy,"bin/emqx_ctl","bin/emqx_ctl-{{rel_vsn}}"}
+    , {copy,"bin/install_upgrade.escript", "bin/install_upgrade.escript-{{rel_vsn}}"}
+    , {copy,"bin/nodetool","bin/nodetool-{{rel_vsn}}"}
+    , {copy,"_build/default/lib/cuttlefish/cuttlefish","bin/cuttlefish-{{rel_vsn}}"}
+    ] ++ do_relx_overlay(ReleaseType).
+
+do_relx_overlay(cloud) ->
+    [ {template,"etc/emqx_cloud.d/*.conf","etc/emqx.d/"}
+    , {template,"etc/emqx_cloud.d/vm.args","etc/vm.args"}
+    ];
+do_relx_overlay(edge) ->
+    [ {template,"etc/emqx_edge.d/*.conf","etc/emqx.d/"}
+    , {template,"etc/emqx_edge.d/vm.args.edge","etc/vm.args"}
+    ].
+
+get_vsn() ->
+    PkgVsn = case os:getenv("PKG_VSN") of
+                 false -> os:cmd("git describe --tags");
+                 Vsn -> Vsn
+             end,
+    Vsn2 = re:replace(PkgVsn, "v", "", [{return ,list}]),
+    re:replace(Vsn2, "\n", "", [{return ,list}]).
+
+maybe_dump(Config) ->
+    case os:getenv("DEBUG") of
+        "" -> ok;
+        false -> ok;
+        _ -> file:write_file("rebar.config.rendered", [io_lib:format("~p.\n", [I]) || I <- Config])
+    end,
+    Config.

+ 0 - 18
rebar.config.script

@@ -1,18 +0,0 @@
-%%-*- mode: erlang -*-
-
-%% load the helper modules:
-CompileOpts = [verbose,report_errors,report_warnings,return_errors,binary],
-[case compile:file(ModFile, CompileOpts) of
-    {ok, Mod, BinCode} ->
-        {module, _} = code:load_binary(Mod, ModFile, BinCode);
-    Error ->
-        io:format("[error] compile:file(~p) failed: ~p~n", [ModFile, Error])
- end || ModFile <- filelib:wildcard("**/mods/mod_*.erl")],
-
-%% TODO: load the plugins here:
-%% get user plugins from a text file, fetch it and compile
-
-%% render the rebar.config by evaluating the placeholders:
-CONFIG_R = mod_config_template:render(CONFIG),
-%file:write_file("rebar.config.rendered", [io_lib:format("~p.\n", [I]) || I <- CONFIG_R]),
-CONFIG_R.