Files
pdf/scripts/check_pdfium_boundary.sh
T
2026-05-15 10:39:16 +05:30

37 lines
1.3 KiB
Bash

#!/usr/bin/env bash
# Rule R2 enforcement: raw PDFium APIs (FPDF_*) and PDFium headers (fpdf*.h) may
# only appear under engine/src/parser/. Run locally and in CI.
#
# C/C++ comments are stripped before matching, so headers that *document* the
# rule (e.g. engine/include/pdfengine/pdf_document.hpp) don't trip it — only
# real code usage counts.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${REPO_ROOT}"
pattern='FPDF_|#[[:space:]]*include[[:space:]]*[<"]fpdf'
violations=""
while IFS= read -r -d '' file; do
# engine/src/parser/ is the one allowed home of raw PDFium usage.
case "${file}" in
engine/src/parser/*) continue ;;
esac
# Strip // line comments and /* ... */ block comments, then search.
if perl -0777 -pe 's{//[^\n]*|/\*.*?\*/}{}gs' "${file}" | grep -Eq "${pattern}"; then
violations+=" ${file}"$'\n'
fi
done < <(find engine bindings \
\( -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.hpp' \) \
-print0 2>/dev/null)
if [[ -n "${violations}" ]]; then
echo "ERROR: Rule R2 violation — raw PDFium usage outside engine/src/parser/:" >&2
printf '%s' "${violations}" >&2
echo "All PDFium access must go through the parser boundary." >&2
exit 1
fi
echo "R2 boundary check: OK (no raw PDFium usage outside engine/src/parser/)"