forked from VoxeLibre/VoxeLibre
tools: remove inline scripting from make-luacheck-files
- the awk script was moved to its own file (deps-to-luacheck.awk) with minor changes, including added commentary, slightly more rigorous error checking, and using a different separator model to avoid a second stage to remove trailing commas - SED_MODCONF2DEPS was moved to a containing function, and commented - the awk command itself is now easier on the eyes
This commit is contained in:
parent
02a8496b5f
commit
b1fbbfdd35
|
@ -0,0 +1,41 @@
|
|||
BEGIN {
|
||||
if (!DIR || !MOD) {
|
||||
printf("error: DIR and MOD must be set.\n");
|
||||
_panic=1;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
printf("files[\"" DIR "\"] = { globals = { \"" MOD "\" }");
|
||||
|
||||
if (!EMPTY) {
|
||||
printf(", read_globals = { ");
|
||||
}
|
||||
};
|
||||
|
||||
# Without a pattern, this will match on empty lines
|
||||
# and mess up the entry. We clean up the extra commas
|
||||
# later in the script.
|
||||
/.+/{
|
||||
# Get rid of the optional (?) mark from
|
||||
# depends.txt entries.
|
||||
sub("?$", "");
|
||||
|
||||
# Some files have CRLF, so get rid of those
|
||||
# too.
|
||||
sub("\xd", "");
|
||||
|
||||
SEP=", ";
|
||||
if (NR == 1) {
|
||||
SEP="";
|
||||
}
|
||||
printf(SEP "\"" $1 "\"");
|
||||
};
|
||||
|
||||
END {
|
||||
if (!_panic) {
|
||||
if (!EMPTY) {
|
||||
printf(" }");
|
||||
}
|
||||
printf(" }\n");
|
||||
}
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
#
|
||||
# make-luacheck-files.sh
|
||||
# v1 - E - Initial version
|
||||
# v2 - E - Remove (most) inline scripts
|
||||
|
||||
set -ue
|
||||
|
||||
|
@ -10,53 +11,27 @@ if [ ! -d "mods" ] || [ ! -r ".luacheck.head" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# We need these to be explicitly NOT expanded.
|
||||
# shellcheck disable=2016
|
||||
{
|
||||
# This creates a luacheckrc-compatible line from a mod (supplied on
|
||||
# the command line with -v MOD="mod_name"), a directory (-v DIR="..."),
|
||||
# and a list of dependencies (via STDIN). The `read_globals` section is
|
||||
# skipped if there are no dependencies (-v EMPTY=1).
|
||||
AWK_DEPS2LCHECK='
|
||||
BEGIN {
|
||||
printf("files[\"" DIR "\"] = { globals = { \"" MOD "\" }");
|
||||
if (!EMPTY) {
|
||||
printf(", read_globals = { ");
|
||||
}
|
||||
};
|
||||
|
||||
# Without a pattern, this will match on empty lines
|
||||
# and mess up the entry. We clean up the extra commas
|
||||
# later in the script.
|
||||
/.+/{
|
||||
sub("?$", "");
|
||||
sub("\xd", "");
|
||||
printf("\"" $1 "\", ");
|
||||
};
|
||||
|
||||
END {
|
||||
if (!EMPTY) {
|
||||
printf("}");
|
||||
}
|
||||
printf(" }\n");
|
||||
};'
|
||||
|
||||
# This takes any line that contains 'depends' and an equal sign
|
||||
# and spits out each (comma-separated) entry on its own line.
|
||||
SED_MODCONF2DEPS='
|
||||
/depends *=/{
|
||||
s/.*depends *=//;
|
||||
s/, ?/\n/g;
|
||||
p;
|
||||
}'
|
||||
|
||||
HEADER='
|
||||
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
|
||||
|
@ -69,7 +44,7 @@ find mods -type d -print | while read -r DIR; do
|
|||
printf "found: %s (%s)\n" "$DIR" "mod.conf" 1>&2
|
||||
# mod.conf needs some more help to get usable
|
||||
# data out of it.
|
||||
DEPS="$(sed -n -r -e "$SED_MODCONF2DEPS" "$DIR/mod.conf")"
|
||||
DEPS="$(modconf2deps < "$DIR/mod.conf")"
|
||||
else
|
||||
# Empty dir, or not a mod dir.
|
||||
continue
|
||||
|
@ -84,10 +59,13 @@ find mods -type d -print | while read -r DIR; do
|
|||
# for the mod name.
|
||||
MOD="${DIR##*/}"
|
||||
|
||||
# Now we run through it through the formatter,
|
||||
# and remove any rogue trailing commas.
|
||||
{ awk -v DIR="$DIR" -v EMPTY="$EMPTY" -v MOD="$MOD" -- "$AWK_DEPS2LCHECK" | sed -e "s/, }/ }/"; } <<-EOF
|
||||
$DEPS
|
||||
# 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
|
||||
|
||||
|
|
Loading…
Reference in New Issue