mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 01:39:35 +02:00
Replace rebar3_format with efmt, improve emacs indentation script
Revert partially "Add Makefile targets to format and indent source code"
This reverts commit 3bda858225
.
This commit is contained in:
parent
4dea2f1eb6
commit
378bf64fd5
5 changed files with 47 additions and 46 deletions
11
Makefile.in
11
Makefile.in
|
@ -13,6 +13,7 @@ SED = @SED@
|
||||||
ERL = @ERL@
|
ERL = @ERL@
|
||||||
EPMD = @EPMD@
|
EPMD = @EPMD@
|
||||||
IEX = @IEX@
|
IEX = @IEX@
|
||||||
|
EMACS = @EMACS@
|
||||||
|
|
||||||
INSTALLUSER=@INSTALLUSER@
|
INSTALLUSER=@INSTALLUSER@
|
||||||
INSTALLGROUP=@INSTALLGROUP@
|
INSTALLGROUP=@INSTALLGROUP@
|
||||||
|
@ -266,11 +267,15 @@ _build/edoc/logo.png: edoc_compile
|
||||||
#' format / indent
|
#' format / indent
|
||||||
#
|
#
|
||||||
|
|
||||||
|
.SILENT: format indent
|
||||||
|
|
||||||
|
FORMAT_LOG=/tmp/ejabberd-format.log
|
||||||
|
|
||||||
format:
|
format:
|
||||||
tools/rebar3-format.sh $(REBAR3)
|
tools/rebar3-format.sh $(FORMAT_LOG) $(REBAR3)
|
||||||
|
|
||||||
indent:
|
indent:
|
||||||
tools/emacs-indent.sh
|
tools/emacs-indent.sh $(FORMAT_LOG) $(EMACS)
|
||||||
|
|
||||||
#.
|
#.
|
||||||
#' copy-files
|
#' copy-files
|
||||||
|
@ -714,7 +719,7 @@ help:
|
||||||
@echo " translations Extract translation files"
|
@echo " translations Extract translation files"
|
||||||
@echo " TAGS Generate tags file for text editors"
|
@echo " TAGS Generate tags file for text editors"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo " format Format source code using rebar3_format"
|
@echo " format Format source code using efmt [rebar3]"
|
||||||
@echo " indent Indent source code using erlang-mode [emacs]"
|
@echo " indent Indent source code using erlang-mode [emacs]"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo " dialyzer Run Dialyzer static analyzer"
|
@echo " dialyzer Run Dialyzer static analyzer"
|
||||||
|
|
|
@ -88,6 +88,8 @@ AC_PATH_PROG([ESCRIPT], [escript], [], [$ERLANG_ROOT_DIR/bin])
|
||||||
#locating make
|
#locating make
|
||||||
AC_CHECK_PROG([MAKE], [make], [make], [])
|
AC_CHECK_PROG([MAKE], [make], [make], [])
|
||||||
|
|
||||||
|
AC_PATH_TOOL(EMACS, emacs, , [${extra_erl_path}$PATH])
|
||||||
|
|
||||||
if test "x$ESCRIPT" = "x"; then
|
if test "x$ESCRIPT" = "x"; then
|
||||||
AC_MSG_ERROR(['escript' was not found])
|
AC_MSG_ERROR(['escript' was not found])
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -164,7 +164,7 @@
|
||||||
{branch, "consolidation_fix"}}}
|
{branch, "consolidation_fix"}}}
|
||||||
}]}}.
|
}]}}.
|
||||||
{if_rebar3, {project_plugins, [configure_deps,
|
{if_rebar3, {project_plugins, [configure_deps,
|
||||||
{if_var_true, tools, rebar3_format},
|
{if_var_true, tools, rebar3_efmt},
|
||||||
{if_var_true, tools, {rebar3_lint, "4.1.1"}}
|
{if_var_true, tools, {rebar3_lint, "4.1.1"}}
|
||||||
]}}.
|
]}}.
|
||||||
{if_not_rebar3, {plugins, [
|
{if_not_rebar3, {plugins, [
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
# To indent and remove tabs, surround the piece of code with:
|
# To indent and remove tabs, surround the piece of code with:
|
||||||
# %% @indent-begin
|
# %% @indent-begin
|
||||||
# %% @indent-end
|
# %% @indent-end
|
||||||
#
|
#
|
||||||
|
# Install Emacs and erlang-mode. For example in Debian:
|
||||||
|
# apt-get install emacs erlang-mode
|
||||||
|
#
|
||||||
# Then run:
|
# Then run:
|
||||||
# make indent
|
# make indent
|
||||||
#
|
#
|
||||||
# Please note this script only indents the first occurrence.
|
# Please note this script only indents the first occurrence per file
|
||||||
|
|
||||||
FILES=$(git grep --name-only @indent-begin src/)
|
FILES=$(git grep --name-only @indent-begin include/ src/)
|
||||||
|
LOG=${1:-/tmp/ejabberd-format.log}
|
||||||
|
EMACS=${2:-emacs}
|
||||||
|
|
||||||
|
if [ ! "$EMACS" ] || [ ! -x "$EMACS" ]
|
||||||
|
then
|
||||||
|
echo "==> Cannot indent source code because Emacs is not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
for FILENAME in $FILES; do
|
for FILENAME in $FILES; do
|
||||||
echo "==> Indenting $FILENAME..."
|
echo "==> Indenting $FILENAME..." >>$LOG
|
||||||
emacs -batch $FILENAME \
|
emacs -batch $FILENAME \
|
||||||
-f "erlang-mode" \
|
-f "erlang-mode" \
|
||||||
--eval "(goto-char (point-min))" \
|
--eval "(goto-char (point-min))" \
|
||||||
|
@ -23,5 +34,13 @@ for FILENAME in $FILES; do
|
||||||
--eval "(erlang-indent-region begin end)" \
|
--eval "(erlang-indent-region begin end)" \
|
||||||
--eval "(untabify begin end)" \
|
--eval "(untabify begin end)" \
|
||||||
-f "delete-trailing-whitespace" \
|
-f "delete-trailing-whitespace" \
|
||||||
-f "save-buffer"
|
-f "save-buffer" >>$LOG 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
grep -q 'Error' $LOG \
|
||||||
|
&& cat $LOG
|
||||||
|
grep -q 'Error: void-function (erlang-mode)' $LOG \
|
||||||
|
&& echo \
|
||||||
|
&& echo "==> Maybe you need to install erlang-mode system package" \
|
||||||
|
&& exit 1
|
||||||
|
rm $LOG
|
||||||
|
|
|
@ -1,41 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
# To start formatting a file, add a line that contains:
|
# To format the source code, simply run:
|
||||||
# @format-begin
|
# make format
|
||||||
# Formatting in that file can later be disabled adding another line with:
|
|
||||||
# @format-end
|
|
||||||
#
|
|
||||||
# It can be reenabled again later in the file.
|
|
||||||
#
|
|
||||||
# Finally, call: make format
|
|
||||||
|
|
||||||
REBAR=$1
|
LOG=${1:-/tmp/ejabberd-format.log}
|
||||||
|
REBAR3=${2:-rebar3}
|
||||||
|
|
||||||
FORMAT()
|
$REBAR3 efmt -w --parallel >$LOG 2>&1
|
||||||
{
|
|
||||||
FPATH=$1
|
|
||||||
ERLS=$(git grep --name-only @format-begin "$FPATH"/)
|
|
||||||
|
|
||||||
for ERL in $ERLS; do
|
if ! grep -q 'All files were formatted correctly' $LOG
|
||||||
perl -n -e 'sub o { open(OUT, ">", sprintf("%s-format-%02d", $f, $n++));}; BEGIN{($f)=@ARGV;o()}; o() if /\@format-/; print OUT $_;' $ERL
|
then
|
||||||
done
|
cat $LOG
|
||||||
|
exit 1
|
||||||
EFMTS=$(find "$FPATH"/*-format-* -type f -exec grep --files-with-matches "@format-begin" '{}' ';')
|
fi
|
||||||
EFMTS2=""
|
rm $LOG
|
||||||
for EFMT in $EFMTS; do
|
|
||||||
EFMTS2="$EFMTS2 --files $EFMT"
|
|
||||||
done
|
|
||||||
$REBAR format $EFMTS2
|
|
||||||
|
|
||||||
for ERL in $ERLS; do
|
|
||||||
SPLITS=$(find $ERL-format-* -type f)
|
|
||||||
rm $ERL
|
|
||||||
for SPLIT in $SPLITS; do
|
|
||||||
cat $SPLIT >> $ERL
|
|
||||||
rm $SPLIT
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
FORMAT src
|
|
||||||
FORMAT test
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue