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 1 commit
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
27 changes: 22 additions & 5 deletions src/lipo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ use failure::ResultExt;
use log::info;
use std::fs;
use std::process::Command;
use std::path::Path;

fn is_output_updated(output: impl AsRef<Path>, inputs: impl IntoIterator<Item=impl AsRef<Path>>) -> std::io::Result<bool> {
TimNN marked this conversation as resolved.
Show resolved Hide resolved
let output_mtime = fs::metadata(output)?.modified()?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we handle the "file not found" case here explicitly (by returning that the output needs to be updated)? Then we can also log a warning below if this function fails.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment still applies: Can you please explicitly check if fs::metadata returned "not found"?

for input in inputs {
let input_mtime = fs::metadata(input)?.modified()?;
if input_mtime > output_mtime {
return Ok(false)
}
}
Ok(true)
}

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

output.push(&lib_name);

let mut cmd = Command::new("lipo");
cmd.arg("-create").arg("-output").arg(output);
cmd.args(inputs);
if let Ok(true) = is_output_updated(&output, &inputs) {
info!("Universal library for {} is updated", package.name());
TimNN marked this conversation as resolved.
Show resolved Hide resolved
}
TimNN marked this conversation as resolved.
Show resolved Hide resolved
else {
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);

info!("Creating universal library for {}", package.name());
info!("Creating universal library for {}", package.name());

crate::exec::run(cmd)?;
crate::exec::run(cmd)?;
}
}

Ok(())
Expand Down