Mineclonia/tools/make-luacheck-files.sh

74 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
#
# make-luacheck-files.sh
# v1 - E - Initial version
# v2 - E - Remove (most) inline scripts
set -ue
if [ ! -d "mods" ] || [ ! -r ".luacheck.head" ]; then
printf "error: this script needs to be run from the mineclonia project root\n" 1>&2
exit 1
fi
HEADER='
-------------------------------------------------------------------
-- THIS FILE WAS AUTOGENERATED BY tools/make-luacheck-files.sh ! --
-- DO NOT EDIT BY HAND. YOUR CHANGES WILL BE LOST NEXT RUN! --
-------------------------------------------------------------------
'
# This takes any line that contains 'depends' and an equal sign
# and spits out each (comma-separated) entry on its own line.
modconf2deps() {
sed -n -r -e '
# Match any lines like "depends = asdfada"
/depends *=/{
# Get rid of the "depends =" part
s/.*depends *=//;
# Convert commas to newlines
s/, */\n/g;
# Record the output
p;
}'
}
find mods -type d -print | while read -r DIR; do
if [ -r "$DIR/depends.txt" ]; then
printf "found: %s (%s)\n" "$DIR" "depends.txt" 1>&2
# depends.txt is a simple newline-delimited file,
# so we can just read it in.
DEPS="$(cat "$DIR/depends.txt")"
elif [ -r "$DIR/mod.conf" ]; then
printf "found: %s (%s)\n" "$DIR" "mod.conf" 1>&2
# mod.conf needs some more help to get usable
# data out of it.
DEPS="$(modconf2deps < "$DIR/mod.conf")"
else
# Empty dir, or not a mod dir.
continue
fi
EMPTY=0
if [ -z "$DEPS" ]; then
EMPTY=1
fi
# Get only the last chunk of the directory
# for the mod name.
MOD="${DIR##*/}"
# Now we run through it through the formatter
awk \
-v DIR="$DIR" \
-v EMPTY="$EMPTY" \
-v MOD="$MOD" \
-f tools/deps-to-luacheck.awk <<-EOF
$DEPS
EOF
done > .luacheck.files
# Put the final thing together with the warning header
{ printf "%s" "$HEADER"; cat .luacheck.head .luacheck.files; } > .luacheckrc