From 26bf64d34d97846a9b9220ef9e527b63b976763a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 11:48:09 +0200 Subject: [PATCH 01/11] @SRCPAT -> %SRCPAT% --- README.md | 2 +- build/autodoc.sh | 4 ++-- example_docs/simple md/Makefile | 2 +- example_docs/somedir/Makefile | 2 +- example_docs/somedir/a directory in space/Makefile | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 888aa97..5a43537 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ You may combine build instruction systems to your liking. However, Makefiles must contain a SRCPAT annotation comment as follows, where `` is a source pattern as above. ```Makefile -#@SRCPAT +#%SRCPAT% ``` If there are multiple SRCPAT annotations, the lowermost one will be used. diff --git a/build/autodoc.sh b/build/autodoc.sh index 312e036..e199e5a 100755 --- a/build/autodoc.sh +++ b/build/autodoc.sh @@ -11,10 +11,10 @@ do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT local object="$3" # check Makefile 'source pattern' - local srcpat="$(grep -E "^#@SRCPAT" "${dir}/${makefile}" | tail -n 1 | sed -r "s/^#@SRCPAT\s+//")" + 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! " + echo -n "Empty source pattern, check '#%SRCPAT%' annotation! " return 1 elif [[ "${object}" =~ ${srcpat} ]]; then diff --git a/example_docs/simple md/Makefile b/example_docs/simple md/Makefile index 5042f01..6902e49 100644 --- a/example_docs/simple md/Makefile +++ b/example_docs/simple md/Makefile @@ -1,4 +1,4 @@ -#@SRCPAT \.md$ +#%SRCPAT% \.md$ .PHONY: all all: simple.pdf simple.html diff --git a/example_docs/somedir/Makefile b/example_docs/somedir/Makefile index 52668e7..a7b1d27 100644 --- a/example_docs/somedir/Makefile +++ b/example_docs/somedir/Makefile @@ -1,4 +1,4 @@ -#@SRCPAT (file|\.tex)$ +#%SRCPAT% (file|\.tex)$ .PHONY: all all: files.txt diff --git a/example_docs/somedir/a directory in space/Makefile b/example_docs/somedir/a directory in space/Makefile index e435afe..b358204 100644 --- a/example_docs/somedir/a directory in space/Makefile +++ b/example_docs/somedir/a directory in space/Makefile @@ -1,4 +1,4 @@ -#@SRCPAT .* +#%SRCPAT% .* .PHONY: all all: From de336d3a73d2569c3d8caab434d1a74e8e6127bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 11:53:22 +0200 Subject: [PATCH 02/11] main script rename in repo --- build/Dockerfile | 2 +- build/{autodoc.sh => autodoc} | 0 docker-compose.yml | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename build/{autodoc.sh => autodoc} (100%) diff --git a/build/Dockerfile b/build/Dockerfile index 0c0b8db..48b8413 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -4,7 +4,7 @@ RUN apt-get update && apt-get -y install \ inotify-tools \ && rm -rf /var/lib/apt/lists/* -COPY autodoc.sh /usr/local/bin/autodoc +COPY autodoc /usr/local/bin/autodoc RUN chmod +x /usr/local/bin/autodoc CMD ["autodoc"] diff --git a/build/autodoc.sh b/build/autodoc similarity index 100% rename from build/autodoc.sh rename to build/autodoc diff --git a/docker-compose.yml b/docker-compose.yml index d89ccb7..606a0c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,5 +14,5 @@ services: command: "bash" volumes: - - "${PWD}/build/autodoc.sh:/usr/local/bin/autodoc:ro" - "${PWD}/example_docs:/docs" + - "${PWD}/build/autodoc:/usr/local/bin/autodoc:ro" From 6413a4b568665a8218ab3e1c3c1817a0a5d478e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 11:53:51 +0200 Subject: [PATCH 03/11] example_docs -> examples --- README.md | 2 +- docker-compose.yml | 2 +- .../somedir => examples/automatic directory listing}/.gitignore | 0 .../somedir => examples/automatic directory listing}/Makefile | 0 .../automatic directory listing}/a directory in space/Fishfile | 0 .../automatic directory listing}/a directory in space/Makefile | 0 .../automatic directory listing}/fake latex file.tex | 0 {example_docs => examples}/simple md/.gitignore | 0 {example_docs => examples}/simple md/Makefile | 0 {example_docs => examples}/simple md/simple.md | 0 .../unrelated file.txt => examples/unbuildable file.txt | 0 11 files changed, 2 insertions(+), 2 deletions(-) rename {example_docs/somedir => examples/automatic directory listing}/.gitignore (100%) rename {example_docs/somedir => examples/automatic directory listing}/Makefile (100%) rename {example_docs/somedir => examples/automatic directory listing}/a directory in space/Fishfile (100%) rename {example_docs/somedir => examples/automatic directory listing}/a directory in space/Makefile (100%) rename {example_docs/somedir => examples/automatic directory listing}/fake latex file.tex (100%) rename {example_docs => examples}/simple md/.gitignore (100%) rename {example_docs => examples}/simple md/Makefile (100%) rename {example_docs => examples}/simple md/simple.md (100%) rename example_docs/unrelated file.txt => examples/unbuildable file.txt (100%) diff --git a/README.md b/README.md index 5a43537..d91246d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The `autodoc` image [available on Docker Hub](https://hub.docker.com/r/ldericher 01. Install [Docker CE](https://docs.docker.com/install/) -01. Clone or download the `autodoc` repository, open a terminal inside the [example_docs](https://github.com/ldericher/autodoc/tree/master/example_docs) directory +01. Clone or download the `autodoc` repository, open a terminal inside the [examples](https://github.com/ldericher/autodoc/tree/master/examples) directory 01. Deploy an `autodoc` container: diff --git a/docker-compose.yml b/docker-compose.yml index 606a0c0..426315c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,5 +14,5 @@ services: command: "bash" volumes: - - "${PWD}/example_docs:/docs" - "${PWD}/build/autodoc:/usr/local/bin/autodoc:ro" + - "${PWD}/examples:/docs" diff --git a/example_docs/somedir/.gitignore b/examples/automatic directory listing/.gitignore similarity index 100% rename from example_docs/somedir/.gitignore rename to examples/automatic directory listing/.gitignore diff --git a/example_docs/somedir/Makefile b/examples/automatic directory listing/Makefile similarity index 100% rename from example_docs/somedir/Makefile rename to examples/automatic directory listing/Makefile diff --git a/example_docs/somedir/a directory in space/Fishfile b/examples/automatic directory listing/a directory in space/Fishfile similarity index 100% rename from example_docs/somedir/a directory in space/Fishfile rename to examples/automatic directory listing/a directory in space/Fishfile diff --git a/example_docs/somedir/a directory in space/Makefile b/examples/automatic directory listing/a directory in space/Makefile similarity index 100% rename from example_docs/somedir/a directory in space/Makefile rename to examples/automatic directory listing/a directory in space/Makefile diff --git a/example_docs/somedir/fake latex file.tex b/examples/automatic directory listing/fake latex file.tex similarity index 100% rename from example_docs/somedir/fake latex file.tex rename to examples/automatic directory listing/fake latex file.tex diff --git a/example_docs/simple md/.gitignore b/examples/simple md/.gitignore similarity index 100% rename from example_docs/simple md/.gitignore rename to examples/simple md/.gitignore diff --git a/example_docs/simple md/Makefile b/examples/simple md/Makefile similarity index 100% rename from example_docs/simple md/Makefile rename to examples/simple md/Makefile diff --git a/example_docs/simple md/simple.md b/examples/simple md/simple.md similarity index 100% rename from example_docs/simple md/simple.md rename to examples/simple md/simple.md diff --git a/example_docs/unrelated file.txt b/examples/unbuildable file.txt similarity index 100% rename from example_docs/unrelated file.txt rename to examples/unbuildable file.txt From 67aef64bec770b8821f5f564e083bfdd3502ec61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 13:16:36 +0200 Subject: [PATCH 04/11] split into script collection --- build/Dockerfile | 3 +- build/autodoc | 102 --------------------- build/usr/local/bin/autodoc | 34 +++++++ build/usr/local/lib/autodoc/globals | 4 + build/usr/local/lib/autodoc/handle_inotify | 46 ++++++++++ build/usr/local/lib/autodoc/plugin_make | 35 +++++++ docker-compose.yml | 3 +- 7 files changed, 122 insertions(+), 105 deletions(-) delete mode 100755 build/autodoc create mode 100755 build/usr/local/bin/autodoc create mode 100644 build/usr/local/lib/autodoc/globals create mode 100644 build/usr/local/lib/autodoc/handle_inotify create mode 100644 build/usr/local/lib/autodoc/plugin_make diff --git a/build/Dockerfile b/build/Dockerfile index 48b8413..c014a7a 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -4,7 +4,6 @@ RUN apt-get update && apt-get -y install \ inotify-tools \ && rm -rf /var/lib/apt/lists/* -COPY autodoc /usr/local/bin/autodoc -RUN chmod +x /usr/local/bin/autodoc +COPY usr /usr CMD ["autodoc"] diff --git a/build/autodoc b/build/autodoc deleted file mode 100755 index e199e5a..0000000 --- a/build/autodoc +++ /dev/null @@ -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 diff --git a/build/usr/local/bin/autodoc b/build/usr/local/bin/autodoc new file mode 100755 index 0000000..7a643db --- /dev/null +++ b/build/usr/local/bin/autodoc @@ -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 diff --git a/build/usr/local/lib/autodoc/globals b/build/usr/local/lib/autodoc/globals new file mode 100644 index 0000000..ec8cefe --- /dev/null +++ b/build/usr/local/lib/autodoc/globals @@ -0,0 +1,4 @@ +#!/bin/bash + +# $1:WATCHROOT (default: ".") +g_watchroot="$(readlink -f "${1:-.}")" diff --git a/build/usr/local/lib/autodoc/handle_inotify b/build/usr/local/lib/autodoc/handle_inotify new file mode 100644 index 0000000..4146201 --- /dev/null +++ b/build/usr/local/lib/autodoc/handle_inotify @@ -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}" +} diff --git a/build/usr/local/lib/autodoc/plugin_make b/build/usr/local/lib/autodoc/plugin_make new file mode 100644 index 0000000..b9d215a --- /dev/null +++ b/build/usr/local/lib/autodoc/plugin_make @@ -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 +} diff --git a/docker-compose.yml b/docker-compose.yml index 426315c..e51149f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,5 +14,6 @@ services: command: "bash" 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" From 152beeb5a5abfdfb765a64ac6ff1738911098580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 13:40:46 +0200 Subject: [PATCH 05/11] handling wirh plugins --- build/usr/local/bin/autodoc | 1 + build/usr/local/lib/autodoc/handle_inotify | 10 ++++------ build/usr/local/lib/autodoc/plugin_make | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/build/usr/local/bin/autodoc b/build/usr/local/bin/autodoc index 7a643db..0ceaf32 100755 --- a/build/usr/local/bin/autodoc +++ b/build/usr/local/bin/autodoc @@ -6,6 +6,7 @@ g_bin="$(readlink -f "$(which "$0")")" g_lib=${g_bin/"bin"/"lib"} +declare -a g_plugins # # load base program diff --git a/build/usr/local/lib/autodoc/handle_inotify b/build/usr/local/lib/autodoc/handle_inotify index 4146201..d199ff2 100644 --- a/build/usr/local/lib/autodoc/handle_inotify +++ b/build/usr/local/lib/autodoc/handle_inotify @@ -7,13 +7,11 @@ do_compile() { # $1:DIR $2:OBJECT $3:DONE 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}" \ + # build plugins + for plugin in ${g_plugins[@]}; do + try_${plugin} "${dir}" "${object}" \ && local done="1" - fi + done # never leave $g_watchroot if [ "${dir}" != "${g_watchroot}" ]; then diff --git a/build/usr/local/lib/autodoc/plugin_make b/build/usr/local/lib/autodoc/plugin_make index b9d215a..7b4d1d1 100644 --- a/build/usr/local/lib/autodoc/plugin_make +++ b/build/usr/local/lib/autodoc/plugin_make @@ -1,5 +1,7 @@ #!/bin/bash +g_plugins+=(make) + # compile using bare make command do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT # extract params @@ -24,7 +26,7 @@ do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT echo "Making '${target}'. " fi - make --no-print-directory -C "${dir}" -j ${target} + make --no-print-directory -C "${dir}" -f "${makefile}" -j ${target} else echo -n "SRCPAT '${srcpat}' mismatch. " @@ -33,3 +35,21 @@ do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT return 0 } + +try_make() { # $1:DIR $2:OBJECT + # extract params + local dir="$1" + local object="$2" + local retval=1 + + for FILE in "${dir}"/Makefile "${dir}"/*.mk; do + if [ -r "${FILE}" ]; then + echo -n "Found '${FILE}': " + do_make "${dir}" "$(basename "${FILE}")" "${object}" \ + && local retval=0 + echo "" + fi + done + + return ${retval} +} From 08c1a7e62b2aa6045111aaa15465847a3b32072d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 13:43:28 +0200 Subject: [PATCH 06/11] plugins location --- build/usr/local/bin/autodoc | 2 +- build/usr/local/lib/autodoc/{plugin_make => plugins/make.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename build/usr/local/lib/autodoc/{plugin_make => plugins/make.sh} (100%) diff --git a/build/usr/local/bin/autodoc b/build/usr/local/bin/autodoc index 0ceaf32..cc43353 100755 --- a/build/usr/local/bin/autodoc +++ b/build/usr/local/bin/autodoc @@ -13,7 +13,7 @@ declare -a g_plugins # source "${g_lib}/globals" -source "${g_lib}/plugin_"* +source "${g_lib}/plugins/"*".sh" source "${g_lib}/handle_inotify" # diff --git a/build/usr/local/lib/autodoc/plugin_make b/build/usr/local/lib/autodoc/plugins/make.sh similarity index 100% rename from build/usr/local/lib/autodoc/plugin_make rename to build/usr/local/lib/autodoc/plugins/make.sh From d7f6a1fb8de8f0a5fc00bc63f78d764b8962c71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 13:46:15 +0200 Subject: [PATCH 07/11] plugins -> build systems --- build/usr/local/bin/autodoc | 2 +- build/usr/local/lib/autodoc/handle_inotify | 6 +++--- build/usr/local/lib/autodoc/plugins/make.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/usr/local/bin/autodoc b/build/usr/local/bin/autodoc index cc43353..7677144 100755 --- a/build/usr/local/bin/autodoc +++ b/build/usr/local/bin/autodoc @@ -6,7 +6,7 @@ g_bin="$(readlink -f "$(which "$0")")" g_lib=${g_bin/"bin"/"lib"} -declare -a g_plugins +declare -a g_build_systems # # load base program diff --git a/build/usr/local/lib/autodoc/handle_inotify b/build/usr/local/lib/autodoc/handle_inotify index d199ff2..1637f4a 100644 --- a/build/usr/local/lib/autodoc/handle_inotify +++ b/build/usr/local/lib/autodoc/handle_inotify @@ -7,9 +7,9 @@ do_compile() { # $1:DIR $2:OBJECT $3:DONE local object="$2" local done="${3:-0}" - # build plugins - for plugin in ${g_plugins[@]}; do - try_${plugin} "${dir}" "${object}" \ + # build systems + for build_system in ${g_build_systems[@]}; do + try_${build_system} "${dir}" "${object}" \ && local done="1" done diff --git a/build/usr/local/lib/autodoc/plugins/make.sh b/build/usr/local/lib/autodoc/plugins/make.sh index 7b4d1d1..af34c12 100644 --- a/build/usr/local/lib/autodoc/plugins/make.sh +++ b/build/usr/local/lib/autodoc/plugins/make.sh @@ -1,6 +1,6 @@ #!/bin/bash -g_plugins+=(make) +g_build_systems+=(make) # compile using bare make command do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT From 66731ee148e830e75bb0602c3b13c21185008d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 14:12:06 +0200 Subject: [PATCH 08/11] do_build_system global function --- build/usr/local/bin/autodoc | 1 + build/usr/local/lib/autodoc/handle_inotify | 76 ++++++++++++++------- build/usr/local/lib/autodoc/plugins/make.sh | 28 ++------ 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/build/usr/local/bin/autodoc b/build/usr/local/bin/autodoc index 7677144..a9a33f2 100755 --- a/build/usr/local/bin/autodoc +++ b/build/usr/local/bin/autodoc @@ -7,6 +7,7 @@ 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 diff --git a/build/usr/local/lib/autodoc/handle_inotify b/build/usr/local/lib/autodoc/handle_inotify index 1637f4a..97d751f 100644 --- a/build/usr/local/lib/autodoc/handle_inotify +++ b/build/usr/local/lib/autodoc/handle_inotify @@ -1,29 +1,5 @@ #!/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 - for build_system in ${g_build_systems[@]}; do - try_${build_system} "${dir}" "${object}" \ - && local done="1" - done - - # 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 @@ -42,3 +18,55 @@ do_handle() { # $1:FLAGS $2:OBJECT echo -n "'${object}': '${flags}' in '${dir}'. " do_compile "${dir}" "${object}" } + +# 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 + for build_system in ${g_build_systems[@]}; do + do_build_system "${build_system}" "${dir}" "${object}" \ + && local done="1" + done + + # 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 +} + +# use given BUILD_SYSTEM to process an OBJECT from a DIRectory +do_build_system() { # $1:BUILD_SYSTEM $2:DIR $3:OBJECT + # extract params + local build_system="$1" + local dir="$2" + local object="$3" + + # not done yet + local result=1 + + # get glob pattern for plugin + for glob in ${g_build_systems_glob[${build_system}]}; do + # match glob in directory + for file in "${dir}"/${glob}; do + # check file readability + if [ -r "${file}" ]; then + # actually call into build system + echo -n "Found '${file}': " + do_${build_system} "$(basename "${file}")" "${dir}" "${object}" \ + && local result=0 + echo "" + fi + done + done + + return ${result} +} diff --git a/build/usr/local/lib/autodoc/plugins/make.sh b/build/usr/local/lib/autodoc/plugins/make.sh index af34c12..f150b9f 100644 --- a/build/usr/local/lib/autodoc/plugins/make.sh +++ b/build/usr/local/lib/autodoc/plugins/make.sh @@ -1,12 +1,16 @@ #!/bin/bash +# plugin name g_build_systems+=(make) +# build instruction file globs for this plugin +g_build_systems_glob[make]="Makefile *.mk" + # compile using bare make command -do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT +do_make() { # $1:MAKEFILE $2:DIR $3:OBJECT # extract params - local dir="$1" - local makefile="$2" + local makefile="$1" + local dir="$2" local object="$3" # check Makefile 'source pattern' @@ -35,21 +39,3 @@ do_make() { # $1:DIR $2:MAKEFILE $3:OBJECT return 0 } - -try_make() { # $1:DIR $2:OBJECT - # extract params - local dir="$1" - local object="$2" - local retval=1 - - for FILE in "${dir}"/Makefile "${dir}"/*.mk; do - if [ -r "${FILE}" ]; then - echo -n "Found '${FILE}': " - do_make "${dir}" "$(basename "${FILE}")" "${object}" \ - && local retval=0 - echo "" - fi - done - - return ${retval} -} From 7e6d46244f8270e9827bc0b6441886208e79f985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 14:20:37 +0200 Subject: [PATCH 09/11] $DIR $OBJECT ... --- build/usr/local/lib/autodoc/globals | 2 +- build/usr/local/lib/autodoc/handle_inotify | 18 +++++++++--------- build/usr/local/lib/autodoc/plugins/make.sh | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build/usr/local/lib/autodoc/globals b/build/usr/local/lib/autodoc/globals index ec8cefe..bbe9c83 100644 --- a/build/usr/local/lib/autodoc/globals +++ b/build/usr/local/lib/autodoc/globals @@ -1,4 +1,4 @@ #!/bin/bash -# $1:WATCHROOT (default: ".") +# $WATCHROOT (default: ".") g_watchroot="$(readlink -f "${1:-.}")" diff --git a/build/usr/local/lib/autodoc/handle_inotify b/build/usr/local/lib/autodoc/handle_inotify index 97d751f..6429c36 100644 --- a/build/usr/local/lib/autodoc/handle_inotify +++ b/build/usr/local/lib/autodoc/handle_inotify @@ -1,7 +1,7 @@ #!/bin/bash # process an inotify event -do_handle() { # $1:FLAGS $2:OBJECT +do_handle() { # $FLAGS $OBJECT # extract params local flags="$1" shift 1 @@ -19,8 +19,8 @@ do_handle() { # $1:FLAGS $2:OBJECT do_compile "${dir}" "${object}" } -# compile a directory -do_compile() { # $1:DIR $2:OBJECT $3:DONE +# compile an OBJECT using build instructions found in DIRectory +do_compile() { # $DIR $OBJECT $DONE # extract params local dir="$1" local object="$2" @@ -28,7 +28,7 @@ do_compile() { # $1:DIR $2:OBJECT $3:DONE # build systems for build_system in ${g_build_systems[@]}; do - do_build_system "${build_system}" "${dir}" "${object}" \ + do_build_system "${dir}" "${object}" "${build_system}" \ && local done="1" done @@ -44,11 +44,11 @@ do_compile() { # $1:DIR $2:OBJECT $3:DONE } # use given BUILD_SYSTEM to process an OBJECT from a DIRectory -do_build_system() { # $1:BUILD_SYSTEM $2:DIR $3:OBJECT +do_build_system() { # $DIR $OBJECT $BUILD_SYSTEM # extract params - local build_system="$1" - local dir="$2" - local object="$3" + local dir="$1" + local object="$2" + local build_system="$3" # not done yet local result=1 @@ -61,7 +61,7 @@ do_build_system() { # $1:BUILD_SYSTEM $2:DIR $3:OBJECT if [ -r "${file}" ]; then # actually call into build system echo -n "Found '${file}': " - do_${build_system} "$(basename "${file}")" "${dir}" "${object}" \ + do_${build_system} "${dir}" "${object}" "$(basename "${file}")" \ && local result=0 echo "" fi diff --git a/build/usr/local/lib/autodoc/plugins/make.sh b/build/usr/local/lib/autodoc/plugins/make.sh index f150b9f..5eaff77 100644 --- a/build/usr/local/lib/autodoc/plugins/make.sh +++ b/build/usr/local/lib/autodoc/plugins/make.sh @@ -7,11 +7,11 @@ g_build_systems+=(make) g_build_systems_glob[make]="Makefile *.mk" # compile using bare make command -do_make() { # $1:MAKEFILE $2:DIR $3:OBJECT +do_make() { # $DIR $OBJECT $MAKEFILE # extract params - local makefile="$1" - local dir="$2" - local object="$3" + local dir="$1" + local object="$2" + local makefile="$3" # check Makefile 'source pattern' local srcpat="$(grep -E "^#%SRCPAT%" "${dir}/${makefile}" | tail -n 1 | sed -r "s/^#%SRCPAT%\s+//")" From 91e186b7e263e83f8512097386f903a06e8d3531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 14:58:10 +0200 Subject: [PATCH 10/11] fine logging including make output --- build/usr/local/bin/autodoc | 1 + build/usr/local/lib/autodoc/handle_inotify | 8 ++++---- build/usr/local/lib/autodoc/logging | 12 ++++++++++++ build/usr/local/lib/autodoc/plugins/make.sh | 14 +++++++++----- 4 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 build/usr/local/lib/autodoc/logging diff --git a/build/usr/local/bin/autodoc b/build/usr/local/bin/autodoc index a9a33f2..6c92403 100755 --- a/build/usr/local/bin/autodoc +++ b/build/usr/local/bin/autodoc @@ -14,6 +14,7 @@ declare -A g_build_systems_glob # source "${g_lib}/globals" +source "${g_lib}/logging" source "${g_lib}/plugins/"*".sh" source "${g_lib}/handle_inotify" diff --git a/build/usr/local/lib/autodoc/handle_inotify b/build/usr/local/lib/autodoc/handle_inotify index 6429c36..63e7f94 100644 --- a/build/usr/local/lib/autodoc/handle_inotify +++ b/build/usr/local/lib/autodoc/handle_inotify @@ -15,8 +15,9 @@ do_handle() { # $FLAGS $OBJECT fi # start using toolchain - echo -n "'${object}': '${flags}' in '${dir}'. " + logline_append "'${object}': '${flags}' in '${dir}'." do_compile "${dir}" "${object}" + logline_flush } # compile an OBJECT using build instructions found in DIRectory @@ -39,7 +40,7 @@ do_compile() { # $DIR $OBJECT $DONE elif [ "${done}" == "0" ]; then # hit $g_watchroot - echo "No build instructions found!" + logline_append "Not a source file." fi } @@ -60,10 +61,9 @@ do_build_system() { # $DIR $OBJECT $BUILD_SYSTEM # check file readability if [ -r "${file}" ]; then # actually call into build system - echo -n "Found '${file}': " + logline_append "Found '${file}':" do_${build_system} "${dir}" "${object}" "$(basename "${file}")" \ && local result=0 - echo "" fi done done diff --git a/build/usr/local/lib/autodoc/logging b/build/usr/local/lib/autodoc/logging new file mode 100644 index 0000000..802d576 --- /dev/null +++ b/build/usr/local/lib/autodoc/logging @@ -0,0 +1,12 @@ +#!/bin/bash + +g_logline="" + +logline_append() { # $STRING + g_logline="${g_logline}${1} " +} + +logline_flush() { + echo "${g_logline}" + g_logline="" +} diff --git a/build/usr/local/lib/autodoc/plugins/make.sh b/build/usr/local/lib/autodoc/plugins/make.sh index 5eaff77..6ee1ef8 100644 --- a/build/usr/local/lib/autodoc/plugins/make.sh +++ b/build/usr/local/lib/autodoc/plugins/make.sh @@ -17,7 +17,7 @@ do_make() { # $DIR $OBJECT $MAKEFILE 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! " + logline_append "Empty source pattern, check '#%SRCPAT%' annotation!" return 1 elif [[ "${object}" =~ ${srcpat} ]]; then @@ -25,15 +25,19 @@ do_make() { # $DIR $OBJECT $MAKEFILE local target="$(grep -E "^autodoc:" "${dir}/${makefile}" | sed -r "s/:.*$//")" if [ -z "${target}" ]; then - echo "Running 'make'. " + logline_append "Running 'make'!" else - echo "Making '${target}'. " + logline_append "Making '${target}'!" fi - make --no-print-directory -C "${dir}" -f "${makefile}" -j ${target} + # 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." else - echo -n "SRCPAT '${srcpat}' mismatch. " + logline_append "SRCPAT '${srcpat}' mismatch." return 1 fi From f227ceae35195293d5da19ad1b7c38f4746f007c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 24 Sep 2019 15:00:36 +0200 Subject: [PATCH 11/11] autodoc target example --- README.md | 2 +- .../automatic directory listing/a directory in space/Makefile | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d91246d..14cc6e3 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ However, Makefiles must contain a SRCPAT annotation comment as follows, where `< If there are multiple SRCPAT annotations, the lowermost one will be used. -You *may* add a PHONY target "autodoc" which will be built *instead* of the default target. +You *may* add a PHONY target "autodoc" which will be built *instead* of the default target. This is demonstrated in [examples/automatic directory listing/a directory in space/Makefile](https://github.com/ldericher/autodoc/blob/develop/examples/automatic%20directory%20listing/a%20directory%20in%20space/Makefile). ```Makefile .PHONY: autodoc diff --git a/examples/automatic directory listing/a directory in space/Makefile b/examples/automatic directory listing/a directory in space/Makefile index b358204..c655049 100644 --- a/examples/automatic directory listing/a directory in space/Makefile +++ b/examples/automatic directory listing/a directory in space/Makefile @@ -3,3 +3,7 @@ .PHONY: all all: @echo "Hello World!" + +.PHONY: autodoc +autodoc: + @echo "Hello autodoc!"