Skip to content
Draft

Rebar3 #4120

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rebar3: rebar3 ic setup_eunit plugin
Create a rebar3 ic setup_eunit plugin to keep the same functionality
as the previous one. Since we need to use `setup_eunit.template`, so
move it to `plugins/ic/priv` folder.

Commands:
`rebar3 help ic`, `rebar3 help ic setup_eunit`,
`rebar3 ic`, `rebar3 ic setup_eunit [-f]`, `rebar3 ic setup_eunit -f`,
and `make setup-eunit`
  • Loading branch information
jiahuili430 committed Jul 21, 2022
commit 098e2ad9e23e9dac7622d5db6baf0f75b82ec657
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ test/javascript/junit.xml
/apps/junit_formatter/

.idea
*.iml
_build
*.iml
*.lock
*.crashdump
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ eunit: export ERL_AFLAGS = -config $(shell pwd)/rel/files/eunit.config
eunit: export COUCHDB_QUERY_SERVER_JAVASCRIPT = $(shell pwd)/bin/couchjs $(shell pwd)/share/server/main.js
eunit: export COUCHDB_TEST_ADMIN_PARTY_OVERRIDE=1
eunit: couch
@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) setup_eunit 2> /dev/null
@COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR3) ic setup_eunit 2> /dev/null
@for dir in $(subdirs); do \
COUCHDB_VERSION=$(COUCHDB_VERSION) COUCHDB_GIT_SHA=$(COUCHDB_GIT_SHA) $(REBAR) -r eunit $(EUNIT_OPTS) apps=$$dir || exit 1; \
done
Expand All @@ -191,7 +191,7 @@ exunit: couch elixir-init setup-eunit elixir-check-formatted elixir-credo
setup-eunit: export BUILDDIR = $(shell pwd)
setup-eunit: export ERL_AFLAGS = -config $(shell pwd)/rel/files/eunit.config
setup-eunit:
@$(REBAR) setup_eunit 2> /dev/null
@$(REBAR3) ic setup_eunit 2> /dev/null

just-eunit: export BUILDDIR = $(shell pwd)
just-eunit: export ERL_AFLAGS = -config $(shell pwd)/rel/files/eunit.config
Expand All @@ -202,7 +202,7 @@ just-eunit:
soak-eunit: export BUILDDIR = $(shell pwd)
soak-eunit: export ERL_AFLAGS = -config $(shell pwd)/rel/files/eunit.config
soak-eunit: couch
@$(REBAR) setup_eunit 2> /dev/null
@$(REBAR3) ic setup_eunit 2> /dev/null
while [ $$? -eq 0 ] ; do $(REBAR) -r eunit $(EUNIT_OPTS) ; done

erlfmt-check:
Expand All @@ -222,15 +222,15 @@ python-black: .venv/bin/black
@python3 -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
LC_ALL=C.UTF-8 LANG=C.UTF-8 .venv/bin/black --check \
--exclude="build/|buck-out/|dist/|_build/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/|apps/erlfmt|apps/jiffy|apps/rebar/pr2relnotes.py|apps/fauxton" \
build-aux/*.py dev/run dev/format_*.py apps/mango/test/*.py apps/docs/src/conf.py apps/docs/ext/*.py .
build-aux/*.py dev/run dev/format_*.py apps/mango/test/*.py _build/default/lib/docs/src/conf.py _build/default/lib/docs/ext/*.py .

python-black-update: .venv/bin/black
@python3 -c "import sys; exit(1 if sys.version_info < (3,6) else 0)" || \
echo "Python formatter not supported on Python < 3.6; check results on a newer platform"
@python3 -c "import sys; exit(1 if sys.version_info >= (3,6) else 0)" || \
LC_ALL=C.UTF-8 LANG=C.UTF-8 .venv/bin/black \
--exclude="build/|buck-out/|dist/|_build/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/|apps/rebar/pr2relnotes.py|apps/fauxton" \
build-aux/*.py dev/run apps/mango/test/*.py apps/docs/src/conf.py apps/docs/ext/*.py .
build-aux/*.py dev/run apps/mango/test/*.py _build/default/lib/docs/src/conf.py _build/default/lib/docs/ext/*.py .

.PHONY: elixir
elixir: export MIX_ENV=integration
Expand Down
8 changes: 4 additions & 4 deletions setup_eunit.template → plugins/ic/priv/setup_eunit.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{dir, "tmp/etc"}.
{dir, "tmp/data"}.
{dir, "tmp/tmp_data"}.
{template, "rel/overlay/etc/default.ini", "tmp/etc/default_eunit.ini"}.
{template, "rel/overlay/etc/local.ini", "tmp/etc/local_eunit.ini"}.
{template, "rel/files/eunit.ini", "tmp/etc/eunit.ini"}.
{template, "rel/overlay/etc/vm.args", "tmp/etc/vm.args"}.
{template, "../../../rel/overlay/etc/default.ini", "tmp/etc/default_eunit.ini"}.
{template, "../../../rel/overlay/etc/local.ini", "tmp/etc/local_eunit.ini"}.
{template, "../../../rel/files/eunit.ini", "tmp/etc/eunit.ini"}.
{template, "../../../rel/overlay/etc/vm.args", "tmp/etc/vm.args"}.
7 changes: 7 additions & 0 deletions plugins/ic/src/ic.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{application, ic, [
{description, "rebar3 ic plugin"},
{vsn, "0.1.0"},
{registered, []},
{applications, [kernel, stdlib]},
{env, []}
]}.
8 changes: 8 additions & 0 deletions plugins/ic/src/ic.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-module(ic).

-export([init/1]).

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
{ok, State1} = ic_prv_setup_eunit:init(State),
{ok, State1}.
81 changes: 81 additions & 0 deletions plugins/ic/src/ic_prv_setup_eunit.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
-module(ic_prv_setup_eunit).

-behaviour(provider).

-export([init/1, do/1, format_error/1]).

-define(PROVIDER, setup_eunit).
-define(NAMESPACE, ic).
-define(CWD, filename:absname(rebar_dir:get_cwd())).
-define(TEMPLATE, "setup_eunit").
-define(DEPS, []).

%% ===================================================================
%% Public API
%% ===================================================================
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
Provider = providers:create([
{namespace, ?NAMESPACE},
{name, ?PROVIDER},
{module, ?MODULE},
{bare, true},
{deps, ?DEPS},
{example, "rebar3 ic setup_eunit"},
{opts, [{force, $f, "force", undefined, "overwrite existing files"}]},
{short_desc, "Setup eunit from template"},
{desc, "Setup eunit from template"}
]),
{ok, rebar_state:add_provider(State, Provider)}.

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
build_eunit_config(State),
{ok, State}.

-spec format_error(any()) -> iolist().
format_error(Reason) ->
io_lib:format("~p", [Reason]).

%% ===================================================================
%% Internal functions
%% ===================================================================
build_eunit_config(State) ->
Force = is_forced(State),
DataDir = ?CWD ++ "/tmp/data",
TmpDataDir = ?CWD ++ "/tmp/tmp_data",
cleanup_dirs([DataDir, TmpDataDir]),
AllOpts = [
{template, ?TEMPLATE},
{prefix, ?CWD},
{data_dir, DataDir},
{view_index_dir, DataDir},
{geo_index_dir, DataDir},
{state_dir, TmpDataDir}
],
StateNew = lists:foldl(
fun({Key, Value}, StateAcc) ->
rebar_state:set(StateAcc, Key, Value)
end,
State,
AllOpts
),
ok = rebar_templater:new(?TEMPLATE, [], Force, StateNew).

is_forced(State) ->
{Args, _} = rebar_state:command_parsed_args(State),
case proplists:get_value(force, Args) of
undefined -> false;
_ -> true
end.

cleanup_dirs(Dirs) ->
[del_dir(Dir) || Dir <- Dirs, filelib:is_dir(Dir)].

del_dir(Dir) ->
All = filelib:wildcard(Dir ++ "/**"),
{Dirs, Files} = lists:partition(fun filelib:is_dir/1, All),
lists:foreach(fun file:delete/1, Files),
SortedDirs = lists:sort(fun(A, B) -> length(A) > length(B) end, Dirs),
lists:foreach(fun file:del_dir/1, SortedDirs),
file:del_dir(Dir).
2 changes: 2 additions & 0 deletions rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ os:putenv("COUCHDB_APPS_CONFIG_DIR", filename:join([COUCHDB_ROOT, "rel/apps"])).
AddConfig = [
{require_otp_vsn, "23|24|25"},
{erl_opts, [{i, "../"}, {d, 'COUCHDB_ERLANG_VERSION', VerString}]},
{plugins, [ic, erlfmt]},
{erlfmt, [write]},
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]},
{dialyzer, [
{plt_location, local},
Expand Down
59 changes: 0 additions & 59 deletions rel/plugins/eunit_plugin.erl

This file was deleted.