Skip to content

Commit 4cb13ed

Browse files
committed
Inject std libs with versions
1 parent f42a36c commit 4cb13ed

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

src/librustc/front/std_inject.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use syntax::fold;
2121
use syntax::opt_vec;
2222
use syntax::util::small_vector::SmallVector;
2323

24+
pub static VERSION: &'static str = "0.9-pre";
25+
2426
pub fn maybe_inject_libstd_ref(sess: Session, crate: ast::Crate)
2527
-> ast::Crate {
2628
if use_std(&crate) {
@@ -57,7 +59,8 @@ impl fold::ast_fold for StandardLibraryInjector {
5759
fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
5860
let mut vis = ~[ast::view_item {
5961
node: ast::view_item_extern_mod(self.sess.ident_of("std"),
60-
None,
62+
Some((format!("std\\#{}", VERSION).to_managed(),
63+
ast::CookedStr)),
6164
ast::DUMMY_NODE_ID),
6265
attrs: ~[],
6366
vis: ast::private,
@@ -67,15 +70,17 @@ impl fold::ast_fold for StandardLibraryInjector {
6770
if use_uv(&crate) && !self.sess.building_library.get() {
6871
vis.push(ast::view_item {
6972
node: ast::view_item_extern_mod(self.sess.ident_of("green"),
70-
None,
73+
Some((format!("green\\#{}", VERSION).to_managed(),
74+
ast::CookedStr)),
7175
ast::DUMMY_NODE_ID),
7276
attrs: ~[],
7377
vis: ast::private,
7478
span: dummy_sp()
7579
});
7680
vis.push(ast::view_item {
7781
node: ast::view_item_extern_mod(self.sess.ident_of("rustuv"),
78-
None,
82+
Some((format!("rustuv\\#{}", VERSION).to_managed(),
83+
ast::CookedStr)),
7984
ast::DUMMY_NODE_ID),
8085
attrs: ~[],
8186
vis: ast::private,

src/librustc/front/test.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use driver::session;
1515
use front::config;
16+
use front::std_inject::VERSION;
1617

1718
use std::cell::RefCell;
1819
use std::vec;
@@ -291,7 +292,10 @@ fn mk_std(cx: &TestCtxt) -> ast::view_item {
291292
path_node(~[id_extra]),
292293
ast::DUMMY_NODE_ID))])
293294
} else {
294-
ast::view_item_extern_mod(id_extra, None, ast::DUMMY_NODE_ID)
295+
ast::view_item_extern_mod(id_extra,
296+
Some((format!("extra\\#{}", VERSION).to_managed(),
297+
ast::CookedStr)),
298+
ast::DUMMY_NODE_ID)
295299
};
296300
ast::view_item {
297301
node: vi,

src/librustpkg/path_util.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
pub use crate_id::CrateId;
1616
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
17-
pub use version::{Version, NoVersion, split_version_general, try_parsing_version};
17+
pub use version::{Version, ExactRevision, NoVersion, split_version, split_version_general,
18+
try_parsing_version};
1819
pub use rustc::metadata::filesearch::rust_path;
1920
use rustc::metadata::filesearch::libdir;
2021
use rustc::driver::driver::host_triple;
@@ -213,8 +214,9 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
213214
}
214215

215216
// rustc doesn't use target-specific subdirectories
216-
pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
217-
library_in(lib_name, &NoVersion, &sysroot.join(libdir()))
217+
pub fn system_library(sysroot: &Path, crate_id: &str) -> Option<Path> {
218+
let (lib_name, version) = split_crate_id(crate_id);
219+
library_in(lib_name, &version, &sysroot.join(libdir()))
218220
}
219221

220222
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
268270
}
269271
None => break
270272
}
273+
271274
}
272275
_ => { f_name = f_name.slice(0, i); }
273276
}
@@ -293,6 +296,22 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
293296
abs_path
294297
}
295298

299+
fn split_crate_id<'a>(crate_id: &'a str) -> (&'a str, Version) {
300+
match split_version(crate_id) {
301+
Some((name, vers)) =>
302+
match vers {
303+
ExactRevision(ref v) => match v.find('-') {
304+
Some(pos) => (name, ExactRevision(v.slice(0, pos).to_owned())),
305+
None => (name, ExactRevision(v.to_owned()))
306+
},
307+
_ => (name, vers)
308+
},
309+
None => (crate_id, NoVersion)
310+
}
311+
}
312+
313+
314+
296315
/// Returns the executable that would be installed for <crateid>
297316
/// in <workspace>
298317
/// As a side effect, creates the bin-dir if it doesn't exist

0 commit comments

Comments
 (0)