Skip to content

Commit

Permalink
Merge branch 'topic/bbannier/fix-autogen-docs-hook'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Dec 12, 2024
2 parents 1669154 + 831f3f1 commit d59f245
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.12.0-dev.240 | 2024-12-12 13:09:05 +0100

* Make sure autogen-docs pre-commit hook can always run in CI. (Benjamin Bannier, Corelight)

1.12.0-dev.238 | 2024-12-10 14:53:29 +0100

* Update tutorial to use spicy-driver's batch mode. (Robin Sommer, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.0-dev.238
1.12.0-dev.240
48 changes: 33 additions & 15 deletions doc/scripts/autogen-docs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,50 @@
set -o errexit
set -o nounset

# GNU `sort` sorts case-insensitive while macOS `sed` sorts case-sensitive which
# we want. Force GNU sed into case-sensitive mode.
export LC_COLLATE=C

# We expect a GNU sed. If we find `gsed` use that instead since we are likely
# on macOS which by default provides a BSD sed.
SED="sed"
if command -v gsed >/dev/null 2>&1; then
SED=gsed
fi

ROOTDIR="$(cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/../.."
BUILDDIR="${ROOTDIR}/build"
SPICYDOC="${BUILDDIR}/bin/spicy-doc"
SPICYDTR="${ROOTDIR}/doc/scripts/spicy-doc-to-rst"
AUTOGEN_FINAL="${ROOTDIR}/doc/autogen"
AUTOGEN_STAGE=$(mktemp -d -t spicy-autogen-docs.XXXXXXXXXX)

update_architecture_diagram() {
# autogen-architecture-diagram needs the diagrams package and dot.
if ! python3 -c "import diagrams" >/dev/null 2>&1; then
>&2 echo "Warning: Need Python diagrams to run autogen-docs, skipping"
return
fi
if ! command -v dot >/dev/null 2>&1; then
>&2 echo "Warning: Need 'dot' to run autogen-docs, skipping"
return
fi

"${ROOTDIR}/doc/scripts/autogen-architecture-diagram" "${AUTOGEN_STAGE}/architecture" || exit 1

# Remove comments and titles from SVG to make content stable.
${SED} -i"" -e '/<!--/d' -e '/-->/d' "${AUTOGEN_STAGE}/architecture.svg"
${SED} -i"" -e '/<title/d' -e '/title>/d' "${AUTOGEN_STAGE}/architecture.svg"

# Delete unstable DOT and PDF outputs.
rm -f "${AUTOGEN_STAGE}/architecture.dot" "${AUTOGEN_STAGE}/architecture.pdf"
}

if ! command -v rsync >/dev/null 2>&1; then
>&2 echo "Warning: Need rsync to run autogen-docs, aborting"
exit 0
fi

# autogen-architecture-diagram needs the diagrams package
if ! command -v python -c 'import diagrams' >/dev/null 2>&1; then
>&2 echo "Warning: Need Python diagrams to run autogen-docs, aborting"
exit 0
fi

if [[ ! -x ${BUILDDIR}/bin/spicy-doc ]]; then
>&2 echo "Warning: Could not find required executable ${BUILDDIR}/bin/spicy-doc, aborting"
exit 0
Expand All @@ -49,15 +75,7 @@ cat ${ROOTDIR}/spicy/toolchain/src/compiler/parser/scanner.ll \
| awk '{print $1}' \
| sort >${AUTOGEN_STAGE}/reserved-keywords.txt

# Render architecture diagram.
"${ROOTDIR}/doc/scripts/autogen-architecture-diagram" "${AUTOGEN_STAGE}/architecture" || exit 1

# Remove comments and titles from SVG to make content stable.
gsed -i"" -e '/<!--/d' -e '/-->/d' "${AUTOGEN_STAGE}/architecture.svg"
gsed -i"" -e '/<title/d' -e '/title>/d' "${AUTOGEN_STAGE}/architecture.svg"

# Delete unstable DOT and PDF outputs.
rm -f "${AUTOGEN_STAGE}/architecture.dot" "${AUTOGEN_STAGE}/architecture.pdf"
update_architecture_diagram

# All done, move staged files to final location where changed.
# "-rlpgo" is "-a" minus "-tD".
Expand Down

0 comments on commit d59f245

Please sign in to comment.