mirror of
https://github.com/ldericher/autodoc.git
synced 2025-12-06 15:43:01 +00:00
split into script collection
This commit is contained in:
parent
6413a4b568
commit
67aef64bec
7 changed files with 122 additions and 105 deletions
|
|
@ -4,7 +4,6 @@ RUN apt-get update && apt-get -y install \
|
||||||
inotify-tools \
|
inotify-tools \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY autodoc /usr/local/bin/autodoc
|
COPY usr /usr
|
||||||
RUN chmod +x /usr/local/bin/autodoc
|
|
||||||
|
|
||||||
CMD ["autodoc"]
|
CMD ["autodoc"]
|
||||||
|
|
|
||||||
102
build/autodoc
102
build/autodoc
|
|
@ -1,102 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# $1:WATCHROOT (default: ".")
|
|
||||||
g_watchroot="$(readlink -f "${1:-.}")"
|
|
||||||
|
|
||||||
# compile using bare make command
|
|
||||||
do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT
|
|
||||||
# extract params
|
|
||||||
local dir="$1"
|
|
||||||
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+//")"
|
|
||||||
|
|
||||||
if [ -z "${srcpat}" ]; then
|
|
||||||
echo -n "Empty source pattern, check '#%SRCPAT%' annotation! "
|
|
||||||
return 1
|
|
||||||
|
|
||||||
elif [[ "${object}" =~ ${srcpat} ]]; then
|
|
||||||
# check for autodoc target
|
|
||||||
local target="$(grep -E "^autodoc:" "${dir}/${makefile}" | sed -r "s/:.*$//")"
|
|
||||||
|
|
||||||
if [ -z "${target}" ]; then
|
|
||||||
echo "Running 'make'. "
|
|
||||||
else
|
|
||||||
echo "Making '${target}'. "
|
|
||||||
fi
|
|
||||||
|
|
||||||
make --no-print-directory -C "${dir}" -j ${target}
|
|
||||||
|
|
||||||
else
|
|
||||||
echo -n "SRCPAT '${srcpat}' mismatch. "
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# compile a directory
|
|
||||||
do_compile() { # $1:DIR $2:OBJECT $3:DONE
|
|
||||||
# extract params
|
|
||||||
local dir="$1"
|
|
||||||
local object="$2"
|
|
||||||
local done="${3:-0}"
|
|
||||||
|
|
||||||
# build systems
|
|
||||||
|
|
||||||
if [ -r "${dir}/Makefile" ]; then
|
|
||||||
# Makefile found
|
|
||||||
echo -n "Found '${dir}/Makefile': "
|
|
||||||
do_make "${dir}" "Makefile" "${object}" \
|
|
||||||
&& local done="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# never leave $g_watchroot
|
|
||||||
if [ "${dir}" != "${g_watchroot}" ]; then
|
|
||||||
# search parent dir for more build instructions
|
|
||||||
do_compile "$(dirname "${dir}")" "${object}" "${done}"
|
|
||||||
|
|
||||||
elif [ "${done}" == "0" ]; then
|
|
||||||
# hit $g_watchroot
|
|
||||||
echo "No build instructions 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 "$*")"
|
|
||||||
|
|
||||||
if [[ "${flags}" =~ "ISDIR" ]]; then
|
|
||||||
# object refers to directory
|
|
||||||
local dir="${dir}/${object}"
|
|
||||||
local object="."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# start using toolchain
|
|
||||||
echo -n "'${object}': '${flags}' in '${dir}'. "
|
|
||||||
do_compile "${dir}" "${object}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# MAIN
|
|
||||||
#
|
|
||||||
|
|
||||||
echo "Booting ${0} in '${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
|
|
||||||
34
build/usr/local/bin/autodoc
Executable file
34
build/usr/local/bin/autodoc
Executable file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# hard globals
|
||||||
|
#
|
||||||
|
|
||||||
|
g_bin="$(readlink -f "$(which "$0")")"
|
||||||
|
g_lib=${g_bin/"bin"/"lib"}
|
||||||
|
|
||||||
|
#
|
||||||
|
# load base program
|
||||||
|
#
|
||||||
|
|
||||||
|
source "${g_lib}/globals"
|
||||||
|
source "${g_lib}/plugin_"*
|
||||||
|
source "${g_lib}/handle_inotify"
|
||||||
|
|
||||||
|
#
|
||||||
|
# MAIN
|
||||||
|
#
|
||||||
|
|
||||||
|
echo "Booting '${g_bin}' in '${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 NOTIFICATION; do
|
||||||
|
do_handle ${NOTIFICATION}
|
||||||
|
done
|
||||||
4
build/usr/local/lib/autodoc/globals
Normal file
4
build/usr/local/lib/autodoc/globals
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# $1:WATCHROOT (default: ".")
|
||||||
|
g_watchroot="$(readlink -f "${1:-.}")"
|
||||||
46
build/usr/local/lib/autodoc/handle_inotify
Normal file
46
build/usr/local/lib/autodoc/handle_inotify
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# compile a directory
|
||||||
|
do_compile() { # $1:DIR $2:OBJECT $3:DONE
|
||||||
|
# extract params
|
||||||
|
local dir="$1"
|
||||||
|
local object="$2"
|
||||||
|
local done="${3:-0}"
|
||||||
|
|
||||||
|
# build systems
|
||||||
|
if [ -r "${dir}/Makefile" ]; then
|
||||||
|
# Makefile found
|
||||||
|
echo -n "Found '${dir}/Makefile': "
|
||||||
|
do_make "${dir}" "Makefile" "${object}" \
|
||||||
|
&& local done="1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# never leave $g_watchroot
|
||||||
|
if [ "${dir}" != "${g_watchroot}" ]; then
|
||||||
|
# search parent dir for more build instructions
|
||||||
|
do_compile "$(dirname "${dir}")" "${object}" "${done}"
|
||||||
|
|
||||||
|
elif [ "${done}" == "0" ]; then
|
||||||
|
# hit $g_watchroot
|
||||||
|
echo "No build instructions 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 "$*")"
|
||||||
|
|
||||||
|
if [[ "${flags}" =~ "ISDIR" ]]; then
|
||||||
|
# object refers to directory
|
||||||
|
local dir="${dir}/${object}"
|
||||||
|
local object="."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# start using toolchain
|
||||||
|
echo -n "'${object}': '${flags}' in '${dir}'. "
|
||||||
|
do_compile "${dir}" "${object}"
|
||||||
|
}
|
||||||
35
build/usr/local/lib/autodoc/plugin_make
Normal file
35
build/usr/local/lib/autodoc/plugin_make
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# compile using bare make command
|
||||||
|
do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT
|
||||||
|
# extract params
|
||||||
|
local dir="$1"
|
||||||
|
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+//")"
|
||||||
|
|
||||||
|
if [ -z "${srcpat}" ]; then
|
||||||
|
echo -n "Empty source pattern, check '#%SRCPAT%' annotation! "
|
||||||
|
return 1
|
||||||
|
|
||||||
|
elif [[ "${object}" =~ ${srcpat} ]]; then
|
||||||
|
# check for autodoc target
|
||||||
|
local target="$(grep -E "^autodoc:" "${dir}/${makefile}" | sed -r "s/:.*$//")"
|
||||||
|
|
||||||
|
if [ -z "${target}" ]; then
|
||||||
|
echo "Running 'make'. "
|
||||||
|
else
|
||||||
|
echo "Making '${target}'. "
|
||||||
|
fi
|
||||||
|
|
||||||
|
make --no-print-directory -C "${dir}" -j ${target}
|
||||||
|
|
||||||
|
else
|
||||||
|
echo -n "SRCPAT '${srcpat}' mismatch. "
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
@ -14,5 +14,6 @@ services:
|
||||||
command: "bash"
|
command: "bash"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- "${PWD}/build/autodoc:/usr/local/bin/autodoc:ro"
|
- "${PWD}/build/usr/local/bin/autodoc:/usr/local/bin/autodoc:ro"
|
||||||
|
- "${PWD}/build/usr/local/lib/autodoc:/usr/local/lib/autodoc:ro"
|
||||||
- "${PWD}/examples:/docs"
|
- "${PWD}/examples:/docs"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue