Add "do_${build_system}_all" and "do_build_all"

This commit is contained in:
Jörn-Michael Miehe 2020-02-18 07:58:11 +01:00
parent 078cafdc39
commit 76aa31c0c6
5 changed files with 127 additions and 36 deletions

View file

@ -1,13 +1,13 @@
#!/bin/bash
echo -n "Loading '${0}': "
#
# hard globals
#
g_bin="$(readlink -f "$(which "$0")")"
g_lib=${g_bin/"bin"/"lib"}
declare -a g_build_systems
declare -A g_build_systems_glob
#
# load base program
@ -16,16 +16,19 @@ declare -A g_build_systems_glob
source "${g_lib}/globals"
source "${g_lib}/logging"
source "${g_lib}/handle_inotify"
for plugin in "${g_lib}/plugins/"*".sh"; do
source "${plugin}"
done
echo "program parsed."
#
# MAIN
#
echo "Building everything in '${g_watchroot}'."
do_build_all
echo "Booting '${g_bin}' in '${g_watchroot}'."
echo "Watching '${g_watchroot}'."
# setup inotify:
# -mrq monitor, recursive, quiet
# -e events

View file

@ -1,4 +1,15 @@
#!/bin/bash
# array of available build systems
declare -a g_build_systems
# map of file globs for build systems
declare -A g_build_systems_glob
# map of annotation patterns for build systems
declare -A g_build_systems_annotations
# $WATCHROOT (default: ".")
g_watchroot="$(readlink -f "${1:-.}")"
echo -n "globals ... "

View file

@ -29,7 +29,7 @@ do_compile() { # $DIR $OBJECT $DONE
# build systems
for build_system in ${g_build_systems[@]}; do
do_build_system "${dir}" "${object}" "${build_system}" \
do_build_system "${dir}" "${build_system}" "${object}" \
&& local done="1"
done
@ -44,25 +44,59 @@ do_compile() { # $DIR $OBJECT $DONE
fi
}
# use given BUILD_SYSTEM to process an OBJECT from a DIRectory
do_build_system() { # $DIR $OBJECT $BUILD_SYSTEM
# check if defined source pattern matches OBJECT
do_check_srcpat() { # $DIR $BUILD_DESC $ANNOTATION $OBJECT
# extract params
local dir="$1"
local object="$2"
local build_system="$3"
local build_desc="$2"
local annotation="$3"
local object="$4"
# check 'source pattern'
local srcpat="$(grep -E "^${annotation}" "${dir}/${build_desc}" | tail -n 1 | sed -r "s/^${annotation}\s+//")"
if [ -z "${srcpat}" ]; then
# empty srcpat => fail
logline_append "Empty source pattern, check for '${annotation}' annotation!"
return 1
elif [ -z "${object}" ]; then
# empty object = "no specific object" => success
return 0
elif [[ "${object}" =~ ${srcpat} ]]; then
# nonempty object matches srcpat => success
return 0
else
# nonempty object does not match srcpat => fail
logline_append "SRCPAT '${srcpat}' mismatch."
return 1
fi
}
# use given BUILD_SYSTEM to process an OBJECT from a DIRectory
do_build_system() { # $DIR $BUILD_SYSTEM $OBJECT
# extract params
local dir="$1"
local build_system="$2"
local object="$3"
# not done yet
local result=1
# get glob pattern for plugin
# get glob patterns for plugin
for glob in ${g_build_systems_glob[${build_system}]}; do
# match glob in directory
# match each glob in directory
for file in "${dir}"/${glob}; do
# check file readability
if [ -r "${file}" ]; then
# actually call into build system
logline_append "Found '${file}':"
do_${build_system} "${dir}" "${object}" "$(basename "${file}")" \
local file="$(basename "${file}")"
do_${build_system} "${dir}" "${file}" "${object}" \
&& local result=0
fi
done
@ -70,3 +104,30 @@ do_build_system() { # $DIR $OBJECT $BUILD_SYSTEM
return ${result}
}
# force build using all systems
do_build_all() { #
# build systems
for build_system in ${g_build_systems[@]}; do
echo "Build system '${build_system}'."
for glob in ${g_build_systems_glob[${build_system}]}; do
# match each glob recursively
find "${g_watchroot}" -iname "${glob}" | \
while read file; do
if [ -r "${file}" ]; then
# force call into build system
logline_append "Found '${file}':"
local dir="$(dirname "${file}")"
local file="$(basename "${file}")"
do_${build_system}_all "${dir}" "$(basename "${file}")"
logline_flush
fi
done
done
done
}
echo -n "main ... "

View file

@ -10,3 +10,5 @@ logline_flush() {
echo "${g_logline}"
g_logline=""
}
echo -n "logging ... "

View file

@ -6,40 +6,54 @@ g_build_systems+=(make)
# build instruction file globs for this plugin
g_build_systems_glob[make]="Makefile *.mk"
# compile using bare make command
# srcpat annotation prefix for this plugin
g_build_systems_annotations[make]='#%SRCPAT%'
# try to compile file OBJECT
do_make() { # $DIR $OBJECT $MAKEFILE
# extract params
local dir="$1"
local object="$2"
local makefile="$3"
local makefile="$2"
local object="$3"
# check Makefile 'source pattern'
local srcpat="$(grep -E "^#%SRCPAT%" "${dir}/${makefile}" | tail -n 1 | sed -r "s/^#%SRCPAT%\s+//")"
# only run if "object" is source file
if do_check_srcpat "${dir}" "${makefile}" "${g_build_systems_annotations[make]}" "${object}"; then
do_run_make "${dir}" "${makefile}"
fi
}
if [ -z "${srcpat}" ]; then
logline_append "Empty source pattern, check '#%SRCPAT%' annotation!"
return 1
# try running make for MAKEFILE inside DIRectory
do_make_all() { # $DIR $MAKEFILE
# extract params
local dir="$1"
local makefile="$2"
elif [[ "${object}" =~ ${srcpat} ]]; then
# check for autodoc target
local target="$(grep -E "^autodoc:" "${dir}/${makefile}" | sed -r "s/:.*$//")"
# only run if "makefile" is relevant for autodoc
if do_check_srcpat "${dir}" "${makefile}" "${g_build_systems_annotations[make]}" ""; then
do_run_make "${dir}" "${makefile}"
fi
}
if [ -z "${target}" ]; then
logline_append "Running 'make'!"
else
logline_append "Making '${target}'!"
fi
# actually run GNU Make with MAKEFILE inside DIRectory
do_run_make() { # $DIR $MAKEFILE
# extract params
local dir="$1"
local makefile="$2"
# actually run "make" and save (truncated) output
local makelog="$(make --no-print-directory -C "${dir}" -f "${makefile}" -j ${target})"
logline_append "$(echo "${makelog}" | head -n 10 | sed 's/$/;/g' | tr '\n' ' ' | sed 's/ *$//')"
logline_append "Done."
# check for autodoc target
local target="$(grep -E "^autodoc:" "${dir}/${makefile}" | sed -r "s/:.*$//")"
if [ -z "${target}" ]; then
logline_append "Running 'make'!"
else
logline_append "SRCPAT '${srcpat}' mismatch."
return 1
logline_append "Making '${target}'!"
fi
return 0
# actually run "make" and save (truncated) output
local makelog="$(make --no-print-directory -C "${dir}" -f "${makefile}" -j ${target})"
logline_append "$(echo "${makelog}" | head -n 10 | sed 's/$/;/g' | tr '\n' ' ' | sed 's/ *$//')"
logline_append "Done."
}
echo -n "GNU Make plugin ... "