[repo] Workspace: CLAUDE.md, DEPENDENCIES.md, deps check, pinned pdfium fetch
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
// Regenerates the "Every crate in Cargo.lock" table in docs/DEPENDENCIES.md from `cargo metadata`
|
||||
// and exits 1 when a crate's licence is outside the allowed set (or missing).
|
||||
// Usage: node scripts/deps.mjs [--check] (--check: do not rewrite the file, only verify it is current)
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const docPath = join(root, 'docs', 'DEPENDENCIES.md');
|
||||
|
||||
export const ALLOWED = new Set([
|
||||
'MIT', 'MIT-0', 'Apache-2.0', 'Apache-2.0 WITH LLVM-exception', 'BSD-2-Clause', 'BSD-3-Clause', '0BSD',
|
||||
'Zlib', 'MPL-2.0', 'ISC', 'Unicode-3.0', 'Unicode-DFS-2016', 'BSL-1.0', 'CC0-1.0',
|
||||
]);
|
||||
|
||||
// Minimal SPDX evaluator: OR / AND / WITH and parentheses. Old crates write "MIT/Apache-2.0" for OR.
|
||||
export function allowed(expr) {
|
||||
if (!expr) return false;
|
||||
const tokens = expr.replace(/\//g, ' OR ').replace(/\(/g, ' ( ').replace(/\)/g, ' ) ').split(/\s+/).filter(Boolean);
|
||||
let i = 0;
|
||||
function primary() {
|
||||
if (tokens[i] === '(') { i++; const v = orExpr(); i++; return v; }
|
||||
let id = tokens[i++];
|
||||
if (tokens[i] === 'WITH') { id += ` WITH ${tokens[i + 1]}`; i += 2; }
|
||||
return ALLOWED.has(id);
|
||||
}
|
||||
function andExpr() { let v = primary(); while (tokens[i] === 'AND') { i++; v = primary() && v; } return v; }
|
||||
function orExpr() { let v = andExpr(); while (tokens[i] === 'OR') { i++; v = andExpr() || v; } return v; }
|
||||
return orExpr();
|
||||
}
|
||||
|
||||
function main() {
|
||||
const meta = JSON.parse(execFileSync('cargo', ['metadata', '--format-version', '1', '--locked', '--filter-platform', 'x86_64-pc-windows-msvc'], {
|
||||
cwd: root, maxBuffer: 1 << 28, encoding: 'utf8',
|
||||
}));
|
||||
// Only crates reachable on Windows x64 (the one target of V1), not every lockfile entry of every platform:
|
||||
// with --filter-platform, resolve.nodes lists what the workspace really depends on there.
|
||||
const used = new Set(meta.resolve.nodes.map((n) => n.id));
|
||||
const workspace = new Set(meta.workspace_members);
|
||||
const rows = meta.packages
|
||||
.filter((p) => used.has(p.id) && !workspace.has(p.id))
|
||||
.map((p) => ({ name: p.name, version: p.version, licence: p.license ?? (p.license_file ? `file: ${p.license_file}` : '') }))
|
||||
.sort((a, b) => a.name.localeCompare(b.name) || a.version.localeCompare(b.version));
|
||||
const bad = rows.filter((r) => !allowed(r.licence));
|
||||
const table = [
|
||||
`${rows.length} crates; ${bad.length} outside the allowed set.`,
|
||||
'',
|
||||
'| Crate | Version | Licence | Allowed |',
|
||||
'| :-- | :-- | :-- | :-- |',
|
||||
...rows.map((r) => `| ${r.name} | ${r.version} | ${r.licence || '(none)'} | ${allowed(r.licence) ? 'yes' : '**NO**'} |`),
|
||||
].join('\n');
|
||||
const doc = readFileSync(docPath, 'utf8');
|
||||
const next = doc.replace(/<!-- deps:begin -->[\s\S]*<!-- deps:end -->/, `<!-- deps:begin -->\n${table}\n<!-- deps:end -->`);
|
||||
if (process.argv.includes('--check')) {
|
||||
if (next !== doc) { console.error('docs/DEPENDENCIES.md is out of date: run node scripts/deps.mjs'); process.exit(1); }
|
||||
} else if (next !== doc) {
|
||||
writeFileSync(docPath, next);
|
||||
}
|
||||
for (const r of bad) console.error(`not allowed: ${r.name} ${r.version} (${r.licence || 'no licence field'})`);
|
||||
console.log(`${rows.length} crates, ${bad.length} not allowed`);
|
||||
process.exit(bad.length ? 1 : 0);
|
||||
}
|
||||
|
||||
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) main();
|
||||
@@ -0,0 +1,42 @@
|
||||
# Fetches the pinned pdfium build (bblanchon/pdfium-binaries, Windows x64) into third_party/pdfium/.
|
||||
# The archive's sha256 is pinned: a different file is refused and nothing is extracted.
|
||||
# pdfium-render's `pdfium_latest` feature (0.9.5) targets chromium/8125: keep the two in step.
|
||||
# Usage: powershell -File scripts/fetch-pdfium.ps1 [-Dest <folder>]
|
||||
param([string]$Dest = (Join-Path $PSScriptRoot '..\third_party\pdfium'))
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$Release = 'chromium/8125'
|
||||
$Url = 'https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F8125/pdfium-win-x64.tgz'
|
||||
$Sha256 = '9a964261760cff52570aabf038ab346d3a5034dd8b30d0d5fe8861235d356b8b'
|
||||
|
||||
$Dest = [IO.Path]::GetFullPath($Dest)
|
||||
$marker = Join-Path $Dest 'RELEASE'
|
||||
if ((Test-Path (Join-Path $Dest 'bin\pdfium.dll')) -and (Test-Path $marker) -and ((Get-Content $marker -Raw).Trim() -eq "$Release $Sha256")) {
|
||||
Write-Host "pdfium $Release already in $Dest"
|
||||
exit 0
|
||||
}
|
||||
|
||||
$tmp = Join-Path ([IO.Path]::GetTempPath()) ("pdfium-" + [Guid]::NewGuid())
|
||||
New-Item -ItemType Directory -Force $tmp | Out-Null
|
||||
try {
|
||||
$archive = Join-Path $tmp 'pdfium-win-x64.tgz'
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $archive
|
||||
$got = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLowerInvariant()
|
||||
if ($got -ne $Sha256) { throw "pdfium archive sha256 mismatch: expected $Sha256, got $got. Nothing was extracted." }
|
||||
$x = Join-Path $tmp 'x'
|
||||
New-Item -ItemType Directory -Force $x | Out-Null
|
||||
# Windows' own bsdtar: Git's GNU tar on PATH reads "F:\..." as a remote host.
|
||||
& (Join-Path $env:SystemRoot 'System32\tar.exe') -xzf $archive -C $x
|
||||
if ($LASTEXITCODE -ne 0) { throw "tar failed ($LASTEXITCODE)" }
|
||||
if (Test-Path $Dest) { Remove-Item -Recurse -Force $Dest }
|
||||
New-Item -ItemType Directory -Force (Join-Path $Dest 'bin') | Out-Null
|
||||
Copy-Item (Join-Path $x 'bin\pdfium.dll') (Join-Path $Dest 'bin\pdfium.dll')
|
||||
Copy-Item (Join-Path $x 'LICENSE') (Join-Path $Dest 'LICENSE')
|
||||
Copy-Item -Recurse (Join-Path $x 'licenses') (Join-Path $Dest 'licenses')
|
||||
Copy-Item (Join-Path $x 'VERSION') (Join-Path $Dest 'VERSION')
|
||||
Set-Content -Encoding ascii $marker "$Release $Sha256"
|
||||
Write-Host "pdfium $Release -> $Dest"
|
||||
} finally {
|
||||
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
|
||||
}
|
||||
Reference in New Issue
Block a user