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

Check if the universal library is updated before running lipo #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 37 additions & 1 deletion src/lipo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@ use crate::Result;
use crate::cargo::Cargo;
use crate::meta::Meta;
use failure::ResultExt;
use log::info;
use log::{info, warn};
use std::fs;
use std::process::Command;
use std::path::Path;

fn should_update_output(
output: impl AsRef<Path>,
inputs: impl IntoIterator<Item = impl AsRef<Path>>,
) -> std::io::Result<bool> {
let output_metadata = match fs::metadata(output) {
Ok(metadata) => metadata,
Err(_) => return Ok(true),
};
let output_mtime = output_metadata.modified()?;
for input in inputs {
let input_mtime = fs::metadata(input)?.modified()?;
if input_mtime > output_mtime {
return Ok(true);
}
}
Ok(false)
}

pub(crate) fn build(cargo: &Cargo, meta: &Meta, targets: &[impl AsRef<str>]) -> Result<()> {
for package in meta.packages() {
Expand Down Expand Up @@ -37,6 +56,23 @@ pub(crate) fn build(cargo: &Cargo, meta: &Meta, targets: &[impl AsRef<str>]) ->

output.push(&lib_name);

match should_update_output(&output, &inputs) {
Ok(true) => {}
Ok(false) => {
info!(
"Universal library is up-to-date, skipping lipo invocation for {}",
package.name()
);
continue;
}
Err(e) => {
warn!(
"Failed to check if universal library for {:?} is up-to-date: {}",
package.name(),
e
)
}
}
TimNN marked this conversation as resolved.
Show resolved Hide resolved
let mut cmd = Command::new("lipo");
cmd.arg("-create").arg("-output").arg(output);
cmd.args(inputs);
Expand Down