Skip to content

Commit

Permalink
Inject std libs with versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fhahn committed Jan 2, 2014
1 parent f42a36c commit 4cb13ed
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/librustc/front/std_inject.rs
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -67,15 +70,17 @@ 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,
span: dummy_sp()
});
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,
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/front/test.rs
Expand Up @@ -13,6 +13,7 @@

use driver::session;
use front::config;
use front::std_inject::VERSION;

use std::cell::RefCell;
use std::vec;
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 22 additions & 3 deletions src/librustpkg/path_util.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Path> {
library_in(lib_name, &NoVersion, &sysroot.join(libdir()))
pub fn system_library(sysroot: &Path, crate_id: &str) -> Option<Path> {
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> {
Expand Down Expand Up @@ -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); }
}
Expand All @@ -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 <crateid>
/// in <workspace>
/// As a side effect, creates the bin-dir if it doesn't exist
Expand Down

5 comments on commit 4cb13ed

@bors
Copy link
Contributor

@bors bors commented on 4cb13ed Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at fhahn@4cb13ed

@bors
Copy link
Contributor

@bors bors commented on 4cb13ed Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging fhahn/rust/issue9543-remove-extern-mod-foo = 4cb13ed into auto

@bors
Copy link
Contributor

@bors bors commented on 4cb13ed Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fhahn/rust/issue9543-remove-extern-mod-foo = 4cb13ed merged ok, testing candidate = 0df9b85

@bors
Copy link
Contributor

@bors bors commented on 4cb13ed Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 4cb13ed Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 0df9b85

Please sign in to comment.