Skip to content

Commit 92749f0

Browse files
committed
Auto merge of #98098 - bjorn3:archive_refactor, r=michaelwoerister
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. This is simpler and makes it easier to swap out the archive writer in rust-lang/rust#97485.
2 parents 5543d22 + 73b3ae0 commit 92749f0

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

Diff for: src/archive.rs

+8-35
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,19 @@ pub(crate) struct ArArchiveBuilder<'a> {
3030
}
3131

3232
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
33-
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
34-
let (src_archives, entries) = if let Some(input) = input {
35-
let read_cache = ReadCache::new(File::open(input).unwrap());
36-
let archive = ArchiveFile::parse(&read_cache).unwrap();
37-
let mut entries = Vec::new();
38-
39-
for entry in archive.members() {
40-
let entry = entry.unwrap();
41-
entries.push((
42-
entry.name().to_vec(),
43-
ArchiveEntry::FromArchive { archive_index: 0, file_range: entry.file_range() },
44-
));
45-
}
46-
47-
(vec![read_cache.into_inner()], entries)
48-
} else {
49-
(vec![], Vec::new())
50-
};
51-
33+
fn new(sess: &'a Session, output: &Path) -> Self {
5234
ArArchiveBuilder {
5335
sess,
5436
dst: output.to_path_buf(),
5537
use_gnu_style_archive: sess.target.archive_format == "gnu",
5638
// FIXME fix builtin ranlib on macOS
5739
no_builtin_ranlib: sess.target.is_like_osx,
5840

59-
src_archives,
60-
entries,
41+
src_archives: vec![],
42+
entries: vec![],
6143
}
6244
}
6345

64-
fn src_files(&mut self) -> Vec<String> {
65-
self.entries.iter().map(|(name, _)| String::from_utf8(name.clone()).unwrap()).collect()
66-
}
67-
68-
fn remove_file(&mut self, name: &str) {
69-
let index = self
70-
.entries
71-
.iter()
72-
.position(|(entry_name, _)| entry_name == name.as_bytes())
73-
.expect("Tried to remove file not existing in src archive");
74-
self.entries.remove(index);
75-
}
76-
7746
fn add_file(&mut self, file: &Path) {
7847
self.entries.push((
7948
file.file_name().unwrap().to_str().unwrap().to_string().into_bytes(),
@@ -105,7 +74,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
10574
Ok(())
10675
}
10776

108-
fn build(mut self) {
77+
fn build(mut self) -> bool {
10978
enum BuilderKind {
11079
Bsd(ar::Builder<File>),
11180
Gnu(ar::GnuBuilder<File>),
@@ -204,6 +173,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
204173
)
205174
};
206175

176+
let any_members = !entries.is_empty();
177+
207178
// Add all files
208179
for (entry_name, data) in entries.into_iter() {
209180
let header = ar::Header::new(entry_name, data.len() as u64);
@@ -229,6 +200,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
229200
self.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
230201
}
231202
}
203+
204+
any_members
232205
}
233206

234207
fn inject_dll_import_lib(

0 commit comments

Comments
 (0)