加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rebar.config.script 9.23 KB
一键复制 编辑 原始数据 按行查看 历史
%%-*- mode: erlang -*-
%% =============================================================================
%% maybe upload coverdata
%% =============================================================================
CONFIG0 = case os:getenv("TRAVIS") of
"true" ->
JobId = os:getenv("TRAVIS_JOB_ID"),
[{coveralls_service_job_id, JobId},
{coveralls_coverdata, "_build/test/cover/*.coverdata"},
{coveralls_service_name , "travis-ci"} | CONFIG];
_ ->
CONFIG
end,
%% =============================================================================
%% Dependencies
%% =============================================================================
PluginsNeededByElixir = [rebar_mix,
{rebar3_elixir_compile,
{git, "https://github.com/barrel-db/rebar3_elixir_compile.git",
{branch, "master"}}}],
HooksNeededByElixir = {provider_hooks, [{pre, [{compile, {ex, compile}}]}]},
OptsNeededByElixir = {elixir_opts, [{env, dev}]},
Kf = fun(K, L) -> {K, V} = lists:keyfind(K, 1, L), V end,
{ElixirDeps, CONFIG1} = case Kf(elixir_deps, CONFIG0) of
false ->{[], CONFIG0};
[] -> {[], CONFIG0};
ElixirDeps0 ->
Plugins = Kf(plugins, CONFIG0),
NewConfig = lists:keydelete(plugins, 1, CONFIG0),
Plugins1 = {plugins, Plugins ++ PluginsNeededByElixir},
{ElixirDeps0,
[Plugins1, HooksNeededByElixir, OptsNeededByElixir | NewConfig]}
end,
PluginCompatWindowsPlatform = fun(Config) ->
PluginsTmp = Kf(plugins, Config),
ConfigTmp = lists:keydelete(plugins, 1, Config),
Plugins2 = {plugins, case os:type() of
{win32, nt} -> PluginsTmp -- [rebar3_run];
_ -> PluginsTmp
end},
CONFIG2 = [Plugins2 | ConfigTmp]
end,
CONFIG2 = PluginCompatWindowsPlatform(CONFIG1),
BaseDeps = Kf(deps, CONFIG2) ++ ElixirDeps,
CloudDeps = BaseDeps ++ Kf(cloud_deps, CONFIG2),
EdgeDeps = BaseDeps ++ Kf(edge_deps, CONFIG2),
%% Make a dep element for rebar.config GitRef should be either {tag, Tag} or {branch, Branch}
MakeDep =
fun({Name, {git, _, _}} = App, _DefaultDepRef) ->
%% alreay a complete ref
App;
(App, DefaultDepRef) ->
{AppName, GitRef} =
case App of
{Name, Pinned} when is_tuple(Pinned) -> {Name, Pinned};
{Name, Tag} when is_list(Tag) -> {Name, {tag, Tag}};
Name when is_atom(Name) -> {Name, DefaultDepRef}
end,
RepoName = string:join(string:tokens(atom_to_list(AppName), "_"), "-"),
URL = "https://github.com/emqx/" ++ RepoName,
{AppName, {git, URL, GitRef}}
end,
MakeDeps = fun(Deps, DefaultDepRef, TestDeps) -> [MakeDep(App, DefaultDepRef) || App <- Deps] ++ TestDeps end,
%% TODO: this is only a temporary workaround in order to be backward compatible
%% The right way is to always pin dependency version in rebar.config
%% Any dependency that can not be tested and released independently
%% (i.e. has to be a part of a emqx release in order to be tested)
%% should not be a dependency but a local application reside in the same repo.
%% (Meaning: emqx should be an umbrella project)
ComparingFun = fun
_Fun([C1|R1], [C2|R2]) when is_list(C1), is_list(C2);
is_integer(C1), is_integer(C2) -> C1 < C2 orelse _Fun(R1, R2);
_Fun([C1|R1], [C2|R2]) when is_integer(C1), is_list(C2) -> _Fun(R1, R2);
_Fun([C1|R1], [C2|R2]) when is_list(C1), is_integer(C2) -> true;
_Fun(_, _) -> false
end,
SortFun = fun(T1, T2) ->
C = fun(T) ->
[case catch list_to_integer(E) of
I when is_integer(I) -> I;
_ -> E
end || E <- re:split(string:sub_string(T, 2), "[.-]", [{return, list}])]
end,
ComparingFun(C(T1), C(T2))
end,
Tag = os:cmd("git describe --abbrev=0 --tags") -- "\n",
LatestTagCommitId = os:cmd(io_lib:format("git rev-parse ~s", [Tag])) -- "\n",
Tags = string:tokens(os:cmd(io_lib:format("git tag -l \"v*\" --points-at ~s", [LatestTagCommitId])), "\n"),
LatestTag = lists:last(lists:sort(SortFun, Tags)),
Branch = case os:getenv("GITHUB_RUN_ID") of
false -> os:cmd("git branch | grep -e '^*' | cut -d' ' -f 2") -- "\n";
_ -> re:replace(os:getenv("GITHUB_REF"), "^refs/heads/|^refs/tags/", "", [global, {return ,list}])
end,
GitRef = case re:run(Branch, "master|^dev/|^hotfix/", [{capture, none}]) of
match -> {branch, Branch};
_ -> {tag, LatestTag}
end,
DefaultDepRef =
case os:getenv("EMQX_DEPS_DEFAULT_VSN") of
false -> GitRef; %% not set
"" -> GitRef; %% set empty
[] -> GitRef; %% set empty
MaybeTag ->
case re:run(MaybeTag, "^[ev0-9\]+\.\[0-9\]+\.*") of
nomatch -> {branch, MaybeTag};
_ -> {tag, MaybeTag}
end
end,
%% =============================================================================
%% Relx configs
%% =============================================================================
GitDescribe = begin
T = case DefaultDepRef of
{tag, EnvTag} -> EnvTag;
_Else -> LatestTag
end,
re:replace(T, "v", "", [{return ,list}])
end,
Relx0 = Kf(relx, CONFIG2),
{release, {_, Vsn0}, RelxBaseApps0} = lists:keyfind(release, 1, Relx0),
Vsn1 = case Vsn0 of
git_describe -> GitDescribe;
Vsn -> Vsn
end,
RelxElixirApps = Kf(elixir_relx_apps, CONFIG2),
RelxBaseApps = RelxBaseApps0 ++ RelxElixirApps,
RelxOverlay = Kf(overlay, Relx0),
RelxCloudApps = RelxBaseApps ++ Kf(cloud_relx_apps, CONFIG2),
RelxEdgeApps = RelxBaseApps ++ Kf(edge_relx_apps, CONFIG2),
RelxCloudOverlay0 = Kf(cloud_relx_overlay, CONFIG2),
RelxEdgeOverlay0 = Kf(edge_relx_overlay, CONFIG2),
RelxCloudOverlay = RelxOverlay ++ RelxCloudOverlay0,
RelxEdgeOverlay = RelxOverlay ++ RelxEdgeOverlay0,
MakeRelx =
fun(Apps, Overlay, Vars) ->
VarFiles = ["vars-" ++ atom_to_list(Var) ++ ".config" || Var <- Vars],
Apps1 = case os:type() of {win32, nt} -> Apps -- [bcrypt]; _Other -> Apps end,
Relx1 = lists:keystore(release, 1, Relx0, {release, {emqx, Vsn1}, Apps1}),
Relx2 = lists:keystore(overlay, 1, Relx1, {overlay, Overlay}),
lists:keystore(overlay_vars, 1, Relx2, {overlay_vars, VarFiles})
end,
Relx = fun(Vars) -> MakeRelx(RelxBaseApps, RelxOverlay, Vars) end,
RelxCloud = fun(Vars) -> MakeRelx(RelxCloudApps, RelxCloudOverlay, Vars) end,
RelxEdge = fun(Vars) -> MakeRelx(RelxEdgeApps, RelxEdgeOverlay, Vars) end,
TestDeps = [ {meck, "0.8.13"} % hex
, {bbmustache, "1.7.0"} % hex
, {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "v1.1.1"}}}
],
%% =============================================================================
%% Profiles
%% =============================================================================
Profiles =
[ {emqx,
[ {deps, MakeDeps(CloudDeps, DefaultDepRef, [])}
, {relx, RelxCloud([cloud, bin])}
, {post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", compile, "./inject-deps.escript emqx"}]}
]}
, {'emqx-pkg',
[ {deps, MakeDeps(CloudDeps, DefaultDepRef, [])}
, {relx, RelxCloud([cloud, pkg])}
, {post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", compile, "./inject-deps.escript emqx-pkg"}]}
]}
, {'emqx-edge',
[ {deps, MakeDeps(EdgeDeps, DefaultDepRef, [])}
, {relx, RelxEdge([edge, bin])}
, {post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", compile, "./inject-deps.escript emqx-edge"}]}
]}
, {'emqx-edge-pkg',
[ {deps, MakeDeps(EdgeDeps, DefaultDepRef, [])}
, {relx, RelxEdge([edge, pkg])}
, {post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", compile, "./inject-deps.escript emqx-edge-pkg"}]}
]}
],
Deletes = [ deps
, relx
, elixir_deps
, edge_deps
, cloud_deps
, elixir_relx_apps
, edge_relx_apps
, cloud_relx_apps
, cloud_relx_overlay
],
Additions = [{profiles, Profiles}],
CONFIG3 = lists:foldl(fun(K, Acc) -> lists:keydelete(K, 1, Acc) end, CONFIG2, Deletes),
CONFIG4 = lists:foldl(fun({K, V}, Acc) -> lists:keystore(K, 1, Acc, {K, V}) end, CONFIG3, Additions),
FilePath = case os:type() of
{win32, nt} ->
"emqx.rebar.config";
_ ->
"/tmp/emqx.rebar.config"
end,
file:write_file(FilePath, [io_lib:format("~p.\n", [I]) || I <- CONFIG4]),
CONFIG4.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化