From fc0c753c2d876b981cbd646b7eb9336844fa08ae Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:11:14 +0000 Subject: [PATCH 1/3] Remove src_files and remove_file They only apply to the main source archive and their role can be fulfilled through the skip argument of add_archive too. --- src/archive.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index a099e8b3a..4822c7e03 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -61,19 +61,6 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { } } - fn src_files(&mut self) -> Vec { - self.entries.iter().map(|(name, _)| String::from_utf8(name.clone()).unwrap()).collect() - } - - fn remove_file(&mut self, name: &str) { - let index = self - .entries - .iter() - .position(|(entry_name, _)| entry_name == name.as_bytes()) - .expect("Tried to remove file not existing in src archive"); - self.entries.remove(index); - } - fn add_file(&mut self, file: &Path) { self.entries.push(( file.file_name().unwrap().to_str().unwrap().to_string().into_bytes(), From abb9b60f0965fe1cdc412369219d100022f39273 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 18 Jun 2022 17:55:24 +0000 Subject: [PATCH 2/3] Fix "Remove src_files and remove_file" --- src/archive.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index 4822c7e03..e9b074e18 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -92,7 +92,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { Ok(()) } - fn build(mut self) { + fn build(mut self) -> bool { enum BuilderKind { Bsd(ar::Builder), Gnu(ar::GnuBuilder), @@ -191,6 +191,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { ) }; + let any_members = !entries.is_empty(); + // Add all files for (entry_name, data) in entries.into_iter() { let header = ar::Header::new(entry_name, data.len() as u64); @@ -216,6 +218,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { self.sess.fatal(&format!("Ranlib exited with code {:?}", status.code())); } } + + any_members } fn inject_dll_import_lib( From 73b3ae0b8a5f84a231ec8fa850711ab5d6c027a3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:16:51 +0000 Subject: [PATCH 3/3] Remove the source archive functionality of ArchiveWriter We now build archives through strictly additive means rather than taking an existing archive and potentially substracting parts. --- src/archive.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index e9b074e18..0812f930b 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -30,25 +30,7 @@ pub(crate) struct ArArchiveBuilder<'a> { } impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { - fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self { - let (src_archives, entries) = if let Some(input) = input { - let read_cache = ReadCache::new(File::open(input).unwrap()); - let archive = ArchiveFile::parse(&read_cache).unwrap(); - let mut entries = Vec::new(); - - for entry in archive.members() { - let entry = entry.unwrap(); - entries.push(( - entry.name().to_vec(), - ArchiveEntry::FromArchive { archive_index: 0, file_range: entry.file_range() }, - )); - } - - (vec![read_cache.into_inner()], entries) - } else { - (vec![], Vec::new()) - }; - + fn new(sess: &'a Session, output: &Path) -> Self { ArArchiveBuilder { sess, dst: output.to_path_buf(), @@ -56,8 +38,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { // FIXME fix builtin ranlib on macOS no_builtin_ranlib: sess.target.is_like_osx, - src_archives, - entries, + src_archives: vec![], + entries: vec![], } }