Files
vectorcraft/xtask/src/pdf_deps.rs
T
dotCooCoo 3ecd070872 Part of #10798: the font list's style rows preview their style on the text
Hovering a style row of an expanded family in the font list previewed
only the family on the selected type. apply_preview now takes the style
the picker reports with its preview (FontPickerOutput::preview_style and
CharacterControlsOutput::preview_style) and passes it to the font
command, so the type shows the hovered style; a family row still
previews the family in the closest style it has.

Every craft-libs rev moves to storytold/craft-libs#5489's head
(4f3e34d0dd), which adds preview_style, gives style rows a sample in
their own face, and keeps a typed query when a family's disclosure, its
star or a filter is clicked. Cargo.lock changes only the craft-libs
source lines.
2026-12-05 02:29:35 -08:00

105 lines
4.0 KiB
Rust

//! Verify that PDF reading and writing use one immutable shared crate and patched backends.
use std::path::Path;
use std::process::Command;
use serde_json::Value;
const REV: &str = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da";
const PACKAGES: &[(&str, &str, &str)] = &[
("craft-pdf", "0.1.0", REV),
("krilla", "0.8.2", REV),
("hayro-syntax", "0.7.2", REV),
("hayro-interpret", "0.7.0", REV),
("hayro-jbig2", "0.3.0", REV),
("hayro-cmap", "0.1.0", REV),
("hayro-postscript", "0.1.0", REV),
];
/// The resolved source of a craft-libs package at `rev`.
fn source(rev: &str) -> String {
format!("git+https://github.com/storytold/craft-libs?rev={rev}#{rev}")
}
pub fn run(root: &Path) -> Result<(), String> {
let output = Command::new(std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into()))
.current_dir(root)
.args(["metadata", "--locked", "--format-version", "1"])
.output()
.map_err(|e| format!("cargo metadata: {e}"))?;
if !output.status.success() {
return Err(format!("cargo metadata: {}", String::from_utf8_lossy(&output.stderr)));
}
let metadata: Value = serde_json::from_slice(&output.stdout).map_err(|e| format!("cargo metadata: {e}"))?;
validate(&metadata)?;
println!("PDF: shared crate and patched backends match their pinned sources");
Ok(())
}
fn validate(metadata: &Value) -> Result<(), String> {
let packages = metadata.get("packages").and_then(Value::as_array).ok_or("cargo metadata has no packages")?;
for &(name, version, rev) in PACKAGES {
let source = source(rev);
let mut found = packages.iter().filter(|p| p.get("name").and_then(Value::as_str) == Some(name));
let package = found.next().ok_or_else(|| format!("{name}: missing resolved package"))?;
if found.next().is_some() {
return Err(format!("{name}: expected one resolved package"));
}
if package.get("version").and_then(Value::as_str) != Some(version) || package.get("source").and_then(Value::as_str) != Some(source.as_str()) {
return Err(format!("{name}: expected {version} from {source}; got {package}"));
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
fn metadata() -> Value {
let packages: Vec<_> = PACKAGES.iter().map(|(name, version, rev)| json!({"name":name, "version":version, "source":source(rev)})).collect();
json!({"packages": packages})
}
#[test]
fn accepts_pinned_pdf_packages_without_changing_printer_transport() {
let mut m = metadata();
m["packages"]
.as_array_mut()
.unwrap()
.push(json!({"name":"craft-print", "version":"0.1.0", "source":"git+https://github.com/storytold/craft-libs?rev=d991bf6792f8ade99c51358bf3c1d902c8cd96b5#d991bf6792f8ade99c51358bf3c1d902c8cd96b5"}));
assert!(validate(&m).is_ok());
}
#[test]
fn rejects_missing_or_duplicate_pdf_packages() {
for index in 0..PACKAGES.len() {
let mut m = metadata();
m["packages"].as_array_mut().unwrap().remove(index);
assert!(validate(&m).is_err());
let mut m = metadata();
let duplicate = m["packages"][index].clone();
m["packages"].as_array_mut().unwrap().push(duplicate);
assert!(validate(&m).is_err());
}
}
#[test]
fn rejects_registry_local_version_and_revision_drift() {
for index in 0..PACKAGES.len() {
for (field, value) in [
("source", Value::Null),
("source", json!("registry+https://github.com/rust-lang/crates.io-index")),
("source", json!("git+https://github.com/storytold/craft-libs?branch=main#other")),
("source", json!(source("92d392cff132eaf53e13afff77f38b5c11b73aa0"))),
("version", json!("0.99.0")),
] {
let mut m = metadata();
m["packages"][index][field] = value;
assert!(validate(&m).is_err());
}
}
}
}