Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustpkg: Handle requested versions in extern mod directives properly #10494

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@

use metadata::cstore;
use metadata::decoder;
use metadata::filesearch::FileSearch;
use metadata::filesearch::{FileSearch, split_version};
use metadata::loader;

use std::hashmap::HashMap;
use syntax::ast;
use std::vec;
use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{Span, dummy_sp};
Expand Down Expand Up @@ -143,15 +142,30 @@ fn visit_view_item(e: @mut Env, i: &ast::view_item) {
let meta_items = match path_opt {
None => meta_items.clone(),
Some((p, _path_str_style)) => {
let p_path = Path::new(p);
match p_path.filestem_str() {
None|Some("") =>
e.diag.span_bug(i.span, "Bad package path in `extern mod` item"),
Some(s) =>
vec::append(
~[attr::mk_name_value_item_str(@"package_id", p),
attr::mk_name_value_item_str(@"name", s.to_managed())],
*meta_items)
match split_version(p) {
None => {
let p_path = Path::new(p);
let s = match p_path.filestem_str() {
None|Some("") =>
e.diag.span_bug(i.span,
"Bad package path in `extern mod` item"),
Some(s) => s,
};
~[attr::mk_name_value_item_str(@"package_id", p),
attr::mk_name_value_item_str(@"name", s.to_managed())]
}
Some((name, version)) => {
let p_path = Path::new(name);
let s = match p_path.filestem_str() {
None|Some("") =>
e.diag.span_bug(i.span,
"Bad package path in `extern mod` item"),
Some(s) => s,
};
~[attr::mk_name_value_item_str(@"package_id", name.to_managed()),
attr::mk_name_value_item_str(@"name", s.to_managed()),
attr::mk_name_value_item_str(@"vers", version.to_managed())]
}
}
}
};
Expand Down
24 changes: 24 additions & 0 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,27 @@ pub fn rust_path() -> ~[Path] {
pub fn libdir() -> ~str {
(env!("CFG_LIBDIR")).to_owned()
}


/// If s is of the form foo#bar, where bar is a valid version
/// number, return the prefix before the # and the version.
/// Otherwise, return None.
pub fn split_version<'a>(s: &'a str) -> Option<(&'a str, &'a str)> {
// Check for extra '#' characters separately
if s.split_iter('#').len() > 2 {
return None;
}
split_version_general(s, '#')
}

pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, &'a str)> {
match s.rfind(sep) {
Some(i) => {
let path = s.slice(0, i);
Some((path, s.slice(i + 1, s.len())))
}
None => {
None
}
}
}
12 changes: 7 additions & 5 deletions src/librustpkg/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,19 @@ impl CtxMethods for BuildContext {
let pkgid = pkg_src.id.clone();

debug!("build: workspace = {} (in Rust path? {:?} is git dir? {:?} \
pkgid = {} pkgsrc start_dir = {}", workspace.display(),
pkgid = {} pkgsrc start_dir = {}", workspace.display(),
in_rust_path(&workspace), is_git_dir(&workspace.join(&pkgid.path)),
pkgid.to_str(), pkg_src.start_dir.display());
pkgid.to_str(),
pkg_src.start_dir.display());
let pkg_dir = workspace.join(&pkgid.path);
debug!("build: what to build = {:?}", what_to_build);

// If workspace isn't in the RUST_PATH, and it's a git repo,
// then clone it into the first entry in RUST_PATH, and repeat
if !in_rust_path(&workspace) && is_git_dir(&workspace.join(&pkgid.path)) {
if !in_rust_path(&workspace) && is_git_dir(&pkg_dir) {
let mut out_dir = default_workspace().join("src");
out_dir.push(&pkgid.path);
let git_result = source_control::safe_git_clone(&workspace.join(&pkgid.path),
let git_result = source_control::safe_git_clone(&pkg_dir,
&pkgid.version,
&out_dir);
match git_result {
Expand Down Expand Up @@ -516,7 +518,7 @@ impl CtxMethods for BuildContext {
JustOne(ref p) => {
// We expect that p is relative to the package source's start directory,
// so check that assumption
debug!("JustOne: p = {}", p.display());
debug!("JustOne: p = {} and {}", p.display(), pkg_src.start_dir.display());
assert!(pkg_src.start_dir.join(p).exists());
if is_lib(p) {
PkgSrc::push_crate(&mut pkg_src.libs, 0, p);
Expand Down
Loading