From c1121fad3fda4af4fac95f704fd46e9fe3f44ea6 Mon Sep 17 00:00:00 2001 From: patr0nus Date: Tue, 29 Dec 2020 01:51:59 +0800 Subject: [PATCH 1/3] Check if the universal library is updated --- src/lipo.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/lipo.rs b/src/lipo.rs index caf41b5..449af19 100644 --- a/src/lipo.rs +++ b/src/lipo.rs @@ -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, inputs: impl IntoIterator>) -> std::io::Result { + let output_mtime = fs::metadata(output)?.modified()?; + 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]) -> Result<()> { for package in meta.packages() { @@ -37,13 +49,18 @@ pub(crate) fn build(cargo: &Cargo, meta: &Meta, targets: &[impl AsRef]) -> 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()); + } + else { + 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(()) From 1df1ea15f1fa260448284c0342c92855bc2eb2d1 Mon Sep 17 00:00:00 2001 From: patr0nus Date: Wed, 20 Jan 2021 23:06:34 +0800 Subject: [PATCH 2/3] Refactor `is_output_updated` to `should_update_output` && rustfmt --- src/lipo.rs | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/lipo.rs b/src/lipo.rs index 449af19..d3a13dc 100644 --- a/src/lipo.rs +++ b/src/lipo.rs @@ -7,15 +7,22 @@ use std::fs; use std::process::Command; use std::path::Path; -fn is_output_updated(output: impl AsRef, inputs: impl IntoIterator>) -> std::io::Result { - let output_mtime = fs::metadata(output)?.modified()?; +fn should_update_output( + output: impl AsRef, + inputs: impl IntoIterator>, +) -> std::io::Result { + 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(false) + return Ok(true); } } - Ok(true) + Ok(false) } pub(crate) fn build(cargo: &Cargo, meta: &Meta, targets: &[impl AsRef]) -> Result<()> { @@ -49,18 +56,30 @@ pub(crate) fn build(cargo: &Cargo, meta: &Meta, targets: &[impl AsRef]) -> output.push(&lib_name); - if let Ok(true) = is_output_updated(&output, &inputs) { - info!("Universal library for {} is updated", package.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 + ) + } } - else { - let mut cmd = Command::new("lipo"); - cmd.arg("-create").arg("-output").arg(output); - cmd.args(inputs); + 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(()) From f076aca9b8c2430f483caa54487142d5b63579e9 Mon Sep 17 00:00:00 2001 From: "Wang, Chi" Date: Wed, 20 Jan 2021 23:39:22 +0800 Subject: [PATCH 3/3] Add missing `use` --- src/lipo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lipo.rs b/src/lipo.rs index d3a13dc..54a4277 100644 --- a/src/lipo.rs +++ b/src/lipo.rs @@ -2,7 +2,7 @@ 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;