Skip to content

Commit 6bad0d5

Browse files
committed
Auto merge of rust-lang#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#97485.
2 parents e4b0d3a + 0d28d64 commit 6bad0d5

File tree

1 file changed

+8
-39
lines changed

1 file changed

+8
-39
lines changed

src/archive.rs

+8-39
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct ArArchiveBuilder<'a> {
3232
}
3333

3434
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
35-
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
35+
fn new(sess: &'a Session, output: &Path) -> Self {
3636
let config = ArchiveConfig {
3737
sess,
3838
dst: output.to_path_buf(),
@@ -41,48 +41,13 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
4141
use_gnu_style_archive: sess.target.options.archive_format == "gnu",
4242
};
4343

44-
let (src_archives, entries) = if let Some(input) = input {
45-
let mut archive = ar::Archive::new(File::open(input).unwrap());
46-
let mut entries = Vec::new();
47-
48-
let mut i = 0;
49-
while let Some(entry) = archive.next_entry() {
50-
let entry = entry.unwrap();
51-
entries.push((
52-
String::from_utf8(entry.header().identifier().to_vec()).unwrap(),
53-
ArchiveEntry::FromArchive {
54-
archive_index: 0,
55-
entry_index: i,
56-
},
57-
));
58-
i += 1;
59-
}
60-
61-
(vec![(input.to_owned(), archive)], entries)
62-
} else {
63-
(vec![], Vec::new())
64-
};
65-
6644
ArArchiveBuilder {
6745
config,
68-
src_archives,
69-
entries,
46+
src_archives: vec![],
47+
entries: vec![],
7048
}
7149
}
7250

73-
fn src_files(&mut self) -> Vec<String> {
74-
self.entries.iter().map(|(name, _)| name.clone()).collect()
75-
}
76-
77-
fn remove_file(&mut self, name: &str) {
78-
let index = self
79-
.entries
80-
.iter()
81-
.position(|(entry_name, _)| entry_name == name)
82-
.expect("Tried to remove file not existing in src archive");
83-
self.entries.remove(index);
84-
}
85-
8651
fn add_file(&mut self, file: &Path) {
8752
self.entries.push((
8853
file.file_name().unwrap().to_str().unwrap().to_string(),
@@ -113,7 +78,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
11378
Ok(())
11479
}
11580

116-
fn build(mut self) {
81+
fn build(mut self) -> bool {
11782
use std::process::Command;
11883

11984
fn add_file_using_ar(archive: &Path, file: &Path) {
@@ -146,6 +111,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
146111
BuilderKind::Bsd(ar::Builder::new(File::create(&self.config.dst).unwrap()))
147112
};
148113

114+
let any_members = !self.entries.is_empty();
115+
149116
// Add all files
150117
for (entry_name, entry) in self.entries.into_iter() {
151118
match entry {
@@ -206,6 +173,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
206173
if !status.success() {
207174
self.config.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
208175
}
176+
177+
any_members
209178
}
210179

211180
fn inject_dll_import_lib(&mut self, _lib_name: &str, _dll_imports: &[DllImport], _tmpdir: &MaybeTempDir) {

0 commit comments

Comments
 (0)