Inject std libs with versions
This commit is contained in:
parent
f42a36cded
commit
4cb13ed982
3 changed files with 35 additions and 7 deletions
|
@ -21,6 +21,8 @@ use syntax::fold;
|
||||||
use syntax::opt_vec;
|
use syntax::opt_vec;
|
||||||
use syntax::util::small_vector::SmallVector;
|
use syntax::util::small_vector::SmallVector;
|
||||||
|
|
||||||
|
pub static VERSION: &'static str = "0.9-pre";
|
||||||
|
|
||||||
pub fn maybe_inject_libstd_ref(sess: Session, crate: ast::Crate)
|
pub fn maybe_inject_libstd_ref(sess: Session, crate: ast::Crate)
|
||||||
-> ast::Crate {
|
-> ast::Crate {
|
||||||
if use_std(&crate) {
|
if use_std(&crate) {
|
||||||
|
@ -57,7 +59,8 @@ impl fold::ast_fold for StandardLibraryInjector {
|
||||||
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
|
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
|
||||||
let mut vis = ~[ast::view_item {
|
let mut vis = ~[ast::view_item {
|
||||||
node: ast::view_item_extern_mod(self.sess.ident_of("std"),
|
node: ast::view_item_extern_mod(self.sess.ident_of("std"),
|
||||||
None,
|
Some((format!("std\\#{}", VERSION).to_managed(),
|
||||||
|
ast::CookedStr)),
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::private,
|
vis: ast::private,
|
||||||
|
@ -67,7 +70,8 @@ impl fold::ast_fold for StandardLibraryInjector {
|
||||||
if use_uv(&crate) && !self.sess.building_library.get() {
|
if use_uv(&crate) && !self.sess.building_library.get() {
|
||||||
vis.push(ast::view_item {
|
vis.push(ast::view_item {
|
||||||
node: ast::view_item_extern_mod(self.sess.ident_of("green"),
|
node: ast::view_item_extern_mod(self.sess.ident_of("green"),
|
||||||
None,
|
Some((format!("green\\#{}", VERSION).to_managed(),
|
||||||
|
ast::CookedStr)),
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::private,
|
vis: ast::private,
|
||||||
|
@ -75,7 +79,8 @@ impl fold::ast_fold for StandardLibraryInjector {
|
||||||
});
|
});
|
||||||
vis.push(ast::view_item {
|
vis.push(ast::view_item {
|
||||||
node: ast::view_item_extern_mod(self.sess.ident_of("rustuv"),
|
node: ast::view_item_extern_mod(self.sess.ident_of("rustuv"),
|
||||||
None,
|
Some((format!("rustuv\\#{}", VERSION).to_managed(),
|
||||||
|
ast::CookedStr)),
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::private,
|
vis: ast::private,
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
use driver::session;
|
use driver::session;
|
||||||
use front::config;
|
use front::config;
|
||||||
|
use front::std_inject::VERSION;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
@ -291,7 +292,10 @@ fn mk_std(cx: &TestCtxt) -> ast::view_item {
|
||||||
path_node(~[id_extra]),
|
path_node(~[id_extra]),
|
||||||
ast::DUMMY_NODE_ID))])
|
ast::DUMMY_NODE_ID))])
|
||||||
} else {
|
} else {
|
||||||
ast::view_item_extern_mod(id_extra, None, ast::DUMMY_NODE_ID)
|
ast::view_item_extern_mod(id_extra,
|
||||||
|
Some((format!("extra\\#{}", VERSION).to_managed(),
|
||||||
|
ast::CookedStr)),
|
||||||
|
ast::DUMMY_NODE_ID)
|
||||||
};
|
};
|
||||||
ast::view_item {
|
ast::view_item {
|
||||||
node: vi,
|
node: vi,
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
pub use crate_id::CrateId;
|
pub use crate_id::CrateId;
|
||||||
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
|
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
|
||||||
pub use version::{Version, NoVersion, split_version_general, try_parsing_version};
|
pub use version::{Version, ExactRevision, NoVersion, split_version, split_version_general,
|
||||||
|
try_parsing_version};
|
||||||
pub use rustc::metadata::filesearch::rust_path;
|
pub use rustc::metadata::filesearch::rust_path;
|
||||||
use rustc::metadata::filesearch::libdir;
|
use rustc::metadata::filesearch::libdir;
|
||||||
use rustc::driver::driver::host_triple;
|
use rustc::driver::driver::host_triple;
|
||||||
|
@ -213,8 +214,9 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
|
||||||
}
|
}
|
||||||
|
|
||||||
// rustc doesn't use target-specific subdirectories
|
// rustc doesn't use target-specific subdirectories
|
||||||
pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
|
pub fn system_library(sysroot: &Path, crate_id: &str) -> Option<Path> {
|
||||||
library_in(lib_name, &NoVersion, &sysroot.join(libdir()))
|
let (lib_name, version) = split_crate_id(crate_id);
|
||||||
|
library_in(lib_name, &version, &sysroot.join(libdir()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
|
fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
|
||||||
|
@ -268,6 +270,7 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
|
||||||
}
|
}
|
||||||
None => break
|
None => break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
_ => { f_name = f_name.slice(0, i); }
|
_ => { f_name = f_name.slice(0, i); }
|
||||||
}
|
}
|
||||||
|
@ -293,6 +296,22 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
|
||||||
abs_path
|
abs_path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) {
|
||||||
|
match split_version(crate_id) {
|
||||||
|
Some((name, vers)) =>
|
||||||
|
match vers {
|
||||||
|
ExactRevision(ref v) => match v.find('-') {
|
||||||
|
Some(pos) => (name, ExactRevision(v.slice(0, pos).to_owned())),
|
||||||
|
None => (name, ExactRevision(v.to_owned()))
|
||||||
|
},
|
||||||
|
_ => (name, vers)
|
||||||
|
},
|
||||||
|
None => (crate_id, NoVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Returns the executable that would be installed for <crateid>
|
/// Returns the executable that would be installed for <crateid>
|
||||||
/// in <workspace>
|
/// in <workspace>
|
||||||
/// As a side effect, creates the bin-dir if it doesn't exist
|
/// As a side effect, creates the bin-dir if it doesn't exist
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue