From 4cb13ed9823d30ac3163e7e6b3e74becd09a508d Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 1 Jan 2014 23:36:03 +0100 Subject: [PATCH] Inject std libs with versions --- src/librustc/front/std_inject.rs | 11 ++++++++--- src/librustc/front/test.rs | 6 +++++- src/librustpkg/path_util.rs | 25 ++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/librustc/front/std_inject.rs b/src/librustc/front/std_inject.rs index f25bd14e1da1a..51b65bcce41ca 100644 --- a/src/librustc/front/std_inject.rs +++ b/src/librustc/front/std_inject.rs @@ -21,6 +21,8 @@ use syntax::fold; use syntax::opt_vec; 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) -> ast::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 { let mut vis = ~[ast::view_item { node: ast::view_item_extern_mod(self.sess.ident_of("std"), - None, + Some((format!("std\\#{}", VERSION).to_managed(), + ast::CookedStr)), ast::DUMMY_NODE_ID), attrs: ~[], vis: ast::private, @@ -67,7 +70,8 @@ impl fold::ast_fold for StandardLibraryInjector { if use_uv(&crate) && !self.sess.building_library.get() { vis.push(ast::view_item { node: ast::view_item_extern_mod(self.sess.ident_of("green"), - None, + Some((format!("green\\#{}", VERSION).to_managed(), + ast::CookedStr)), ast::DUMMY_NODE_ID), attrs: ~[], vis: ast::private, @@ -75,7 +79,8 @@ impl fold::ast_fold for StandardLibraryInjector { }); vis.push(ast::view_item { node: ast::view_item_extern_mod(self.sess.ident_of("rustuv"), - None, + Some((format!("rustuv\\#{}", VERSION).to_managed(), + ast::CookedStr)), ast::DUMMY_NODE_ID), attrs: ~[], vis: ast::private, diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 6a07222100895..fb19f20d12958 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -13,6 +13,7 @@ use driver::session; use front::config; +use front::std_inject::VERSION; use std::cell::RefCell; use std::vec; @@ -291,7 +292,10 @@ fn mk_std(cx: &TestCtxt) -> ast::view_item { path_node(~[id_extra]), ast::DUMMY_NODE_ID))]) } 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 { node: vi, diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index 1b8a988ab2c5a..aaaf56af436b4 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -14,7 +14,8 @@ pub use crate_id::CrateId; 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; use rustc::metadata::filesearch::libdir; 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 -pub fn system_library(sysroot: &Path, lib_name: &str) -> Option { - library_in(lib_name, &NoVersion, &sysroot.join(libdir())) +pub fn system_library(sysroot: &Path, crate_id: &str) -> Option { + 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 { @@ -268,6 +270,7 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti } None => break } + } _ => { 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 } +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 /// in /// As a side effect, creates the bin-dir if it doesn't exist