Skip to content
Merged
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
37 changes: 0 additions & 37 deletions crates/build-deps/src/build/kobo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,43 +269,6 @@ fn find_versioned_soname(libs_dir: &Path, lib: &str) -> Result<String> {
}
}

/// Recursive copy that mirrors a source tree to `dst`, skipping git
/// metadata (`*.git`, `*.gitattributes`), build artefacts (`build/`,
/// `objs/`) and `autom4te.cache/`.
///
/// Symlinks are preserved as symlinks; regular files and directories
/// are copied recursively. Used by [`source::copy_source`] and by
/// the native build to snapshot the MuPDF source tree before
/// patching.
pub fn cp_r(src: &Path, dst: &Path) -> Result<()> {
std::fs::create_dir_all(dst)?;
for entry in std::fs::read_dir(src)? {
let entry = entry?;
let name = entry.file_name();
let name_str = name.to_string_lossy();
if name_str.starts_with(".git")
|| name_str == "build"
|| name_str == "objs"
|| name_str == "autom4te.cache"
{
continue;
}
let ft = entry.file_type()?;
let dst_child = dst.join(&name);
if ft.is_dir() {
cp_r(&entry.path(), &dst_child)?;
} else if ft.is_symlink() {
if let Ok(target) = std::fs::read_link(entry.path()) {
#[cfg(unix)]
std::os::unix::fs::symlink(&target, &dst_child)?;
}
} else {
std::fs::copy(entry.path(), &dst_child)?;
}
}
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
5 changes: 3 additions & 2 deletions crates/build-deps/src/build/kobo/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ use anyhow::{Context, Result};

use crate::build::mupdf;
use crate::cmd;
use crate::utils;

/// Copy a library's source tree into `build_dir` and overlay any
/// build scripts kept under `build-scripts/<lib>/` (typically
/// `kobo.patch`, `kobo-options.txt`, etc.).
///
/// Skips git metadata, `build/`, `objs/` and `autom4te.cache/` via
/// [`super::cp_r`].
/// [`utils::cp_r`].
pub fn copy_source(src_dir: &Path, build_dir: &Path, name: &str, root: &Path) -> Result<()> {
println!("Copying {name} source...");

super::cp_r(src_dir, build_dir)?;
utils::cp_r(src_dir, build_dir)?;

let scripts_dir = root.join("build-scripts").join(name);
if scripts_dir.exists() {
Expand Down
9 changes: 5 additions & 4 deletions crates/build-deps/src/build/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use std::path::{Path, PathBuf};

use anyhow::{Context, Result, bail};

use crate::build::{kobo, mupdf};
use crate::build::mupdf;
use crate::cmd;
use crate::markers;
use crate::utils;
use crate::versions::MUPDF_VERSION;

/// Default Cargo target triple when `TARGET` is unset (build script context
Expand Down Expand Up @@ -80,7 +81,7 @@ pub fn ensure_native_artifacts(root: &Path) -> Result<NativeArtifacts> {
build_libwebp_native(root)?;

if !mupdf_build.exists() {
kobo::cp_r(&mupdf_src, &mupdf_build).context("failed to copy mupdf source")?;
utils::cp_r(&mupdf_src, &mupdf_build).context("failed to copy mupdf source")?;
}

mupdf::apply_webp_patches_if_needed(&mupdf_build, root)
Expand Down Expand Up @@ -151,7 +152,7 @@ pub fn build_libwebp_native(root: &Path) -> Result<()> {

let src_dir = root.join("thirdparty/libwebp");
if !libwebp_dir.join("configure").exists() {
kobo::cp_r(&src_dir, &libwebp_dir)?;
utils::cp_r(&src_dir, &libwebp_dir)?;
}

cmd::run("make", &["distclean"], &libwebp_dir, &[]).ok();
Expand Down Expand Up @@ -351,7 +352,7 @@ pub fn build_mupdf_native(root: &Path) -> Result<()> {

let src_dir = root.join("thirdparty/mupdf");
if !mupdf_dir.exists() {
kobo::cp_r(&src_dir, &mupdf_dir)?;
utils::cp_r(&src_dir, &mupdf_dir)?;
}

println!("Building MuPDF for native development...");
Expand Down
1 change: 1 addition & 0 deletions crates/build-deps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
pub mod build;
pub mod cmd;
pub mod markers;
pub mod utils;
pub mod versions;

use std::path::Path;
Expand Down
46 changes: 46 additions & 0 deletions crates/build-deps/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Generic filesystem helpers for build orchestration.

use std::path::Path;

use anyhow::Result;

/// Recursive copy that mirrors a source tree to `dst`, skipping git
/// metadata (`*.git`, `*.gitattributes`), build artefacts (`build/`,
/// `objs/`) and `autom4te.cache/`.
///
/// Symlinks are preserved as symlinks; regular files and directories
/// are copied recursively.
pub fn cp_r(src: &Path, dst: &Path) -> Result<()> {
std::fs::create_dir_all(dst)?;
for entry in std::fs::read_dir(src)? {
let entry = entry?;
let name = entry.file_name();
let name_str = name.to_string_lossy();
if name_str.starts_with(".git")
|| name_str == "build"
|| name_str == "objs"
|| name_str == "autom4te.cache"
{
continue;
}

let ft = entry.file_type()?;
let dst_child = dst.join(&name);
if ft.is_dir() {
cp_r(&entry.path(), &dst_child)?;
continue;
}

if ft.is_symlink() {
if let Ok(target) = std::fs::read_link(entry.path()) {
#[cfg(unix)]
std::os::unix::fs::symlink(&target, &dst_child)?;
}
continue;
}

std::fs::copy(entry.path(), &dst_child)?;
}

Ok(())
}
Loading