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@
|
||||
EPMD = @EPMD@
|
||||
IEX = @IEX@
|
||||
EMACS = @EMACS@
|
||||
|
||||
INSTALLUSER=@INSTALLUSER@
|
||||
INSTALLGROUP=@INSTALLGROUP@
|
||||
|
@ -266,11 +267,15 @@ _build/edoc/logo.png: edoc_compile
|
|||
#' format / indent
|
||||
#
|
||||
|
||||
.SILENT: format indent
|
||||
|
||||
FORMAT_LOG=/tmp/ejabberd-format.log
|
||||
|
||||
format:
|
||||
tools/rebar3-format.sh $(REBAR3)
|
||||
tools/rebar3-format.sh $(FORMAT_LOG) $(REBAR3)
|
||||
|
||||
indent:
|
||||
tools/emacs-indent.sh
|
||||
tools/emacs-indent.sh $(FORMAT_LOG) $(EMACS)
|
||||
|
||||
#.
|
||||
#' copy-files
|
||||
|
@ -714,7 +719,7 @@ help:
|
|||
@echo " translations Extract translation files"
|
||||
@echo " TAGS Generate tags file for text editors"
|
||||
@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 ""
|
||||
@echo " dialyzer Run Dialyzer static analyzer"
|
||||
|
|
|
@ -88,6 +88,8 @@ AC_PATH_PROG([ESCRIPT], [escript], [], [$ERLANG_ROOT_DIR/bin])
|
|||
#locating make
|
||||
AC_CHECK_PROG([MAKE], [make], [make], [])
|
||||
|
||||
AC_PATH_TOOL(EMACS, emacs, , [${extra_erl_path}$PATH])
|
||||
|
||||
if test "x$ESCRIPT" = "x"; then
|
||||
AC_MSG_ERROR(['escript' was not found])
|
||||
fi
|
||||
|
|
|
@ -164,7 +164,7 @@
|
|||
{branch, "consolidation_fix"}}}
|
||||
}]}}.
|
||||
{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_not_rebar3, {plugins, [
|
||||
|
|
|
@ -1,18 +1,29 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
# To indent and remove tabs, surround the piece of code with:
|
||||
# %% @indent-begin
|
||||
# %% @indent-end
|
||||
#
|
||||
# Install Emacs and erlang-mode. For example in Debian:
|
||||
# apt-get install emacs erlang-mode
|
||||
#
|
||||
# Then run:
|
||||
# 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
|
||||
echo "==> Indenting $FILENAME..."
|
||||
echo "==> Indenting $FILENAME..." >>$LOG
|
||||
emacs -batch $FILENAME \
|
||||
-f "erlang-mode" \
|
||||
--eval "(goto-char (point-min))" \
|
||||
|
@ -23,5 +34,13 @@ for FILENAME in $FILES; do
|
|||
--eval "(erlang-indent-region begin end)" \
|
||||
--eval "(untabify begin end)" \
|
||||
-f "delete-trailing-whitespace" \
|
||||
-f "save-buffer"
|
||||
-f "save-buffer" >>$LOG 2>&1
|
||||
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:
|
||||
# @format-begin
|
||||
# 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
|
||||
# To format the source code, simply run:
|
||||
# make format
|
||||
|
||||
REBAR=$1
|
||||
LOG=${1:-/tmp/ejabberd-format.log}
|
||||
REBAR3=${2:-rebar3}
|
||||
|
||||
FORMAT()
|
||||
{
|
||||
FPATH=$1
|
||||
ERLS=$(git grep --name-only @format-begin "$FPATH"/)
|
||||
$REBAR3 efmt -w --parallel >$LOG 2>&1
|
||||
|
||||
for ERL in $ERLS; do
|
||||
perl -n -e 'sub o { open(OUT, ">", sprintf("%s-format-%02d", $f, $n++));}; BEGIN{($f)=@ARGV;o()}; o() if /\@format-/; print OUT $_;' $ERL
|
||||
done
|
||||
|
||||
EFMTS=$(find "$FPATH"/*-format-* -type f -exec grep --files-with-matches "@format-begin" '{}' ';')
|
||||
EFMTS2=""
|
||||
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
|
||||
if ! grep -q 'All files were formatted correctly' $LOG
|
||||
then
|
||||
cat $LOG
|
||||
exit 1
|
||||
fi
|
||||
rm $LOG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue