Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moss/boulder: Add support for font providers #316

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ tokio-util = { version = "0.7.11", features = ["io"] }
url = { version = "2.5.2", features = ["serde"] }
xxhash-rust = { version = "0.8.11", features = ["xxh3"] }
zstd = { version = "0.13.2", features = ["zstdmt"] }
read-fonts = "0.20.0"

[profile.release]
lto = "thin"
Expand Down
1 change: 1 addition & 0 deletions boulder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ strum.workspace = true
thiserror.workspace = true
tokio.workspace = true
url.workspace = true
read-fonts.workspace = true
1 change: 1 addition & 0 deletions boulder/src/package/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<'a> Chain<'a> {
Box::new(handler::elf),
Box::new(handler::pkg_config),
Box::new(handler::cmake),
Box::new(handler::font),
// Catch-all if not excluded
Box::new(handler::include_any),
],
Expand Down
28 changes: 28 additions & 0 deletions boulder/src/package/analysis/handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{path::PathBuf, process::Command};

use moss::{dependency, Dependency, Provider};
use read_fonts::{types::NameId, FontRef, TableProvider};

use crate::package::collect::PathInfo;

Expand Down Expand Up @@ -136,3 +137,30 @@

Ok(Decision::NextHandler.into())
}

pub fn font(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
if !info.target_path.starts_with("/usr/share/font")

Check warning on line 142 in boulder/src/package/analysis/handler.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] boulder/src/package/analysis/handler.rs#L142

warning: this boolean expression can be simplified --> boulder/src/package/analysis/handler.rs:142:8 | 142 | if !info.target_path.starts_with("/usr/share/font") | ________^ 143 | | && !(info.file_name().ends_with(".ttf") || info.file_name().ends_with(".otf")) | |______________________________________________________________________________________^ help: try: `!(info.target_path.starts_with("/usr/share/font") || info.file_name().ends_with(".ttf") || info.file_name().ends_with(".otf"))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool = note: `#[warn(clippy::nonminimal_bool)]` on by default
Raw output
boulder/src/package/analysis/handler.rs:142:8:w:warning: this boolean expression can be simplified
   --> boulder/src/package/analysis/handler.rs:142:8
    |
142 |       if !info.target_path.starts_with("/usr/share/font")
    |  ________^
143 | |         && !(info.file_name().ends_with(".ttf") || info.file_name().ends_with(".otf"))
    | |______________________________________________________________________________________^ help: try: `!(info.target_path.starts_with("/usr/share/font") || info.file_name().ends_with(".ttf") || info.file_name().ends_with(".otf"))`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
    = note: `#[warn(clippy::nonminimal_bool)]` on by default


__END__
&& !(info.file_name().ends_with(".ttf") || info.file_name().ends_with(".otf"))
{
return Ok(Decision::NextHandler.into());
}

let bytes = std::fs::read(&info.path)?;
let font = FontRef::new(&bytes)?;
let font_name_table = font.name()?;
if let Some(record) = font_name_table
.name_record()
.iter()
.find(|record| record.name_id() == NameId::FAMILY_NAME)
{
let data = record.string(font_name_table.string_data())?;
let family_name = data.chars().collect::<String>();

bucket.providers.insert(Provider {
kind: dependency::Kind::Font,
name: family_name,
});
}

Ok(Decision::NextHandler.into())
}
4 changes: 4 additions & 0 deletions crates/stone/src/payload/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub enum Dependency {

/// An emul32-compatible pkgconfig .pc dependency (lib32/*.pc)
PkgConfig32,

/// OpenType Font FAMILY_NAME
Font,
}

#[repr(u8)]
Expand Down Expand Up @@ -146,6 +149,7 @@ fn decode_dependency(i: u8) -> Result<Dependency, DecodeError> {
6 => Dependency::Binary,
7 => Dependency::SystemBinary,
8 => Dependency::PkgConfig32,
9 => Dependency::Font,
_ => return Err(DecodeError::UnknownDependency(i)),
};
Ok(result)
Expand Down
5 changes: 5 additions & 0 deletions moss/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub enum Kind {

/// Exported 32-bit pkgconfig provider
PkgConfig32,

/// OpenType Font FAMILY_NAME
Font,
}

/// Convert payload dependency types to our internal representation
Expand All @@ -74,6 +77,7 @@ impl From<payload::meta::Dependency> for Kind {
payload::meta::Dependency::Binary => Kind::Binary,
payload::meta::Dependency::SystemBinary => Kind::SystemBinary,
payload::meta::Dependency::PkgConfig32 => Kind::PkgConfig32,
payload::meta::Dependency::Font => Kind::Font,
}
}
}
Expand All @@ -91,6 +95,7 @@ impl From<Kind> for payload::meta::Dependency {
Kind::Binary => Self::Binary,
Kind::SystemBinary => Self::SystemBinary,
Kind::PkgConfig32 => Self::PkgConfig32,
Kind::Font => Self::Font,
}
}
}
Expand Down
Loading