diff --git a/src/args.rs b/src/args.rs index b73cef0..7b7b097 100644 --- a/src/args.rs +++ b/src/args.rs @@ -651,6 +651,9 @@ pub enum Command { #[arg(long)] /// Do not create directory entries in archive. This means all files are stored in a flat structure. no_dir: bool, + #[arg(long)] + /// Output dependency file path. This file will contain a list of all files packed in the archive. + dep_file: Option, }, } diff --git a/src/main.rs b/src/main.rs index 802f66c..0c5ca8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2387,6 +2387,7 @@ pub fn pack_archive_v2( config: std::sync::Arc, backslash: bool, no_dir: bool, + dep_file: Option<&str>, ) -> anyhow::Result<()> { let typ = match &arg.script_type { Some(t) => t, @@ -2463,6 +2464,20 @@ pub fn pack_archive_v2( get_archived_encoding(arg, builder, get_encoding(arg, builder)), &config, )?; + if let Some(dep_file) = dep_file { + let df = std::fs::File::create(dep_file) + .map_err(|e| anyhow::anyhow!("Failed to create dep file {}: {}", dep_file, e))?; + let mut df = std::io::BufWriter::new(df); + use std::io::Write; + write!(df, "{}:", output) + .map_err(|e| anyhow::anyhow!("Failed to write to dep file {}: {}", dep_file, e))?; + for f in &files { + write!(df, " {}", f) + .map_err(|e| anyhow::anyhow!("Failed to write to dep file {}: {}", dep_file, e))?; + } + writeln!(df) + .map_err(|e| anyhow::anyhow!("Failed to write to dep file {}: {}", dep_file, e))?; + } for (file, name) in files.iter().zip(reff) { let mut f = match std::fs::File::open(file) { Ok(f) => f, @@ -3166,6 +3181,7 @@ fn main() { input, backslash, no_dir, + dep_file, } => { if !input.is_empty() { let input = input.iter().map(|s| s.as_str()).collect::>(); @@ -3176,6 +3192,7 @@ fn main() { cfg.clone(), *backslash, *no_dir, + dep_file.as_ref().map(|s| s.as_str()), ); if let Err(e) = re { COUNTER.inc_error();