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 commit is contained in:
parent
7ff0df5102
commit
18c6fe5798
5 changed files with 11 additions and 82 deletions
|
@ -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![],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct ArArchiveBuilder<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
|
||||
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
|
||||
fn new(sess: &'a Session, output: &Path) -> Self {
|
||||
let config = ArchiveConfig {
|
||||
sess,
|
||||
dst: output.to_path_buf(),
|
||||
|
@ -41,32 +41,10 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
|
|||
use_gnu_style_archive: sess.target.options.archive_format == "gnu",
|
||||
};
|
||||
|
||||
let (src_archives, entries) = if let Some(input) = input {
|
||||
let mut archive = ar::Archive::new(File::open(input).unwrap());
|
||||
let mut entries = Vec::new();
|
||||
|
||||
let mut i = 0;
|
||||
while let Some(entry) = archive.next_entry() {
|
||||
let entry = entry.unwrap();
|
||||
entries.push((
|
||||
String::from_utf8(entry.header().identifier().to_vec()).unwrap(),
|
||||
ArchiveEntry::FromArchive {
|
||||
archive_index: 0,
|
||||
entry_index: i,
|
||||
},
|
||||
));
|
||||
i += 1;
|
||||
}
|
||||
|
||||
(vec![(input.to_owned(), archive)], entries)
|
||||
} else {
|
||||
(vec![], Vec::new())
|
||||
};
|
||||
|
||||
ArArchiveBuilder {
|
||||
config,
|
||||
src_archives,
|
||||
entries,
|
||||
src_archives: vec![],
|
||||
entries: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,7 @@ use rustc_session::Session;
|
|||
pub struct LlvmArchiveBuilder<'a> {
|
||||
sess: &'a Session,
|
||||
dst: PathBuf,
|
||||
src: Option<PathBuf>,
|
||||
additions: Vec<Addition>,
|
||||
src_archive: Option<Option<ArchiveRO>>,
|
||||
}
|
||||
|
||||
enum Addition {
|
||||
|
@ -59,14 +57,8 @@ fn llvm_machine_type(cpu: &str) -> LLVMMachineType {
|
|||
impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
|
||||
/// Creates a new static archive, ready for modifying the archive specified
|
||||
/// by `config`.
|
||||
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> LlvmArchiveBuilder<'a> {
|
||||
LlvmArchiveBuilder {
|
||||
sess,
|
||||
dst: output.to_path_buf(),
|
||||
src: input.map(|p| p.to_path_buf()),
|
||||
additions: Vec::new(),
|
||||
src_archive: None,
|
||||
}
|
||||
fn new(sess: &'a Session, output: &Path) -> LlvmArchiveBuilder<'a> {
|
||||
LlvmArchiveBuilder { sess, dst: output.to_path_buf(), additions: Vec::new() }
|
||||
}
|
||||
|
||||
fn add_archive<F>(&mut self, archive: &Path, skip: F) -> io::Result<()>
|
||||
|
@ -257,15 +249,6 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
|
|||
}
|
||||
|
||||
impl<'a> LlvmArchiveBuilder<'a> {
|
||||
fn src_archive(&mut self) -> Option<&ArchiveRO> {
|
||||
if let Some(ref a) = self.src_archive {
|
||||
return a.as_ref();
|
||||
}
|
||||
let src = self.src.as_ref()?;
|
||||
self.src_archive = Some(ArchiveRO::open(src).ok());
|
||||
self.src_archive.as_ref().unwrap().as_ref()
|
||||
}
|
||||
|
||||
fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
|
||||
let kind = &*self.sess.target.archive_format;
|
||||
kind.parse().map_err(|_| kind)
|
||||
|
@ -279,20 +262,6 @@ impl<'a> LlvmArchiveBuilder<'a> {
|
|||
let dst = CString::new(self.dst.to_str().unwrap())?;
|
||||
|
||||
unsafe {
|
||||
if let Some(archive) = self.src_archive() {
|
||||
for child in archive.iter() {
|
||||
let child = child.map_err(string_to_io_error)?;
|
||||
let Some(child_name) = child.name() else { continue };
|
||||
|
||||
let name = CString::new(child_name)?;
|
||||
members.push(llvm::LLVMRustArchiveMemberNew(
|
||||
ptr::null(),
|
||||
name.as_ptr(),
|
||||
Some(child.raw),
|
||||
));
|
||||
strings.push(name);
|
||||
}
|
||||
}
|
||||
for addition in &mut additions {
|
||||
match addition {
|
||||
Addition::File { path, name_in_archive } => {
|
||||
|
|
|
@ -42,7 +42,7 @@ pub(super) fn find_library(
|
|||
}
|
||||
|
||||
pub trait ArchiveBuilder<'a> {
|
||||
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self;
|
||||
fn new(sess: &'a Session, output: &Path) -> Self;
|
||||
|
||||
fn add_file(&mut self, path: &Path);
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
let lib_search_paths = archive_search_paths(sess);
|
||||
|
||||
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename, None);
|
||||
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename);
|
||||
|
||||
let trailing_metadata = match flavor {
|
||||
RlibFlavor::Normal => {
|
||||
|
@ -2472,7 +2472,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
|||
let is_builtins = sess.target.no_builtins
|
||||
|| !codegen_results.crate_info.is_no_builtins.contains(&cnum);
|
||||
|
||||
let mut archive = <B as ArchiveBuilder>::new(sess, &dst, None);
|
||||
let mut archive = <B as ArchiveBuilder>::new(sess, &dst);
|
||||
if let Err(e) = archive.add_archive(cratepath, move |f| {
|
||||
if f == METADATA_FILENAME {
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue