Skip to content

Commit 2c2d7f9

Browse files
committed
---
yaml --- r: 131837 b: refs/heads/dist-snap c: 7f6a66f h: refs/heads/master i: 131835: 578023f v: v3
1 parent 17c3fb4 commit 2c2d7f9

File tree

3 files changed

+86
-35
lines changed

3 files changed

+86
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 930abc156789db6ee897a68f02fac6af682cca5b
9+
refs/heads/dist-snap: 7f6a66f77ef362059328524d54b6b987322d2c36
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/back/archive.rs

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
//! A helper class for dealing with static archives
1212
13-
use super::link::{get_ar_prog};
14-
use driver::session::Session;
15-
use metadata::filesearch;
1613
use llvm::{ArchiveRef, llvm};
1714

1815
use libc;
@@ -24,22 +21,38 @@ use std::os;
2421
use std::raw;
2522
use std::str;
2623
use syntax::abi;
24+
use ErrorHandler = syntax::diagnostic::Handler;
2725

2826
pub static METADATA_FILENAME: &'static str = "rust.metadata.bin";
2927

28+
pub struct ArchiveConfig<'a> {
29+
pub handler: &'a ErrorHandler,
30+
pub dst: Path,
31+
pub lib_search_paths: Vec<Path>,
32+
pub os: abi::Os,
33+
pub maybe_ar_prog: Option<String>
34+
}
35+
3036
pub struct Archive<'a> {
31-
sess: &'a Session,
37+
handler: &'a ErrorHandler,
3238
dst: Path,
39+
lib_search_paths: Vec<Path>,
40+
os: abi::Os,
41+
maybe_ar_prog: Option<String>
3342
}
3443

3544
pub struct ArchiveRO {
3645
ptr: ArchiveRef,
3746
}
3847

39-
fn run_ar(sess: &Session, args: &str, cwd: Option<&Path>,
48+
fn run_ar(handler: &ErrorHandler, maybe_ar_prog: &Option<String>,
49+
args: &str, cwd: Option<&Path>,
4050
paths: &[&Path]) -> ProcessOutput {
41-
let ar = get_ar_prog(sess);
42-
let mut cmd = Command::new(ar.as_slice());
51+
let ar = match *maybe_ar_prog {
52+
Some(ref ar) => ar.as_slice(),
53+
None => "ar"
54+
};
55+
let mut cmd = Command::new(ar);
4356

4457
cmd.arg(args).args(paths);
4558
debug!("{}", cmd);
@@ -56,42 +69,55 @@ fn run_ar(sess: &Session, args: &str, cwd: Option<&Path>,
5669
Ok(prog) => {
5770
let o = prog.wait_with_output().unwrap();
5871
if !o.status.success() {
59-
sess.err(format!("{} failed with: {}",
72+
handler.err(format!("{} failed with: {}",
6073
cmd,
6174
o.status).as_slice());
62-
sess.note(format!("stdout ---\n{}",
75+
handler.note(format!("stdout ---\n{}",
6376
str::from_utf8(o.output
6477
.as_slice()).unwrap())
6578
.as_slice());
66-
sess.note(format!("stderr ---\n{}",
79+
handler.note(format!("stderr ---\n{}",
6780
str::from_utf8(o.error
6881
.as_slice()).unwrap())
6982
.as_slice());
70-
sess.abort_if_errors();
83+
handler.abort_if_errors();
7184
}
7285
o
7386
},
7487
Err(e) => {
75-
sess.err(format!("could not exec `{}`: {}", ar.as_slice(),
88+
handler.err(format!("could not exec `{}`: {}", ar.as_slice(),
7689
e).as_slice());
77-
sess.abort_if_errors();
90+
handler.abort_if_errors();
7891
fail!("rustc::back::archive::run_ar() should not reach this point");
7992
}
8093
}
8194
}
8295

8396
impl<'a> Archive<'a> {
8497
/// Initializes a new static archive with the given object file
85-
pub fn create<'b>(sess: &'a Session, dst: &'b Path,
86-
initial_object: &'b Path) -> Archive<'a> {
87-
run_ar(sess, "crus", None, [dst, initial_object]);
88-
Archive { sess: sess, dst: dst.clone() }
98+
pub fn create<'b>(config: ArchiveConfig<'a>, initial_object: &'b Path) -> Archive<'a> {
99+
let ArchiveConfig { handler, dst, lib_search_paths, os, maybe_ar_prog } = config;
100+
run_ar(handler, &maybe_ar_prog, "crus", None, [&dst, initial_object]);
101+
Archive {
102+
handler: handler,
103+
dst: dst,
104+
lib_search_paths: lib_search_paths,
105+
os: os,
106+
maybe_ar_prog: maybe_ar_prog
107+
}
89108
}
90109

91110
/// Opens an existing static archive
92-
pub fn open(sess: &'a Session, dst: Path) -> Archive<'a> {
111+
pub fn open(config: ArchiveConfig<'a>) -> Archive<'a> {
112+
let ArchiveConfig { handler, dst, lib_search_paths, os, maybe_ar_prog } = config;
93113
assert!(dst.exists());
94-
Archive { sess: sess, dst: dst }
114+
Archive {
115+
handler: handler,
116+
dst: dst,
117+
lib_search_paths: lib_search_paths,
118+
os: os,
119+
maybe_ar_prog: maybe_ar_prog
120+
}
95121
}
96122

97123
/// Adds all of the contents of a native library to this archive. This will
@@ -120,22 +146,22 @@ impl<'a> Archive<'a> {
120146
/// Adds an arbitrary file to this archive
121147
pub fn add_file(&mut self, file: &Path, has_symbols: bool) {
122148
let cmd = if has_symbols {"r"} else {"rS"};
123-
run_ar(self.sess, cmd, None, [&self.dst, file]);
149+
run_ar(self.handler, &self.maybe_ar_prog, cmd, None, [&self.dst, file]);
124150
}
125151

126152
/// Removes a file from this archive
127153
pub fn remove_file(&mut self, file: &str) {
128-
run_ar(self.sess, "d", None, [&self.dst, &Path::new(file)]);
154+
run_ar(self.handler, &self.maybe_ar_prog, "d", None, [&self.dst, &Path::new(file)]);
129155
}
130156

131157
/// Updates all symbols in the archive (runs 'ar s' over it)
132158
pub fn update_symbols(&mut self) {
133-
run_ar(self.sess, "s", None, [&self.dst]);
159+
run_ar(self.handler, &self.maybe_ar_prog, "s", None, [&self.dst]);
134160
}
135161

136162
/// Lists all files in an archive
137163
pub fn files(&self) -> Vec<String> {
138-
let output = run_ar(self.sess, "t", None, [&self.dst]);
164+
let output = run_ar(self.handler, &self.maybe_ar_prog, "t", None, [&self.dst]);
139165
let output = str::from_utf8(output.output.as_slice()).unwrap();
140166
// use lines_any because windows delimits output with `\r\n` instead of
141167
// just `\n`
@@ -148,7 +174,7 @@ impl<'a> Archive<'a> {
148174

149175
// First, extract the contents of the archive to a temporary directory
150176
let archive = os::make_absolute(archive);
151-
run_ar(self.sess, "x", Some(loc.path()), [&archive]);
177+
run_ar(self.handler, &self.maybe_ar_prog, "x", Some(loc.path()), [&archive]);
152178

153179
// Next, we must rename all of the inputs to "guaranteed unique names".
154180
// The reason for this is that archives are keyed off the name of the
@@ -184,23 +210,20 @@ impl<'a> Archive<'a> {
184210
// Finally, add all the renamed files to this archive
185211
let mut args = vec!(&self.dst);
186212
args.extend(inputs.iter());
187-
run_ar(self.sess, "r", None, args.as_slice());
213+
run_ar(self.handler, &self.maybe_ar_prog, "r", None, args.as_slice());
188214
Ok(())
189215
}
190216

191217
fn find_library(&self, name: &str) -> Path {
192-
let (osprefix, osext) = match self.sess.targ_cfg.os {
218+
let (osprefix, osext) = match self.os {
193219
abi::OsWin32 => ("", "lib"), _ => ("lib", "a"),
194220
};
195221
// On Windows, static libraries sometimes show up as libfoo.a and other
196222
// times show up as foo.lib
197223
let oslibname = format!("{}{}.{}", osprefix, name, osext);
198224
let unixlibname = format!("lib{}.a", name);
199225

200-
let mut rustpath = filesearch::rust_path();
201-
rustpath.push(self.sess.target_filesearch().get_lib_path());
202-
let search = self.sess.opts.addl_lib_search_paths.borrow();
203-
for path in search.iter().chain(rustpath.iter()) {
226+
for path in self.lib_search_paths.iter() {
204227
debug!("looking for {} inside {}", name, path.display());
205228
let test = path.join(oslibname.as_slice());
206229
if test.exists() { return test }
@@ -209,7 +232,7 @@ impl<'a> Archive<'a> {
209232
if test.exists() { return test }
210233
}
211234
}
212-
self.sess.fatal(format!("could not find native static library `{}`, \
235+
self.handler.fatal(format!("could not find native static library `{}`, \
213236
perhaps an -L flag is missing?",
214237
name).as_slice());
215238
}

branches/dist-snap/src/librustc/back/link.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::archive::{Archive, METADATA_FILENAME};
11+
use super::archive::{Archive, ArchiveConfig, METADATA_FILENAME};
1212
use super::rpath;
1313
use super::rpath::RPathConfig;
1414
use super::svh::Svh;
@@ -29,6 +29,7 @@ use util::sha2::{Digest, Sha256};
2929

3030
use std::c_str::{ToCStr, CString};
3131
use std::char;
32+
use std::collections::HashSet;
3233
use std::io::{fs, TempDir, Command};
3334
use std::io;
3435
use std::ptr;
@@ -962,6 +963,17 @@ fn link_binary_output(sess: &Session,
962963
out_filename
963964
}
964965

966+
fn archive_search_paths(sess: &Session) -> Vec<Path> {
967+
let mut rustpath = filesearch::rust_path();
968+
rustpath.push(sess.target_filesearch().get_lib_path());
969+
// FIXME: Addl lib search paths are an unordered HashSet?
970+
// Shouldn't this search be done in some order?
971+
let addl_lib_paths: HashSet<Path> = sess.opts.addl_lib_search_paths.borrow().clone();
972+
let mut search: Vec<Path> = addl_lib_paths.move_iter().collect();
973+
search.push_all(rustpath.as_slice());
974+
return search;
975+
}
976+
965977
// Create an 'rlib'
966978
//
967979
// An rlib in its current incarnation is essentially a renamed .a file. The
@@ -972,7 +984,15 @@ fn link_rlib<'a>(sess: &'a Session,
972984
trans: Option<&CrateTranslation>, // None == no metadata/bytecode
973985
obj_filename: &Path,
974986
out_filename: &Path) -> Archive<'a> {
975-
let mut a = Archive::create(sess, out_filename, obj_filename);
987+
let handler = &sess.diagnostic().handler;
988+
let config = ArchiveConfig {
989+
handler: handler,
990+
dst: out_filename.clone(),
991+
lib_search_paths: archive_search_paths(sess),
992+
os: sess.targ_cfg.os,
993+
maybe_ar_prog: sess.opts.cg.ar.clone()
994+
};
995+
let mut a = Archive::create(config, obj_filename);
976996

977997
for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
978998
match kind {
@@ -1561,7 +1581,15 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session,
15611581
sess.abort_if_errors();
15621582
}
15631583
}
1564-
let mut archive = Archive::open(sess, dst.clone());
1584+
let handler = &sess.diagnostic().handler;
1585+
let config = ArchiveConfig {
1586+
handler: handler,
1587+
dst: dst.clone(),
1588+
lib_search_paths: archive_search_paths(sess),
1589+
os: sess.targ_cfg.os,
1590+
maybe_ar_prog: sess.opts.cg.ar.clone()
1591+
};
1592+
let mut archive = Archive::open(config);
15651593
archive.remove_file(format!("{}.o", name).as_slice());
15661594
let files = archive.files();
15671595
if files.iter().any(|s| s.as_slice().ends_with(".o")) {

0 commit comments

Comments
 (0)