From d085d9d3151a684cb8b7471e4b0f6e243e68ed8b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Dec 2014 14:32:02 -0800 Subject: [PATCH] rustc: Add knowledge of separate lookup paths This commit adds support for the compiler to distinguish between different forms of lookup paths in the compiler itself. Issue #19767 has some background on this topic, as well as some sample bugs which can occur if these lookup paths are not separated. This commits extends the existing command line flag `-L` with the same trailing syntax as the `-l` flag. Each argument to `-L` can now have a trailing `:all`, `:native`, `:crate`, or `:dependency`. This suffix indicates what form of lookup path the compiler should add the argument to. The `dependency` lookup path is used when looking up crate dependencies, the `crate` lookup path is used when looking for immediate dependencies (`extern crate` statements), and the `native` lookup path is used for probing for native libraries to insert into rlibs. Paths with `all` are used for all of these purposes (the default). The default compiler lookup path (the rustlib libdir) is by default added to all of these paths. Additionally, the `RUST_PATH` lookup path is added to all of these paths. Closes #19767 --- src/librustc/metadata/creader.rs | 21 +++--- src/librustc/metadata/filesearch.rs | 15 ++-- src/librustc/session/config.rs | 15 ++-- src/librustc/session/mod.rs | 14 ++-- src/librustc/session/search_paths.rs | 69 +++++++++++++++++++ src/librustc_driver/driver.rs | 5 +- src/librustc_trans/back/link.rs | 23 +++---- src/librustdoc/core.rs | 5 +- src/librustdoc/lib.rs | 16 +++-- src/librustdoc/markdown.rs | 4 +- src/librustdoc/test.rs | 16 +++-- .../run-make/compiler-lookup-paths/Makefile | 30 ++++++++ src/test/run-make/compiler-lookup-paths/a.rs | 11 +++ src/test/run-make/compiler-lookup-paths/b.rs | 12 ++++ src/test/run-make/compiler-lookup-paths/c.rs | 13 ++++ src/test/run-make/compiler-lookup-paths/d.rs | 14 ++++ src/test/run-make/compiler-lookup-paths/e.rs | 12 ++++ src/test/run-make/compiler-lookup-paths/f.rs | 12 ++++ .../run-make/compiler-lookup-paths/native.c | 0 .../run-make/staticlib-blank-lib/Makefile | 4 +- 20 files changed, 251 insertions(+), 60 deletions(-) create mode 100644 src/librustc/session/search_paths.rs create mode 100644 src/test/run-make/compiler-lookup-paths/Makefile create mode 100644 src/test/run-make/compiler-lookup-paths/a.rs create mode 100644 src/test/run-make/compiler-lookup-paths/b.rs create mode 100644 src/test/run-make/compiler-lookup-paths/c.rs create mode 100644 src/test/run-make/compiler-lookup-paths/d.rs create mode 100644 src/test/run-make/compiler-lookup-paths/e.rs create mode 100644 src/test/run-make/compiler-lookup-paths/f.rs create mode 100644 src/test/run-make/compiler-lookup-paths/native.c diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 98b57511957f6..e03d645aec367 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -14,6 +14,7 @@ use back::svh::Svh; use session::{config, Session}; +use session::search_paths::PathKind; use metadata::cstore; use metadata::cstore::{CStore, CrateSource}; use metadata::decoder; @@ -134,7 +135,8 @@ fn visit_view_item(e: &mut Env, i: &ast::ViewItem) { info.ident[], info.name[], None, - i.span); + i.span, + PathKind::Crate); e.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum); } None => () @@ -388,12 +390,13 @@ fn register_crate<'a>(e: &mut Env, (cnum, cmeta, source) } -fn resolve_crate<'a>(e: &mut Env, +fn resolve_crate(e: &mut Env, root: &Option, ident: &str, name: &str, hash: Option<&Svh>, - span: Span) + span: Span, + kind: PathKind) -> (ast::CrateNum, Rc, cstore::CrateSource) { match existing_match(e, name, hash) { @@ -404,7 +407,7 @@ fn resolve_crate<'a>(e: &mut Env, ident: ident, crate_name: name, hash: hash.map(|a| &*a), - filesearch: e.sess.target_filesearch(), + filesearch: e.sess.target_filesearch(kind), triple: e.sess.opts.target_triple[], root: root, rejected_via_hash: vec!(), @@ -434,7 +437,8 @@ fn resolve_crate_deps(e: &mut Env, dep.name[], dep.name[], Some(&dep.hash), - span); + span, + PathKind::Dependency); (dep.cnum, local_cnum) }).collect() } @@ -453,7 +457,8 @@ impl<'a> PluginMetadataReader<'a> { } } - pub fn read_plugin_metadata(&mut self, krate: &ast::ViewItem) -> PluginMetadata { + pub fn read_plugin_metadata(&mut self, + krate: &ast::ViewItem) -> PluginMetadata { let info = extract_crate_info(&self.env, krate).unwrap(); let target_triple = self.env.sess.opts.target_triple[]; let is_cross = target_triple != config::host_triple(); @@ -464,7 +469,7 @@ impl<'a> PluginMetadataReader<'a> { ident: info.ident[], crate_name: info.name[], hash: None, - filesearch: self.env.sess.host_filesearch(), + filesearch: self.env.sess.host_filesearch(PathKind::Crate), triple: config::host_triple(), root: &None, rejected_via_hash: vec!(), @@ -477,7 +482,7 @@ impl<'a> PluginMetadataReader<'a> { // try loading from target crates (only valid if there are // no syntax extensions) load_ctxt.triple = target_triple; - load_ctxt.filesearch = self.env.sess.target_filesearch(); + load_ctxt.filesearch = self.env.sess.target_filesearch(PathKind::Crate); let lib = load_ctxt.load_library_crate(); if decoder::get_plugin_registrar_fn(lib.metadata.as_slice()).is_some() { let message = format!("crate `{}` contains a plugin_registrar fn but \ diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 0b859abc531c8..cc67f3ddf0330 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -12,13 +12,13 @@ pub use self::FileMatch::*; -use std::cell::RefCell; use std::collections::HashSet; use std::io::fs::PathExtensions; use std::io::fs; use std::os; use util::fs as myfs; +use session::search_paths::{SearchPaths, PathKind}; #[deriving(Copy)] pub enum FileMatch { @@ -36,8 +36,9 @@ pub type pick<'a> = |path: &Path|: 'a -> FileMatch; pub struct FileSearch<'a> { pub sysroot: &'a Path, - pub addl_lib_search_paths: &'a RefCell>, + pub search_paths: &'a SearchPaths, pub triple: &'a str, + pub kind: PathKind, } impl<'a> FileSearch<'a> { @@ -47,9 +48,7 @@ impl<'a> FileSearch<'a> { let mut visited_dirs = HashSet::new(); let mut found = false; - debug!("filesearch: searching additional lib search paths [{}]", - self.addl_lib_search_paths.borrow().len()); - for path in self.addl_lib_search_paths.borrow().iter() { + for path in self.search_paths.iter(self.kind) { match f(path) { FileMatches => found = true, FileDoesntMatch => () @@ -133,12 +132,14 @@ impl<'a> FileSearch<'a> { pub fn new(sysroot: &'a Path, triple: &'a str, - addl_lib_search_paths: &'a RefCell>) -> FileSearch<'a> { + search_paths: &'a SearchPaths, + kind: PathKind) -> FileSearch<'a> { debug!("using sysroot = {}, triple = {}", sysroot.display(), triple); FileSearch { sysroot: sysroot, - addl_lib_search_paths: addl_lib_search_paths, + search_paths: search_paths, triple: triple, + kind: kind, } } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 6629f6620d484..0cbbbfe3d36ea 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -19,6 +19,7 @@ pub use self::OutputType::*; pub use self::DebugInfoLevel::*; use session::{early_error, Session}; +use session::search_paths::SearchPaths; use rustc_back::target::Target; use lint; @@ -35,7 +36,6 @@ use syntax::parse::token::InternedString; use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; use getopts; -use std::cell::{RefCell}; use std::fmt; use llvm; @@ -86,7 +86,7 @@ pub struct Options { // This was mutable for rustpkg, which updates search paths based on the // parsed code. It remains mutable in case its replacements wants to use // this. - pub addl_lib_search_paths: RefCell>, + pub search_paths: SearchPaths, pub libs: Vec<(String, cstore::NativeLibraryKind)>, pub maybe_sysroot: Option, pub target_triple: String, @@ -198,7 +198,7 @@ pub fn basic_options() -> Options { lint_opts: Vec::new(), describe_lints: false, output_types: Vec::new(), - addl_lib_search_paths: RefCell::new(Vec::new()), + search_paths: SearchPaths::new(), maybe_sysroot: None, target_triple: host_triple().to_string(), cfg: Vec::new(), @@ -1007,9 +1007,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { } }; - let addl_lib_search_paths = matches.opt_strs("L").iter().map(|s| { - Path::new(s[]) - }).collect(); + let mut search_paths = SearchPaths::new(); + for s in matches.opt_strs("L").iter() { + search_paths.add_path(s[]); + } let libs = matches.opt_strs("l").into_iter().map(|s| { let mut parts = s.rsplitn(1, ':'); @@ -1109,7 +1110,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { lint_opts: lint_opts, describe_lints: describe_lints, output_types: output_types, - addl_lib_search_paths: RefCell::new(addl_lib_search_paths), + search_paths: search_paths, maybe_sysroot: sysroot_opt, target_triple: target, cfg: cfg, diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 37bdd1673e9ca..06e9379a07b8f 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -9,9 +9,10 @@ // except according to those terms. +use lint; use metadata::cstore::CStore; use metadata::filesearch; -use lint; +use session::search_paths::PathKind; use util::nodemap::NodeMap; use syntax::ast::NodeId; @@ -28,6 +29,7 @@ use std::os; use std::cell::{Cell, RefCell}; pub mod config; +pub mod search_paths; // Represents the data associated with a compilation // session for a single crate. @@ -209,16 +211,18 @@ impl Session { .expect("missing sysroot and default_sysroot in Session") } } - pub fn target_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { + pub fn target_filesearch(&self, kind: PathKind) -> filesearch::FileSearch { filesearch::FileSearch::new(self.sysroot(), self.opts.target_triple[], - &self.opts.addl_lib_search_paths) + &self.opts.search_paths, + kind) } - pub fn host_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { + pub fn host_filesearch(&self, kind: PathKind) -> filesearch::FileSearch { filesearch::FileSearch::new( self.sysroot(), config::host_triple(), - &self.opts.addl_lib_search_paths) + &self.opts.search_paths, + kind) } } diff --git a/src/librustc/session/search_paths.rs b/src/librustc/session/search_paths.rs new file mode 100644 index 0000000000000..8a6217a49f560 --- /dev/null +++ b/src/librustc/session/search_paths.rs @@ -0,0 +1,69 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::slice; + +#[deriving(Clone)] +pub struct SearchPaths { + paths: Vec<(PathKind, Path)>, +} + +pub struct Iter<'a> { + kind: PathKind, + iter: slice::Iter<'a, (PathKind, Path)>, +} + +#[deriving(Eq, PartialEq, Clone, Copy)] +pub enum PathKind { + Native, + Crate, + Dependency, + All, +} + +impl SearchPaths { + pub fn new() -> SearchPaths { + SearchPaths { paths: Vec::new() } + } + + pub fn add_path(&mut self, path: &str) { + let (kind, path) = if path.ends_with(":native") { + (PathKind::Native, path.slice_to(path.len() - ":native".len())) + } else if path.ends_with(":crate") { + (PathKind::Crate, path.slice_to(path.len() - ":crate".len())) + } else if path.ends_with(":dependency") { + (PathKind::Dependency, + path.slice_to(path.len() - ":dependency".len())) + } else if path.ends_with(":all") { + (PathKind::All, path.slice_to(path.len() - ":all".len())) + } else { + (PathKind::All, path) + }; + self.paths.push((kind, Path::new(path))); + } + + pub fn iter(&self, kind: PathKind) -> Iter { + Iter { kind: kind, iter: self.paths.iter() } + } +} + +impl<'a> Iterator<&'a Path> for Iter<'a> { + fn next(&mut self) -> Option<&'a Path> { + loop { + match self.iter.next() { + Some(&(kind, ref p)) if self.kind == PathKind::All || + kind == PathKind::All || + kind == self.kind => return Some(p), + Some(..) => {} + None => return None, + } + } + } +} diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 20bb9c2f4fd1c..f7e9f52751e16 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -10,6 +10,7 @@ use rustc::session::Session; use rustc::session::config::{mod, Input, OutputFilenames}; +use rustc::session::search_paths::PathKind; use rustc::lint; use rustc::metadata::creader; use rustc::middle::{stability, ty, reachable}; @@ -256,7 +257,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, let mut _old_path = String::new(); if cfg!(windows) { _old_path = os::getenv("PATH").unwrap_or(_old_path); - let mut new_path = sess.host_filesearch().get_dylib_search_paths(); + let mut new_path = sess.host_filesearch(PathKind::All).get_dylib_search_paths(); new_path.extend(os::split_paths(_old_path[]).into_iter()); os::setenv("PATH", os::join_paths(new_path[]).unwrap()); } @@ -516,7 +517,7 @@ pub fn phase_6_link_output(sess: &Session, trans: &trans::CrateTranslation, outputs: &OutputFilenames) { let old_path = os::getenv("PATH").unwrap_or_else(||String::new()); - let mut new_path = sess.host_filesearch().get_tools_search_paths(); + let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(); new_path.extend(os::split_paths(old_path[]).into_iter()); os::setenv("PATH", os::join_paths(new_path[]).unwrap()); diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index ec61d3a69537c..39ba2a98ce42a 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -16,9 +16,11 @@ use super::svh::Svh; use session::config; use session::config::NoDebugInfo; use session::config::{OutputFilenames, Input, OutputTypeBitcode, OutputTypeExe, OutputTypeObject}; +use session::search_paths::PathKind; use session::Session; use metadata::common::LinkMeta; use metadata::{encoder, cstore, filesearch, csearch, creader}; +use metadata::filesearch::FileDoesntMatch; use trans::{CrateContext, CrateTranslation, gensym_name}; use middle::ty::{mod, Ty}; use util::common::time; @@ -504,10 +506,11 @@ fn link_binary_output(sess: &Session, } fn archive_search_paths(sess: &Session) -> Vec { - let mut rustpath = filesearch::rust_path(); - rustpath.push(sess.target_filesearch().get_lib_path()); - let mut search: Vec = sess.opts.addl_lib_search_paths.borrow().clone(); - search.push_all(rustpath[]); + let mut search = Vec::new(); + sess.target_filesearch(PathKind::Native).for_each_lib_search_path(|path| { + search.push(path.clone()); + FileDoesntMatch + }); return search; } @@ -832,7 +835,7 @@ fn link_args(cmd: &mut Command, // The default library location, we need this to find the runtime. // The location of crates will be determined as needed. - let lib_path = sess.target_filesearch().get_lib_path(); + let lib_path = sess.target_filesearch(PathKind::All).get_lib_path(); // target descriptor let t = &sess.target.target; @@ -1040,14 +1043,10 @@ fn link_args(cmd: &mut Command, // in the current crate. Upstream crates with native library dependencies // may have their native library pulled in above. fn add_local_native_libraries(cmd: &mut Command, sess: &Session) { - for path in sess.opts.addl_lib_search_paths.borrow().iter() { - cmd.arg("-L").arg(path); - } - - let rustpath = filesearch::rust_path(); - for path in rustpath.iter() { + sess.target_filesearch(PathKind::All).for_each_lib_search_path(|path| { cmd.arg("-L").arg(path); - } + FileDoesntMatch + }); // Some platforms take hints about whether a library is static or dynamic. // For those that support this, we ensure we pass the option if the library diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 4cd88bca51e93..a80de6e805b25 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -11,6 +11,7 @@ pub use self::MaybeTyped::*; use rustc_driver::driver; use rustc::session::{mod, config}; +use rustc::session::search_paths::SearchPaths; use rustc::middle::{privacy, ty}; use rustc::lint; use rustc_trans::back::link; @@ -77,7 +78,7 @@ pub struct CrateAnalysis { pub type Externs = HashMap>; -pub fn run_core(libs: Vec, cfgs: Vec, externs: Externs, +pub fn run_core(search_paths: SearchPaths, cfgs: Vec, externs: Externs, cpath: &Path, triple: Option) -> (clean::Crate, CrateAnalysis) { @@ -89,7 +90,7 @@ pub fn run_core(libs: Vec, cfgs: Vec, externs: Externs, let sessopts = config::Options { maybe_sysroot: None, - addl_lib_search_paths: RefCell::new(libs), + search_paths: search_paths, crate_types: vec!(config::CrateTypeRlib), lint_opts: vec!((warning_lint, lint::Allow)), externs: externs, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 8dfb352d0288f..8b66d5751e4cc 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -43,6 +43,7 @@ use std::rc::Rc; use externalfiles::ExternalHtml; use serialize::{Decodable, Encodable}; use serialize::json::{mod, Json}; +use rustc::session::search_paths::SearchPaths; // reexported from `clean` so it can be easily updated with the mod itself pub use clean::SCHEMA_VERSION; @@ -200,7 +201,10 @@ pub fn main_args(args: &[String]) -> int { } let input = matches.free[0].as_slice(); - let libs = matches.opt_strs("L").iter().map(|s| Path::new(s.as_slice())).collect(); + let mut libs = SearchPaths::new(); + for s in matches.opt_strs("L").iter() { + libs.add_path(s.as_slice()); + } let externs = match parse_externs(&matches) { Ok(ex) => ex, Err(err) => { @@ -334,10 +338,10 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche let mut plugins = matches.opt_strs("plugins"); // First, parse the crate and extract all relevant information. - let libs: Vec = matches.opt_strs("L") - .iter() - .map(|s| Path::new(s.as_slice())) - .collect(); + let mut paths = SearchPaths::new(); + for s in matches.opt_strs("L").iter() { + paths.add_path(s.as_slice()); + } let cfgs = matches.opt_strs("cfg"); let triple = matches.opt_str("target"); @@ -346,7 +350,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche let (mut krate, analysis) = std::thread::Thread::spawn(move |:| { let cr = cr; - core::run_core(libs, cfgs, externs, &cr, triple) + core::run_core(paths, cfgs, externs, &cr, triple) }).join().map_err(|_| "rustc failed").unwrap(); info!("finished with rustc"); let mut analysis = Some(analysis); diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 881c7a91d81d0..ab9c4ef942230 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -9,11 +9,11 @@ // except according to those terms. use std::io; -use std::string::String; use core; use getopts; use testing; +use rustc::session::search_paths::SearchPaths; use externalfiles::ExternalHtml; @@ -135,7 +135,7 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches, } /// Run any tests/code examples in the markdown file `input`. -pub fn test(input: &str, libs: Vec, externs: core::Externs, +pub fn test(input: &str, libs: SearchPaths, externs: core::Externs, mut test_args: Vec) -> int { let input_str = load_or_return!(input, 1, 2); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index b55097c0c5a1b..ba66c51b8fc68 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -21,6 +21,7 @@ use std::thread::Thread; use std::collections::{HashSet, HashMap}; use testing; use rustc::session::{mod, config}; +use rustc::session::search_paths::{SearchPaths, PathKind}; use rustc_driver::driver; use syntax::ast; use syntax::codemap::{CodeMap, dummy_spanned}; @@ -38,7 +39,7 @@ use visit_ast::RustdocVisitor; pub fn run(input: &str, cfgs: Vec, - libs: Vec, + libs: SearchPaths, externs: core::Externs, mut test_args: Vec, crate_name: Option) @@ -48,7 +49,7 @@ pub fn run(input: &str, let sessopts = config::Options { maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()), - addl_lib_search_paths: RefCell::new(libs.clone()), + search_paths: libs.clone(), crate_types: vec!(config::CrateTypeDylib), externs: externs.clone(), ..config::basic_options().clone() @@ -107,7 +108,8 @@ pub fn run(input: &str, 0 } -fn runtest(test: &str, cratename: &str, libs: Vec, externs: core::Externs, +fn runtest(test: &str, cratename: &str, libs: SearchPaths, + externs: core::Externs, should_fail: bool, no_run: bool, as_test_harness: bool) { // the test harness wants its own `main` & top level functions, so // never wrap the test in `fn main() { ... }` @@ -116,7 +118,7 @@ fn runtest(test: &str, cratename: &str, libs: Vec, externs: core::Externs, let sessopts = config::Options { maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()), - addl_lib_search_paths: RefCell::new(libs), + search_paths: libs, crate_types: vec!(config::CrateTypeExecutable), output_types: vec!(config::OutputTypeExe), no_trans: no_run, @@ -171,7 +173,7 @@ fn runtest(test: &str, cratename: &str, libs: Vec, externs: core::Externs, let outdir = TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir"); let out = Some(outdir.path().clone()); let cfg = config::build_configuration(&sess); - let libdir = sess.target_filesearch().get_lib_path(); + let libdir = sess.target_filesearch(PathKind::All).get_lib_path(); driver::compile_input(sess, cfg, &input, &out, &None, None); if no_run { return } @@ -242,7 +244,7 @@ pub fn maketest(s: &str, cratename: Option<&str>, lints: bool, dont_insert_main: pub struct Collector { pub tests: Vec, names: Vec, - libs: Vec, + libs: SearchPaths, externs: core::Externs, cnt: uint, use_headers: bool, @@ -251,7 +253,7 @@ pub struct Collector { } impl Collector { - pub fn new(cratename: String, libs: Vec, externs: core::Externs, + pub fn new(cratename: String, libs: SearchPaths, externs: core::Externs, use_headers: bool) -> Collector { Collector { tests: Vec::new(), diff --git a/src/test/run-make/compiler-lookup-paths/Makefile b/src/test/run-make/compiler-lookup-paths/Makefile new file mode 100644 index 0000000000000..032e0882ff8e2 --- /dev/null +++ b/src/test/run-make/compiler-lookup-paths/Makefile @@ -0,0 +1,30 @@ +-include ../tools.mk + +all: $(TMPDIR)/libnative.a + mkdir -p $(TMPDIR)/crate + mkdir -p $(TMPDIR)/native + mv $(TMPDIR)/libnative.a $(TMPDIR)/native + $(RUSTC) a.rs + mv $(TMPDIR)/liba.rlib $(TMPDIR)/crate + $(RUSTC) b.rs -L $(TMPDIR)/crate:native && exit 1 || exit 0 + $(RUSTC) b.rs -L $(TMPDIR)/crate:dependency && exit 1 || exit 0 + $(RUSTC) b.rs -L $(TMPDIR)/crate:crate + $(RUSTC) b.rs -L $(TMPDIR)/crate + $(RUSTC) c.rs -L $(TMPDIR)/crate:native && exit 1 || exit 0 + $(RUSTC) c.rs -L $(TMPDIR)/crate:crate && exit 1 || exit 0 + $(RUSTC) c.rs -L $(TMPDIR)/crate:dependency + $(RUSTC) c.rs -L $(TMPDIR)/crate + $(RUSTC) d.rs -L $(TMPDIR)/native:dependency && exit 1 || exit 0 + $(RUSTC) d.rs -L $(TMPDIR)/native:crate && exit 1 || exit 0 + $(RUSTC) d.rs -L $(TMPDIR)/native:native + $(RUSTC) d.rs -L $(TMPDIR)/native + mkdir -p $(TMPDIR)/e1 + mkdir -p $(TMPDIR)/e2 + $(RUSTC) e.rs -o $(TMPDIR)/e1/libe.rlib + $(RUSTC) e.rs -o $(TMPDIR)/e2/libe.rlib + $(RUSTC) f.rs -L $(TMPDIR)/e1 -L $(TMPDIR)/e2 && exit 1 || exit 0 + $(RUSTC) f.rs -L $(TMPDIR)/e1:crate -L $(TMPDIR)/e2 && exit 1 || exit 0 + $(RUSTC) f.rs -L $(TMPDIR)/e1:crate -L $(TMPDIR)/e2:crate && exit 1 || exit 0 + $(RUSTC) f.rs -L $(TMPDIR)/e1:native -L $(TMPDIR)/e2 + $(RUSTC) f.rs -L $(TMPDIR)/e1:dependency -L $(TMPDIR)/e2 + $(RUSTC) f.rs -L $(TMPDIR)/e1:dependency -L $(TMPDIR)/e2:crate diff --git a/src/test/run-make/compiler-lookup-paths/a.rs b/src/test/run-make/compiler-lookup-paths/a.rs new file mode 100644 index 0000000000000..4ddf231fba2a4 --- /dev/null +++ b/src/test/run-make/compiler-lookup-paths/a.rs @@ -0,0 +1,11 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "lib"] diff --git a/src/test/run-make/compiler-lookup-paths/b.rs b/src/test/run-make/compiler-lookup-paths/b.rs new file mode 100644 index 0000000000000..c38300f976ebc --- /dev/null +++ b/src/test/run-make/compiler-lookup-paths/b.rs @@ -0,0 +1,12 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "lib"] +extern crate a; diff --git a/src/test/run-make/compiler-lookup-paths/c.rs b/src/test/run-make/compiler-lookup-paths/c.rs new file mode 100644 index 0000000000000..8a801d589fb81 --- /dev/null +++ b/src/test/run-make/compiler-lookup-paths/c.rs @@ -0,0 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "lib"] +extern crate b; + diff --git a/src/test/run-make/compiler-lookup-paths/d.rs b/src/test/run-make/compiler-lookup-paths/d.rs new file mode 100644 index 0000000000000..295b6e00e41ab --- /dev/null +++ b/src/test/run-make/compiler-lookup-paths/d.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +#[link(name = "native", kind = "static")] +extern {} diff --git a/src/test/run-make/compiler-lookup-paths/e.rs b/src/test/run-make/compiler-lookup-paths/e.rs new file mode 100644 index 0000000000000..c0407aba7c9f5 --- /dev/null +++ b/src/test/run-make/compiler-lookup-paths/e.rs @@ -0,0 +1,12 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "e"] +#![crate_type = "rlib"] diff --git a/src/test/run-make/compiler-lookup-paths/f.rs b/src/test/run-make/compiler-lookup-paths/f.rs new file mode 100644 index 0000000000000..e616042257625 --- /dev/null +++ b/src/test/run-make/compiler-lookup-paths/f.rs @@ -0,0 +1,12 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] +extern crate e; diff --git a/src/test/run-make/compiler-lookup-paths/native.c b/src/test/run-make/compiler-lookup-paths/native.c new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/test/run-make/staticlib-blank-lib/Makefile b/src/test/run-make/staticlib-blank-lib/Makefile index c56d1212047e8..5878eec66bad4 100644 --- a/src/test/run-make/staticlib-blank-lib/Makefile +++ b/src/test/run-make/staticlib-blank-lib/Makefile @@ -1,6 +1,6 @@ -include ../tools.mk all: - ar crus libfoo.a foo.rs - ar d libfoo.a foo.rs + ar crus $(TMPDIR)/libfoo.a foo.rs + ar d $(TMPDIR)/libfoo.a foo.rs $(RUSTC) foo.rs