mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Add Makefile targets to format and indent source code
This commit is contained in:
parent
701d2ce0f6
commit
3bda858225
15
Makefile.in
15
Makefile.in
@ -261,6 +261,16 @@ _build/edoc/docs.md: edoc_compile
|
||||
_build/edoc/logo.png: edoc_compile
|
||||
wget https://docs.ejabberd.im/assets/img/footer_logo_e.png -O _build/edoc/logo.png
|
||||
|
||||
#.
|
||||
#' format / indent
|
||||
#
|
||||
|
||||
format:
|
||||
tools/rebar3-format.sh $(REBAR)
|
||||
|
||||
indent:
|
||||
tools/emacs-indent.sh
|
||||
|
||||
#.
|
||||
#' copy-files
|
||||
#
|
||||
@ -650,7 +660,7 @@ test:
|
||||
.PHONY: src edoc dialyzer Makefile TAGS clean clean-rel distclean prod rel \
|
||||
install uninstall uninstall-binary uninstall-all translations deps test \
|
||||
all dev doap help install-rel relive scripts uninstall-rel update \
|
||||
erlang_plt deps_plt ejabberd_plt xref hooks options
|
||||
erlang_plt deps_plt ejabberd_plt xref hooks options format indent
|
||||
|
||||
#.
|
||||
#' help
|
||||
@ -682,6 +692,9 @@ help:
|
||||
@echo " translations Extract translation files"
|
||||
@echo " TAGS Generate tags file for text editors"
|
||||
@echo ""
|
||||
@echo " format Format source code using rebar3_format [rebar3]"
|
||||
@echo " indent Indent source code using erlang-mode [emacs]"
|
||||
@echo ""
|
||||
@echo " dialyzer Run Dialyzer static analyzer"
|
||||
@echo " hooks Run hooks validator"
|
||||
@echo " test Run Common Tests suite [rebar3]"
|
||||
|
@ -152,7 +152,9 @@
|
||||
{git, "https://github.com/bsanyi/rebar_mix.git",
|
||||
{branch, "consolidation_fix"}}}
|
||||
}]}}.
|
||||
{if_rebar3, {project_plugins, [configure_deps]}}.
|
||||
{if_rebar3, {project_plugins, [configure_deps,
|
||||
{if_var_true, tools, rebar3_format}
|
||||
]}}.
|
||||
{if_not_rebar3, {plugins, [
|
||||
deps_erl_opts, override_deps_versions2, override_opts, configure_deps
|
||||
]}}.
|
||||
|
27
tools/emacs-indent.sh
Executable file
27
tools/emacs-indent.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# To indent and remove tabs, surround the piece of code with:
|
||||
# %% @indent-begin
|
||||
# %% @indent-end
|
||||
#
|
||||
# Then run:
|
||||
# make indent
|
||||
#
|
||||
# Please note this script only indents the first occurrence.
|
||||
|
||||
FILES=$(git grep --name-only @indent-begin src/)
|
||||
|
||||
for FILENAME in $FILES; do
|
||||
echo "==> Indenting $FILENAME..."
|
||||
emacs -batch $FILENAME \
|
||||
-f "erlang-mode" \
|
||||
--eval "(goto-char (point-min))" \
|
||||
--eval "(re-search-forward \"@indent-begin\" nil t)" \
|
||||
--eval "(setq begin (line-beginning-position))" \
|
||||
--eval "(re-search-forward \"@indent-end\" nil t)" \
|
||||
--eval "(setq end (line-beginning-position))" \
|
||||
--eval "(erlang-indent-region begin end)" \
|
||||
--eval "(untabify begin end)" \
|
||||
-f "delete-trailing-whitespace" \
|
||||
-f "save-buffer"
|
||||
done
|
34
tools/rebar3-format.sh
Executable file
34
tools/rebar3-format.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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
|
||||
|
||||
REBAR=$1
|
||||
|
||||
ERLS=$(git grep --name-only @format-begin src/)
|
||||
|
||||
for ERL in $ERLS; do
|
||||
csplit --quiet --prefix=$ERL-format- $ERL /@format-/ "{*}"
|
||||
done
|
||||
|
||||
EFMTS=$(find src/*-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
|
Loading…
Reference in New Issue
Block a user