Files

43 lines
1.6 KiB
PowerShell
Raw Permalink Normal View History

2026-05-15 10:39:16 +05:30
#requires -Version 5.1
# 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.
$ErrorActionPreference = 'Stop'
$RepoRoot = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $RepoRoot
$sep = [IO.Path]::DirectorySeparatorChar
$allowed = "engine${sep}src${sep}parser${sep}"
$pattern = 'FPDF_|#\s*include\s*[<"]fpdf'
$sources = Get-ChildItem -Path 'engine', 'bindings' -Recurse -File -ErrorAction SilentlyContinue `
-Include '*.cpp', '*.cc', '*.h', '*.hpp' |
Where-Object {
$rel = $_.FullName.Substring($RepoRoot.Length + 1)
-not $rel.StartsWith($allowed)
}
$violations = @()
foreach ($file in $sources) {
$text = Get-Content -Raw -LiteralPath $file.FullName
if (-not $text) { continue }
# Strip // line comments and /* ... */ block comments before matching.
$stripped = [regex]::Replace($text, '//[^\r\n]*|/\*[\s\S]*?\*/', '')
if ($stripped -match $pattern) {
$violations += $file.FullName.Substring($RepoRoot.Length + 1)
}
}
if ($violations) {
Write-Host 'ERROR: Rule R2 violation - raw PDFium usage outside engine/src/parser/:'
$violations | ForEach-Object { Write-Host " $_" }
Write-Host 'All PDFium access must go through the parser boundary.'
exit 1
}
Write-Host 'R2 boundary check: OK (no raw PDFium usage outside engine/src/parser/)'