mirror of
https://github.com/ldericher/autodoc.git
synced 2025-12-06 15:43:01 +00:00
initial commit
This commit is contained in:
commit
efc609d087
2 changed files with 95 additions and 0 deletions
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
FROM ldericher/pandocker:latest
|
||||
|
||||
RUN apt-get update && apt-get -y install \
|
||||
inotify-tools \
|
||||
lsof \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY autodoc.sh /usr/local/bin/autodoc
|
||||
RUN chmod +x /usr/local/bin/autodoc
|
||||
86
autodoc.sh
Executable file
86
autodoc.sh
Executable file
|
|
@ -0,0 +1,86 @@
|
|||
#!/bin/bash
|
||||
|
||||
# $1:WATCHROOT (default: ".")
|
||||
g_watchroot="$(readlink -f "${1:-.}")"
|
||||
|
||||
# compile using bare make command
|
||||
do_make() { # $1:DIR $2:OBJECT
|
||||
# extract params
|
||||
local dir="$1"
|
||||
local object="$2"
|
||||
|
||||
# enter build directory
|
||||
local olddir="$(pwd)"
|
||||
cd "${dir}"
|
||||
|
||||
# extract Makefile 'source pattern'
|
||||
local srcpat="$(grep -E "^#@SRCPAT" Makefile | sed -r "s/^#@SRCPAT\s+//")"
|
||||
|
||||
if [ -z "${srcpat}" ]; then
|
||||
echo "Empty source pattern! Make sure Makefile has '#@SRCPAT' annotation!"
|
||||
elif [[ "${object}" =~ ${srcpat} ]]; then
|
||||
make -j # source pattern matched
|
||||
else
|
||||
echo "'${object}' does not match source pattern '${srcpat}'!"
|
||||
fi
|
||||
|
||||
cd "${olddir}"
|
||||
}
|
||||
|
||||
# compile a directory
|
||||
do_compile() { # $1:DIR $2:OBJECT
|
||||
# extract params
|
||||
local dir="$1"
|
||||
local object="$2"
|
||||
|
||||
# compile using Makefile
|
||||
if [ -e "${dir}/Makefile" ]; then
|
||||
echo "Using '${dir}/Makefile'."
|
||||
do_make "${dir}" "${object}"
|
||||
|
||||
# compile parent dir if not in g_watchroot
|
||||
elif [ "${dir}" != "${g_watchroot}" ]; then
|
||||
do_compile "$(dirname "${dir}")" "${object}"
|
||||
|
||||
# stop otherwise
|
||||
else
|
||||
echo "No compile description found!"
|
||||
fi
|
||||
}
|
||||
|
||||
# process an inotify event
|
||||
do_handle() { # $1:FLAGS $2:OBJECT
|
||||
# extract params
|
||||
local flags="$1"
|
||||
shift 1
|
||||
local dir="$(dirname "$*")"
|
||||
local object="$(basename "$*")"
|
||||
|
||||
# object refers to directory
|
||||
if [[ "${flags}" =~ "ISDIR" ]]; then
|
||||
local dir="${dir}/${object}"
|
||||
local object="."
|
||||
fi
|
||||
|
||||
# use toolchain
|
||||
echo -n "Flags '${flags}' for '${dir}/${object}' ... "
|
||||
do_compile "${dir}" "${object}"
|
||||
}
|
||||
|
||||
#
|
||||
# MAIN
|
||||
#
|
||||
|
||||
echo "watching '${g_watchroot}' ..."
|
||||
# setup inotify:
|
||||
# -mrq monitor, recursive, quiet
|
||||
# -e events
|
||||
# --format %e eventlist csv, %w workdir, %f filename
|
||||
inotifywait -mrq \
|
||||
-e create -e delete -e moved_to -e close_write \
|
||||
--format '%e %w%f' \
|
||||
"${g_watchroot}" | \
|
||||
\
|
||||
while read FILE; do
|
||||
do_handle ${FILE}
|
||||
done
|
||||
Loading…
Reference in a new issue