std/rustc/rustpkg/syntax: Support the extern mod = ... form

This commit allows you to write:

 extern mod x = "a/b/c";

which means rustc will search in the RUST_PATH for a package with
ID a/b/c, and bind it to the name `x` if it's found.

Incidentally, move get_relative_to from back::rpath into std::path
This commit is contained in:
Tim Chevalier 2013-07-31 13:47:32 -07:00
parent e751c90513
commit 96fd606ddd
29 changed files with 819 additions and 602 deletions

View file

@ -23,33 +23,30 @@ fn default_ctxt(p: @Path) -> Ctx {
Ctx { sysroot_opt: Some(p), json: false, dep_cache: @mut HashMap::new() }
}
pub fn build_lib(sysroot: @Path, root: Path, dest: Path, name: ~str, version: Version,
pub fn build_lib(sysroot: @Path, root: Path, name: ~str, version: Version,
lib: Path) {
let pkg_src = PkgSrc {
root: root,
dst_dir: dest.clone(),
id: PkgId{ version: version, ..PkgId::new(name, &dest.pop())},
id: PkgId{ version: version, ..PkgId::new(name)},
libs: ~[mk_crate(lib)],
mains: ~[],
tests: ~[],
benchs: ~[]
};
pkg_src.build(&default_ctxt(sysroot), pkg_src.dst_dir, ~[]);
pkg_src.build(&default_ctxt(sysroot), ~[]);
}
pub fn build_exe(sysroot: @Path, root: Path, dest: Path, name: ~str, version: Version,
main: Path) {
pub fn build_exe(sysroot: @Path, root: Path, name: ~str, version: Version, main: Path) {
let pkg_src = PkgSrc {
root: root,
dst_dir: dest.clone(),
id: PkgId{ version: version, ..PkgId::new(name, &dest.pop())},
id: PkgId{ version: version, ..PkgId::new(name)},
libs: ~[],
mains: ~[mk_crate(main)],
tests: ~[],
benchs: ~[]
};
pkg_src.build(&default_ctxt(sysroot), pkg_src.dst_dir, ~[]);
pkg_src.build(&default_ctxt(sysroot), ~[]);
}
@ -62,12 +59,9 @@ pub fn install_lib(sysroot: @Path,
debug!("sysroot = %s", sysroot.to_str());
debug!("workspace = %s", workspace.to_str());
// make a PkgSrc
let pkg_id = PkgId{ version: version, ..PkgId::new(name, &workspace)};
let build_dir = workspace.push("build");
let dst_dir = build_dir.push_rel(&*pkg_id.local_path);
let pkg_id = PkgId{ version: version, ..PkgId::new(name)};
let pkg_src = PkgSrc {
root: workspace.clone(),
dst_dir: dst_dir.clone(),
id: pkg_id.clone(),
libs: ~[mk_crate(lib_path)],
mains: ~[],
@ -75,13 +69,13 @@ pub fn install_lib(sysroot: @Path,
benchs: ~[]
};
let cx = default_ctxt(sysroot);
pkg_src.build(&cx, dst_dir, ~[]);
pkg_src.build(&cx, ~[]);
cx.install_no_build(&workspace, &pkg_id);
}
pub fn install_exe(sysroot: @Path, workspace: Path, name: ~str, version: Version) {
default_ctxt(sysroot).install(&workspace, &PkgId{ version: version,
..PkgId::new(name, &workspace)});
..PkgId::new(name)});
}

View file

@ -12,6 +12,7 @@
use std::hashmap::HashMap;
use std::os;
pub struct Ctx {
// Sysroot -- if this is None, uses rustc filesearch's
@ -23,3 +24,26 @@ pub struct Ctx {
// though I'm not sure why the value is a bool
dep_cache: @mut HashMap<~str, bool>,
}
impl Ctx {
/// Debugging
pub fn sysroot_opt_str(&self) -> ~str {
match self.sysroot_opt {
None => ~"[none]",
Some(p) => p.to_str()
}
}
}
/// We assume that if ../../rustc exists, then we're running
/// rustpkg from a Rust target directory. This is part of a
/// kludgy hack used to adjust the sysroot.
pub fn in_target(sysroot_opt: Option<@Path>) -> bool {
match sysroot_opt {
None => false,
Some(p) => {
debug!("Checking whether %s is in target", p.to_str());
os::path_is_dir(&p.pop().pop().push("rustc"))
}
}
}

View file

@ -10,6 +10,7 @@
// Listing installed packages
use rustc::metadata::filesearch::rust_path;
use path_util::*;
use std::os;
@ -20,21 +21,46 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
for exec in binfiles.iter() {
let exec_path = Path(*exec).filestem();
do exec_path.iter().advance |s| {
f(&PkgId::new(*s, p))
f(&PkgId::new(*s))
};
}
let libfiles = os::list_dir(&p.push("lib"));
for lib in libfiles.iter() {
debug!("Full name: %s", *lib);
let lib_path = Path(*lib).filestem();
do lib_path.iter().advance |s| {
f(&PkgId::new(*s, p))
};
}
let lib = Path(*lib);
debug!("Full name: %s", lib.to_str());
match has_library(&lib) {
Some(basename) => {
debug!("parent = %s, child = %s",
p.push("lib").to_str(), lib.to_str());
let rel_p = p.push("lib/").get_relative_to(&lib);
debug!("Rel: %s", rel_p.to_str());
let rel_path = rel_p.push(basename).to_str();
debug!("Rel name: %s", rel_path);
f(&PkgId::new(rel_path));
}
None => ()
}
};
}
true
}
pub fn has_library(p: &Path) -> Option<~str> {
let files = os::list_dir(p);
for q in files.iter() {
let as_path = Path(*q);
if as_path.filetype() == Some(os::consts::DLL_SUFFIX.to_owned()) {
let stuff : ~str = as_path.filestem().expect("has_library: weird path");
let mut stuff2 = stuff.split_str_iter(&"-");
let stuff3: ~[&str] = stuff2.collect();
// argh
let chars_to_drop = os::consts::DLL_PREFIX.len();
return Some(stuff3[0].slice(chars_to_drop, stuff3[0].len()).to_owned());
}
}
None
}
pub fn package_is_installed(p: &PkgId) -> bool {
let mut is_installed = false;
do list_installed_packages() |installed| {
@ -44,4 +70,4 @@ pub fn package_is_installed(p: &PkgId) -> bool {
false
};
is_installed
}
}

View file

@ -45,7 +45,7 @@ impl PkgId {
// The PkgId constructor takes a Path argument so as
// to be able to infer the version if the path refers
// to a local git repository
pub fn new(s: &str, work_dir: &Path) -> PkgId {
pub fn new(s: &str) -> PkgId {
use conditions::bad_pkg_id::cond;
let mut given_version = None;
@ -76,7 +76,7 @@ impl PkgId {
let version = match given_version {
Some(v) => v,
None => match try_getting_local_version(&work_dir.push_rel(&*local_path)) {
None => match try_getting_local_version(&*local_path) {
Some(v) => v,
None => match try_getting_version(&remote_path) {
Some(v) => v,
@ -103,6 +103,11 @@ impl PkgId {
pub fn short_name_with_version(&self) -> ~str {
fmt!("%s%s", self.short_name, self.version.to_str())
}
/// True if the ID has multiple components
pub fn is_complex(&self) -> bool {
self.short_name != self.local_path.to_str()
}
}
impl ToStr for PkgId {

View file

@ -23,7 +23,6 @@ use util::compile_crate;
// This contains a list of files found in the source workspace.
pub struct PkgSrc {
root: Path, // root of where the package source code lives
dst_dir: Path, // directory where we will put the compiled output
id: PkgId,
libs: ~[Crate],
mains: ~[Crate],
@ -37,11 +36,9 @@ condition! {
impl PkgSrc {
pub fn new(src_dir: &Path, dst_dir: &Path,
id: &PkgId) -> PkgSrc {
pub fn new(src_dir: &Path, id: &PkgId) -> PkgSrc {
PkgSrc {
root: (*src_dir).clone(),
dst_dir: (*dst_dir).clone(),
id: (*id).clone(),
libs: ~[],
mains: ~[],
@ -202,7 +199,6 @@ impl PkgSrc {
fn build_crates(&self,
ctx: &Ctx,
dst_dir: &Path,
src_dir: &Path,
crates: &[Crate],
cfgs: &[~str],
@ -210,12 +206,13 @@ impl PkgSrc {
for crate in crates.iter() {
let path = &src_dir.push_rel(&crate.file).normalize();
note(fmt!("build_crates: compiling %s", path.to_str()));
note(fmt!("build_crates: destination dir is %s", dst_dir.to_str()));
note(fmt!("build_crates: using as workspace %s", self.root.to_str()));
let result = compile_crate(ctx,
&self.id,
path,
dst_dir,
// compile_crate wants the workspace
&self.root,
crate.flags,
crate.cfgs + cfgs,
false,
@ -229,15 +226,15 @@ impl PkgSrc {
}
}
pub fn build(&self, ctx: &Ctx, dst_dir: Path, cfgs: ~[~str]) {
pub fn build(&self, ctx: &Ctx, cfgs: ~[~str]) {
let dir = self.check_dir();
debug!("Building libs in %s", dir.to_str());
self.build_crates(ctx, &dst_dir, &dir, self.libs, cfgs, Lib);
self.build_crates(ctx, &dir, self.libs, cfgs, Lib);
debug!("Building mains");
self.build_crates(ctx, &dst_dir, &dir, self.mains, cfgs, Main);
self.build_crates(ctx, &dir, self.mains, cfgs, Main);
debug!("Building tests");
self.build_crates(ctx, &dst_dir, &dir, self.tests, cfgs, Test);
self.build_crates(ctx, &dir, self.tests, cfgs, Test);
debug!("Building benches");
self.build_crates(ctx, &dst_dir, &dir, self.benchs, cfgs, Bench);
self.build_crates(ctx, &dir, self.benchs, cfgs, Bench);
}
}

View file

@ -14,61 +14,14 @@ pub use package_path::{RemotePath, LocalPath, normalize};
pub use package_id::PkgId;
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
pub use version::{Version, NoVersion, split_version_general};
pub use rustc::metadata::filesearch::rust_path;
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
use std::os::mkdir_recursive;
use std::os;
use std::iterator::IteratorUtil;
use messages::*;
use package_id::*;
fn push_if_exists(vec: &mut ~[Path], p: &Path) {
let maybe_dir = p.push(".rust");
if os::path_exists(&maybe_dir) {
vec.push(maybe_dir);
}
}
#[cfg(windows)]
static PATH_ENTRY_SEPARATOR: &'static str = ";";
#[cfg(not(windows))]
static PATH_ENTRY_SEPARATOR: &'static str = ":";
/// Returns RUST_PATH as a string, without default paths added
pub fn get_rust_path() -> Option<~str> {
os::getenv("RUST_PATH")
}
/// Returns the value of RUST_PATH, as a list
/// of Paths. Includes default entries for, if they exist:
/// $HOME/.rust
/// DIR/.rust for any DIR that's the current working directory
/// or an ancestor of it
pub fn rust_path() -> ~[Path] {
let mut env_rust_path: ~[Path] = match get_rust_path() {
Some(env_path) => {
let env_path_components: ~[&str] =
env_path.split_str_iter(PATH_ENTRY_SEPARATOR).collect();
env_path_components.map(|&s| Path(s))
}
None => ~[]
};
debug!("RUST_PATH entries from environment: %?", env_rust_path);
let cwd = os::getcwd();
// now add in default entries
env_rust_path.push(cwd.clone());
do cwd.each_parent() |p| { push_if_exists(&mut env_rust_path, p) };
let h = os::homedir();
// Avoid adding duplicates
// could still add dups if someone puts one of these in the RUST_PATH
// manually, though...
for hdir in h.iter() {
if !(cwd.is_ancestor_of(hdir) || hdir.is_ancestor_of(&cwd)) {
push_if_exists(&mut env_rust_path, hdir);
}
}
env_rust_path
}
pub fn default_workspace() -> Path {
let p = rust_path();
if p.is_empty() {
@ -99,39 +52,39 @@ pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, U_RWX) }
/// pkgid's short name
pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
let src_dir = workspace.push("src");
let dirs = os::list_dir(&src_dir);
for p in dirs.iter() {
let p = Path((*p).clone());
let mut found = false;
do os::walk_dir(&src_dir) |p| {
debug!("=> p = %s", p.to_str());
if !os::path_is_dir(&src_dir.push_rel(&p)) {
loop;
}
debug!("p = %s, remote_path = %s", p.to_str(), pkgid.remote_path.to_str());
if os::path_is_dir(p) {
debug!("p = %s, path = %s [%s]", p.to_str(), pkgid.path.to_str(),
src_dir.push_rel(&pkgid.path).to_str());
if p == *pkgid.remote_path {
return true;
}
else {
let pf = p.filename();
for pf in pf.iter() {
let f_ = (*pf).clone();
let g = f_.to_str();
match split_version_general(g, '-') {
Some((ref might_match, ref vers)) => {
debug!("might_match = %s, vers = %s", *might_match,
if *p == src_dir.push_rel(&pkgid.path) {
found = true;
}
else {
let pf = p.filename();
for pf in pf.iter() {
let f_ = (*pf).clone();
let g = f_.to_str();
match split_version_general(g, '-') {
Some((ref might_match, ref vers)) => {
debug!("might_match = %s, vers = %s", *might_match,
vers.to_str());
if *might_match == pkgid.short_name
&& (*vers == pkgid.version || pkgid.version == NoVersion)
{
return true;
if *might_match == pkgid.short_name
&& (*vers == pkgid.version || pkgid.version == NoVersion)
{
found = true;
}
}
}
None => ()
None => ()
}
}
}
}
}
false
true
};
found
}
/// Returns a list of possible directories

View file

@ -33,12 +33,13 @@ use std::hashmap::HashMap;
use rustc::driver::{driver, session};
use rustc::metadata::filesearch;
use rustc::metadata::filesearch::rust_path;
use extra::{getopts};
use syntax::{ast, diagnostic};
use util::*;
use messages::*;
use path_util::{build_pkg_id_in_workspace, first_pkgid_src_in_workspace};
use path_util::{U_RWX, rust_path, in_rust_path};
use path_util::{U_RWX, in_rust_path};
use path_util::{built_executable_in_workspace, built_library_in_workspace, default_workspace};
use path_util::{target_executable_in_workspace, target_library_in_workspace};
use source_control::is_git_dir;
@ -138,35 +139,28 @@ impl<'self> PkgScript<'self> {
let crate = util::ready_crate(sess, self.crate);
debug!("Building output filenames with script name %s",
driver::source_name(&self.input));
match filesearch::get_rustpkg_sysroot() {
Ok(r) => {
let root = r.pop().pop().pop().pop(); // :-\
debug!("Root is %s, calling compile_rest", root.to_str());
let exe = self.build_dir.push(~"pkg" + util::exe_suffix());
util::compile_crate_from_input(&self.input,
&self.build_dir,
sess,
crate);
debug!("Running program: %s %s %s %s", exe.to_str(),
sysroot.to_str(), root.to_str(), "install");
// FIXME #7401 should support commands besides `install`
let status = run::process_status(exe.to_str(), [sysroot.to_str(), ~"install"]);
if status != 0 {
return (~[], status);
}
else {
debug!("Running program (configs): %s %s %s",
exe.to_str(), root.to_str(), "configs");
let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]);
// Run the configs() function to get the configs
let cfgs = str::from_bytes_slice(output.output).word_iter()
.transform(|w| w.to_owned()).collect();
(cfgs, output.status)
}
}
Err(e) => {
fail!("Running package script, couldn't find rustpkg sysroot (%s)", e)
}
let root = filesearch::get_or_default_sysroot().pop().pop(); // :-\
debug!("Root is %s, calling compile_rest", root.to_str());
let exe = self.build_dir.push(~"pkg" + util::exe_suffix());
util::compile_crate_from_input(&self.input,
&self.build_dir,
sess,
crate);
debug!("Running program: %s %s %s %s", exe.to_str(),
sysroot.to_str(), root.to_str(), "install");
// FIXME #7401 should support commands besides `install`
let status = run::process_status(exe.to_str(), [sysroot.to_str(), ~"install"]);
if status != 0 {
return (~[], status);
}
else {
debug!("Running program (configs): %s %s %s",
exe.to_str(), root.to_str(), "configs");
let output = run::process_output(exe.to_str(), [root.to_str(), ~"configs"]);
// Run the configs() function to get the configs
let cfgs = str::from_bytes_slice(output.output).word_iter()
.transform(|w| w.to_owned()).collect();
(cfgs, output.status)
}
}
@ -205,7 +199,7 @@ impl CtxMethods for Ctx {
else {
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(args[0].clone(), &os::getcwd());
let pkgid = PkgId::new(args[0].clone());
do each_pkg_parent_workspace(&pkgid) |workspace| {
debug!("found pkg %s in workspace %s, trying to build",
pkgid.to_str(), workspace.to_str());
@ -228,7 +222,7 @@ impl CtxMethods for Ctx {
else {
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(args[0].clone(), &os::getcwd());
let pkgid = PkgId::new(args[0].clone());
let cwd = os::getcwd();
self.clean(&cwd, &pkgid); // tjc: should use workspace, not cwd
}
@ -254,13 +248,12 @@ impl CtxMethods for Ctx {
else {
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(args[0], &os::getcwd());
let pkgid = PkgId::new(args[0]);
let workspaces = pkg_parent_workspaces(&pkgid);
if workspaces.is_empty() {
let rp = rust_path();
assert!(!rp.is_empty());
let src = PkgSrc::new(&rp[0], &build_pkg_id_in_workspace(&pkgid, &rp[0]),
&pkgid);
let src = PkgSrc::new(&rp[0], &pkgid);
src.fetch_git();
self.install(&rp[0], &pkgid);
}
@ -294,7 +287,7 @@ impl CtxMethods for Ctx {
return usage::uninstall();
}
let pkgid = PkgId::new(args[0], &os::getcwd()); // ??
let pkgid = PkgId::new(args[0]);
if !installed_packages::package_is_installed(&pkgid) {
warn(fmt!("Package %s doesn't seem to be installed! Doing nothing.", args[0]));
return;
@ -332,8 +325,6 @@ impl CtxMethods for Ctx {
in_rust_path(workspace), is_git_dir(&workspace.push_rel(&*pkgid.local_path)),
pkgid.to_str());
let src_dir = first_pkgid_src_in_workspace(pkgid, workspace);
let build_dir = build_pkg_id_in_workspace(pkgid, workspace);
debug!("Destination dir = %s", build_dir.to_str());
// 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
@ -351,7 +342,7 @@ impl CtxMethods for Ctx {
}
// Create the package source
let mut src = PkgSrc::new(workspace, &build_dir, pkgid);
let mut src = PkgSrc::new(workspace, pkgid);
debug!("Package src = %?", src);
// Is there custom build logic? If so, use it
@ -385,7 +376,7 @@ impl CtxMethods for Ctx {
// Find crates inside the workspace
src.find_crates();
// Build it!
src.build(self, build_dir, cfgs);
src.build(self, cfgs);
}
}
@ -444,6 +435,7 @@ impl CtxMethods for Ctx {
for lib in maybe_library.iter() {
let target_lib = target_lib.clone().expect(fmt!("I built %s but apparently \
didn't install it!", lib.to_str()));
let target_lib = target_lib.pop().push(lib.filename().expect("weird target lib"));
debug!("Copying: %s -> %s", lib.to_str(), target_lib.to_str());
if !(os::mkdir_recursive(&target_lib.dir_path(), U_RWX) &&
os::copy_file(lib, &target_lib)) {
@ -518,9 +510,7 @@ pub fn main() {
};
}
let sroot = match filesearch::get_rustpkg_sysroot() {
Ok(r) => Some(@r.pop().pop()), Err(_) => None
};
let sroot = Some(@filesearch::get_or_default_sysroot());
debug!("Using sysroot: %?", sroot);
Ctx {
sysroot_opt: sroot, // Currently, only tests override this

View file

@ -10,7 +10,7 @@
// Utils for working with version control repositories. Just git right now.
use std::{os, run, str};
use std::{io, os, run, str};
use std::run::{ProcessOutput, ProcessOptions, Process};
use version::*;
@ -19,14 +19,37 @@ pub fn git_clone(source: &Path, target: &Path, v: &Version) {
assert!(os::path_is_dir(source));
assert!(is_git_dir(source));
if !os::path_exists(target) {
debug!("Running: git clone %s %s", source.to_str(),
target.to_str());
assert!(git_clone_general(source.to_str(), target, v));
debug!("Running: git clone %s %s", source.to_str(), target.to_str());
let outp = run::process_output("git", [~"clone", source.to_str(), target.to_str()]);
if outp.status != 0 {
io::println(str::from_bytes_owned(outp.output.clone()));
io::println(str::from_bytes_owned(outp.error));
fail!("Couldn't `git clone` %s", source.to_str());
}
else {
match v {
&ExactRevision(ref s) => {
debug!("`Running: git --work-tree=%s --git-dir=%s checkout %s",
*s, target.to_str(), target.push(".git").to_str());
let outp = run::process_output("git",
[fmt!("--work-tree=%s", target.to_str()),
fmt!("--git-dir=%s", target.push(".git").to_str()),
~"checkout", fmt!("%s", *s)]);
if outp.status != 0 {
io::println(str::from_bytes_owned(outp.output.clone()));
io::println(str::from_bytes_owned(outp.error));
fail!("Couldn't `git checkout %s` in %s",
*s, target.to_str());
}
}
_ => ()
}
}
}
else {
// Pull changes
// Note that this ignores tags, which is probably wrong. There are no tests for
// it, though.
// Check that no version was specified. There's no reason to not handle the
// case where a version was requested, but I haven't implemented it.
assert!(*v == NoVersion);
debug!("Running: git --work-tree=%s --git-dir=%s pull --no-edit %s",
target.to_str(), target.push(".git").to_str(), source.to_str());
let outp = run::process_output("git", [fmt!("--work-tree=%s", target.to_str()),

View file

@ -24,7 +24,9 @@ use path_util::{target_executable_in_workspace, target_library_in_workspace,
make_dir_rwx, U_RWX, library_in_workspace,
built_bench_in_workspace, built_test_in_workspace,
built_library_in_workspace, built_executable_in_workspace,
installed_library_in_workspace, rust_path};
installed_library_in_workspace};
use rustc::metadata::filesearch::rust_path;
use rustc::driver::driver::host_triple;
use target::*;
/// Returns the last-modified date as an Option
@ -116,6 +118,22 @@ fn mk_temp_workspace(short_name: &LocalPath, version: &Version) -> Path {
package_dir
}
fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &str) {
let cwd = (*cwd).clone();
let mut prog = run::Process::new("git", args, run::ProcessOptions {
env: env.map(|v| v.slice(0, v.len())),
dir: Some(&cwd),
in_fd: None,
out_fd: None,
err_fd: None
});
let rslt = prog.finish_with_output();
if rslt.status != 0 {
fail!("%s [git returned %?, output = %s, error = %s]", err_msg,
rslt.status, str::from_bytes(rslt.output), str::from_bytes(rslt.error));
}
}
/// Should create an empty git repo in p, relative to the tmp dir, and return the new
/// absolute path
fn init_git_repo(p: &Path) -> Path {
@ -125,37 +143,14 @@ fn init_git_repo(p: &Path) -> Path {
let work_dir_for_opts = work_dir.clone();
assert!(os::mkdir_recursive(&work_dir, U_RWX));
debug!("Running: git init in %s", work_dir.to_str());
let opts = run::ProcessOptions {
env: None,
dir: Some(&work_dir_for_opts),
in_fd: None,
out_fd: None,
err_fd: None
};
let mut prog = run::Process::new("git", [~"init"], opts);
let mut output = prog.finish_with_output();
if output.status == 0 {
// Add stuff to the dir so that git tag succeeds
writeFile(&work_dir.push("README"), "");
prog = run::Process::new("git", [~"add", ~"README"], opts);
output = prog.finish_with_output();
if output.status == 0 {
prog = run::Process::new("git", [~"commit", ~"-m", ~"whatever"], opts);
output = prog.finish_with_output();
if output.status == 0 {
tmp
}
else {
fail!("Couldn't commit in %s", work_dir.to_str());
}
}
else {
fail!("Couldn't add in %s", work_dir.to_str());
}
}
else {
fail!("Couldn't initialize git repository in %s", work_dir.to_str())
}
let ws = work_dir.to_str();
run_git([~"init"], None, &work_dir_for_opts,
fmt!("Couldn't initialize git repository in %s", ws));
// Add stuff to the dir so that git tag succeeds
writeFile(&work_dir.push("README"), "");
run_git([~"add", ~"README"], None, &work_dir_for_opts, fmt!("Couldn't add in %s", ws));
git_commit(&work_dir_for_opts, ~"whatever");
tmp
}
fn add_all_and_commit(repo: &Path) {
@ -164,51 +159,20 @@ fn add_all_and_commit(repo: &Path) {
}
fn git_commit(repo: &Path, msg: ~str) {
let mut prog = run::Process::new("git", [~"commit", ~"-m", msg],
run::ProcessOptions { env: None,
dir: Some(repo),
in_fd: None,
out_fd: None,
err_fd: None
});
let output = prog.finish_with_output();
if output.status != 0 {
fail!("Couldn't commit in %s: output was %s", repo.to_str(),
str::from_bytes(output.output + output.error))
}
run_git([~"commit", ~"--author=tester <test@mozilla.com>", ~"-m", msg],
None, repo, fmt!("Couldn't commit in %s", repo.to_str()));
}
fn git_add_all(repo: &Path) {
let mut prog = run::Process::new("git", [~"add", ~"-A"],
run::ProcessOptions { env: None,
dir: Some(repo),
in_fd: None,
out_fd: None,
err_fd: None
});
let output = prog.finish_with_output();
if output.status != 0 {
fail!("Couldn't add all files in %s: output was %s",
repo.to_str(), str::from_bytes(output.output + output.error))
}
run_git([~"add", ~"-A"], None, repo, fmt!("Couldn't add all files in %s", repo.to_str()));
}
fn add_git_tag(repo: &Path, tag: ~str) {
assert!(repo.is_absolute());
git_add_all(repo);
git_commit(repo, ~"whatever");
let mut prog = run::Process::new("git", [~"tag", tag.clone()],
run::ProcessOptions { env: None,
dir: Some(repo),
in_fd: None,
out_fd: None,
err_fd: None
});
let output = prog.finish_with_output();
if output.status != 0 {
fail!("Couldn't add git tag %s in %s", tag, repo.to_str())
}
run_git([~"tag", tag.clone()], None, repo,
fmt!("Couldn't add git tag %s in %s", tag, repo.to_str()));
}
fn is_rwx(p: &Path) -> bool {
@ -231,6 +195,25 @@ fn test_sysroot() -> Path {
self_path.pop()
}
// Returns the path to rustpkg
fn rustpkg_exec() -> Path {
// Ugh
let first_try = test_sysroot().push("lib").push("rustc")
.push(host_triple()).push("bin").push("rustpkg");
if is_executable(&first_try) {
first_try
}
else {
let second_try = test_sysroot().push("bin").push("rustpkg");
if is_executable(&second_try) {
second_try
}
else {
fail!("in rustpkg test, can't find an installed rustpkg");
}
}
}
fn command_line_test(args: &[~str], cwd: &Path) -> ProcessOutput {
command_line_test_with_env(args, cwd, None)
}
@ -240,8 +223,9 @@ fn command_line_test(args: &[~str], cwd: &Path) -> ProcessOutput {
/// Returns the process's output.
fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~str)]>)
-> ProcessOutput {
let cmd = test_sysroot().push("bin").push("rustpkg").to_str();
debug!("About to run command: %? %? in %s", cmd, args, cwd.to_str());
let cmd = rustpkg_exec().to_str();
debug!("cd %s; %s %s",
cwd.to_str(), cmd, args.connect(" "));
assert!(os::path_is_dir(&*cwd));
let cwd = (*cwd).clone();
let mut prog = run::Process::new(cmd, args, run::ProcessOptions {
@ -263,8 +247,9 @@ So tests that use this need to check the existence of a file
to make sure the command succeeded
*/
if output.status != 0 {
fail!("Command %s %? failed with exit code %?",
cmd, args, output.status);
fail!("Command %s %? failed with exit code %?; its output was {{{ %s }}}",
cmd, args, output.status,
str::from_bytes(output.output) + str::from_bytes(output.error));
}
output
}
@ -329,24 +314,24 @@ fn create_local_package_with_custom_build_hook(pkgid: &PkgId,
fn assert_lib_exists(repo: &Path, short_name: &str, v: Version) {
debug!("assert_lib_exists: repo = %s, short_name = %s", repo.to_str(), short_name);
let lib = target_library_in_workspace(&(PkgId {
version: v, ..PkgId::new(short_name, repo)}
), repo);
debug!("assert_lib_exists: checking whether %s exists", lib.to_str());
assert!(os::path_exists(&lib));
assert!(is_rwx(&lib));
let lib = installed_library_in_workspace(short_name, repo);
debug!("assert_lib_exists: checking whether %? exists", lib);
assert!(lib.is_some());
let libname = lib.get_ref();
assert!(os::path_exists(libname));
assert!(is_rwx(libname));
}
fn assert_executable_exists(repo: &Path, short_name: &str) {
debug!("assert_executable_exists: repo = %s, short_name = %s", repo.to_str(), short_name);
let exec = target_executable_in_workspace(&PkgId::new(short_name, repo), repo);
let exec = target_executable_in_workspace(&PkgId::new(short_name), repo);
assert!(os::path_exists(&exec));
assert!(is_rwx(&exec));
}
fn assert_built_executable_exists(repo: &Path, short_name: &str) {
debug!("assert_built_executable_exists: repo = %s, short_name = %s", repo.to_str(), short_name);
let exec = built_executable_in_workspace(&PkgId::new(short_name, repo),
let exec = built_executable_in_workspace(&PkgId::new(short_name),
repo).expect("assert_built_executable_exists failed");
assert!(os::path_exists(&exec));
assert!(is_rwx(&exec));
@ -563,18 +548,18 @@ fn test_package_ids_must_be_relative_path_like() {
*/
let whatever = PkgId::new("foo", &os::getcwd());
let whatever = PkgId::new("foo");
assert_eq!(~"foo-0.1", whatever.to_str());
assert!("github.com/catamorphism/test_pkg-0.1" ==
PkgId::new("github.com/catamorphism/test-pkg", &os::getcwd()).to_str());
PkgId::new("github.com/catamorphism/test-pkg").to_str());
do cond.trap(|(p, e)| {
assert!("" == p.to_str());
assert!("0-length pkgid" == e);
whatever.clone()
}).inside {
let x = PkgId::new("", &os::getcwd());
let x = PkgId::new("");
assert_eq!(~"foo-0.1", x.to_str());
}
@ -583,8 +568,7 @@ fn test_package_ids_must_be_relative_path_like() {
assert!("absolute pkgid" == e);
whatever.clone()
}).inside {
let z = PkgId::new(os::make_absolute(&Path("foo/bar/quux")).to_str(),
&os::getcwd());
let z = PkgId::new(os::make_absolute(&Path("foo/bar/quux")).to_str());
assert_eq!(~"foo-0.1", z.to_str());
}
@ -607,7 +591,7 @@ fn test_package_version() {
"#[bench] pub fn f() { (); }");
add_git_tag(&repo_subdir, ~"0.4");
let temp_pkg_id = PkgId::new("mockgithub.com/catamorphism/test_pkg_version", &repo);
let temp_pkg_id = PkgId::new("mockgithub.com/catamorphism/test_pkg_version");
match temp_pkg_id.version {
ExactRevision(~"0.4") => (),
_ => fail!(fmt!("test_package_version: package version was %?, expected Some(0.4)",
@ -656,7 +640,7 @@ fn test_package_request_version() {
}
None => false
});
let temp_pkg_id = PkgId::new("mockgithub.com/catamorphism/test_pkg_version#0.3", &repo);
let temp_pkg_id = PkgId::new("mockgithub.com/catamorphism/test_pkg_version#0.3");
assert!(target_executable_in_workspace(&temp_pkg_id, &repo.push(".rust"))
== repo.push(".rust").push("bin").push("test_pkg_version"));
@ -696,12 +680,12 @@ fn rustpkg_library_target() {
add_git_tag(&package_dir, ~"1.0");
command_line_test([~"install", ~"foo"], &foo_repo);
assert_lib_exists(&foo_repo, "foo", ExactRevision(~"1.0"));
assert_lib_exists(&foo_repo.push(".rust"), "foo", ExactRevision(~"1.0"));
}
#[test]
fn rustpkg_local_pkg() {
let dir = create_local_package(&PkgId::new("foo", &os::getcwd()));
let dir = create_local_package(&PkgId::new("foo"));
command_line_test([~"install", ~"foo"], &dir);
assert_executable_exists(&dir, "foo");
}
@ -711,7 +695,7 @@ fn rustpkg_local_pkg() {
#[test]
#[ignore]
fn package_script_with_default_build() {
let dir = create_local_package(&PkgId::new("fancy-lib", &os::getcwd()));
let dir = create_local_package(&PkgId::new("fancy-lib"));
debug!("dir = %s", dir.to_str());
let source = test_sysroot().pop().pop().pop().push("src").push("librustpkg").
push("testsuite").push("pass").push("src").push("fancy-lib").push("pkg.rs");
@ -763,7 +747,7 @@ fn rustpkg_clean_no_arg() {
command_line_test([~"build"], &package_dir);
assert_built_executable_exists(&tmp, "foo");
command_line_test([~"clean"], &package_dir);
assert!(!built_executable_in_workspace(&PkgId::new("foo", &package_dir),
assert!(!built_executable_in_workspace(&PkgId::new("foo"),
&tmp).map_default(false, |m| { os::path_exists(m) }));
}
@ -777,8 +761,7 @@ fn rust_path_test() {
let cwd = os::getcwd();
debug!("cwd = %s", cwd.to_str());
debug!("Running command: cd %s; RUST_LOG=rustpkg RUST_PATH=%s rustpkg install foo",
cwd.to_str(), dir_for_path.to_str());
// use command_line_test_with_env
let mut prog = run::Process::new("rustpkg",
[~"install", ~"foo"],
run::ProcessOptions { env: Some(&[(~"RUST_LOG",
@ -830,39 +813,38 @@ fn rust_path_parse() {
#[test]
fn test_list() {
let dir = mkdtemp(&os::tmpdir(), "test_list").expect("test_list failed");
let foo = PkgId::new("foo", &dir);
let foo = PkgId::new("foo");
create_local_package_in(&foo, &dir);
let bar = PkgId::new("bar", &dir);
let bar = PkgId::new("bar");
create_local_package_in(&bar, &dir);
let quux = PkgId::new("quux", &dir);
let quux = PkgId::new("quux");
create_local_package_in(&quux, &dir);
// NOTE Not really great output, though...
// NOTE do any tests need to be unignored?
// list doesn't output very much right now...
command_line_test([~"install", ~"foo"], &dir);
let env_arg = ~[(~"RUST_PATH", dir.to_str())];
debug!("RUST_PATH = %s", dir.to_str());
let list_output = command_line_test_output_with_env([~"list"], env_arg.clone());
assert!(list_output.iter().any(|x| x.starts_with("libfoo_")));
assert!(list_output.iter().any(|x| x.starts_with("foo")));
command_line_test([~"install", ~"bar"], &dir);
let list_output = command_line_test_output_with_env([~"list"], env_arg.clone());
assert!(list_output.iter().any(|x| x.starts_with("libfoo_")));
assert!(list_output.iter().any(|x| x.starts_with("libbar_")));
assert!(list_output.iter().any(|x| x.starts_with("foo")));
assert!(list_output.iter().any(|x| x.starts_with("bar")));
command_line_test([~"install", ~"quux"], &dir);
let list_output = command_line_test_output_with_env([~"list"], env_arg);
assert!(list_output.iter().any(|x| x.starts_with("libfoo_")));
assert!(list_output.iter().any(|x| x.starts_with("libbar_")));
assert!(list_output.iter().any(|x| x.starts_with("libquux_")));
assert!(list_output.iter().any(|x| x.starts_with("foo")));
assert!(list_output.iter().any(|x| x.starts_with("bar")));
assert!(list_output.iter().any(|x| x.starts_with("quux")));
}
#[test]
fn install_remove() {
let dir = mkdtemp(&os::tmpdir(), "install_remove").expect("install_remove");
let foo = PkgId::new("foo", &dir);
let bar = PkgId::new("bar", &dir);
let quux = PkgId::new("quux", &dir);
let foo = PkgId::new("foo");
let bar = PkgId::new("bar");
let quux = PkgId::new("quux");
create_local_package_in(&foo, &dir);
create_local_package_in(&bar, &dir);
create_local_package_in(&quux, &dir);
@ -887,7 +869,7 @@ fn install_check_duplicates() {
// ("Is already installed -- doing nothing")
// check invariant that there are no dups in the pkg database
let dir = mkdtemp(&os::tmpdir(), "install_remove").expect("install_remove");
let foo = PkgId::new("foo", &dir);
let foo = PkgId::new("foo");
create_local_package_in(&foo, &dir);
command_line_test([~"install", ~"foo"], &dir);
@ -908,7 +890,7 @@ fn install_check_duplicates() {
#[test]
#[ignore(reason = "Workcache not yet implemented -- see #7075")]
fn no_rebuilding() {
let p_id = PkgId::new("foo", &os::getcwd());
let p_id = PkgId::new("foo");
let workspace = create_local_package(&p_id);
command_line_test([~"build", ~"foo"], &workspace);
let date = datestamp(&built_library_in_workspace(&p_id,
@ -922,8 +904,8 @@ fn no_rebuilding() {
#[test]
#[ignore(reason = "Workcache not yet implemented -- see #7075")]
fn no_rebuilding_dep() {
let p_id = PkgId::new("foo", &os::getcwd());
let dep_id = PkgId::new("bar", &os::getcwd());
let p_id = PkgId::new("foo");
let dep_id = PkgId::new("bar");
let workspace = create_local_package_with_dep(&p_id, &dep_id);
command_line_test([~"build", ~"foo"], &workspace);
let bar_date = datestamp(&lib_output_file_name(&workspace,
@ -935,8 +917,8 @@ fn no_rebuilding_dep() {
#[test]
fn do_rebuild_dep_dates_change() {
let p_id = PkgId::new("foo", &os::getcwd());
let dep_id = PkgId::new("bar", &os::getcwd());
let p_id = PkgId::new("foo");
let dep_id = PkgId::new("bar");
let workspace = create_local_package_with_dep(&p_id, &dep_id);
command_line_test([~"build", ~"foo"], &workspace);
let bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
@ -948,8 +930,8 @@ fn do_rebuild_dep_dates_change() {
#[test]
fn do_rebuild_dep_only_contents_change() {
let p_id = PkgId::new("foo", &os::getcwd());
let dep_id = PkgId::new("bar", &os::getcwd());
let p_id = PkgId::new("foo");
let dep_id = PkgId::new("bar");
let workspace = create_local_package_with_dep(&p_id, &dep_id);
command_line_test([~"build", ~"foo"], &workspace);
let bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
@ -962,8 +944,8 @@ fn do_rebuild_dep_only_contents_change() {
#[test]
fn test_versions() {
let workspace = create_local_package(&PkgId::new("foo#0.1", &os::getcwd()));
create_local_package(&PkgId::new("foo#0.2", &os::getcwd()));
let workspace = create_local_package(&PkgId::new("foo#0.1"));
create_local_package(&PkgId::new("foo#0.2"));
command_line_test([~"install", ~"foo#0.1"], &workspace);
let output = command_line_test_output([~"list"]);
// make sure output includes versions
@ -973,7 +955,7 @@ fn test_versions() {
#[test]
#[ignore(reason = "do not yet implemented")]
fn test_build_hooks() {
let workspace = create_local_package_with_custom_build_hook(&PkgId::new("foo", &os::getcwd()),
let workspace = create_local_package_with_custom_build_hook(&PkgId::new("foo"),
"frob");
command_line_test([~"do", ~"foo", ~"frob"], &workspace);
}
@ -983,7 +965,7 @@ fn test_build_hooks() {
#[ignore(reason = "info not yet implemented")]
fn test_info() {
let expected_info = ~"package foo"; // fill in
let workspace = create_local_package(&PkgId::new("foo", &os::getcwd()));
let workspace = create_local_package(&PkgId::new("foo"));
let output = command_line_test([~"info", ~"foo"], &workspace);
assert_eq!(str::from_bytes(output.output), expected_info);
}
@ -992,7 +974,7 @@ fn test_info() {
#[ignore(reason = "test not yet implemented")]
fn test_rustpkg_test() {
let expected_results = ~"1 out of 1 tests passed"; // fill in
let workspace = create_local_package_with_test(&PkgId::new("foo", &os::getcwd()));
let workspace = create_local_package_with_test(&PkgId::new("foo"));
let output = command_line_test([~"test", ~"foo"], &workspace);
assert_eq!(str::from_bytes(output.output), expected_results);
}
@ -1000,7 +982,7 @@ fn test_rustpkg_test() {
#[test]
#[ignore(reason = "test not yet implemented")]
fn test_uninstall() {
let workspace = create_local_package(&PkgId::new("foo", &os::getcwd()));
let workspace = create_local_package(&PkgId::new("foo"));
let _output = command_line_test([~"info", ~"foo"], &workspace);
command_line_test([~"uninstall", ~"foo"], &workspace);
let output = command_line_test([~"list"], &workspace);
@ -1031,3 +1013,62 @@ fn test_non_numeric_tag() {
assert!(os::path_exists(&file1));
assert!(!os::path_exists(&file2));
}
#[test]
fn test_extern_mod() {
let dir = mkdtemp(&os::tmpdir(), "test_extern_mod").expect("test_extern_mod");
let main_file = dir.push("main.rs");
let lib_depend_dir = mkdtemp(&os::tmpdir(), "foo").expect("test_extern_mod");
let aux_dir = lib_depend_dir.push_many(["src", "mockgithub.com", "catamorphism", "test_pkg"]);
assert!(os::mkdir_recursive(&aux_dir, U_RWX));
let aux_pkg_file = aux_dir.push("lib.rs");
writeFile(&aux_pkg_file, "pub mod bar { pub fn assert_true() { assert!(true); } }\n");
assert!(os::path_exists(&aux_pkg_file));
writeFile(&main_file,
"extern mod test = \"mockgithub.com/catamorphism/test_pkg\";\nuse test::bar;\
fn main() { bar::assert_true(); }\n");
command_line_test([~"install", ~"mockgithub.com/catamorphism/test_pkg"], &lib_depend_dir);
let exec_file = dir.push("out");
// Be sure to extend the existing environment
let env = Some([(~"RUST_PATH", lib_depend_dir.to_str())] + os::env());
let rustpkg_exec = rustpkg_exec();
let rustc = rustpkg_exec.with_filename("rustc");
debug!("RUST_PATH=%s %s %s \n --sysroot %s -o %s",
lib_depend_dir.to_str(),
rustc.to_str(),
main_file.to_str(),
test_sysroot().to_str(),
exec_file.to_str());
let mut prog = run::Process::new(rustc.to_str(), [main_file.to_str(),
~"--sysroot", test_sysroot().to_str(),
~"-o", exec_file.to_str()],
run::ProcessOptions {
env: env.map(|v| v.slice(0, v.len())),
dir: Some(&dir),
in_fd: None,
out_fd: None,
err_fd: None
});
let outp = prog.finish_with_output();
if outp.status != 0 {
fail!("output was %s, error was %s",
str::from_bytes(outp.output),
str::from_bytes(outp.error));
}
assert!(os::path_exists(&exec_file) && is_executable(&exec_file));
}
/// Returns true if p exists and is executable
fn is_executable(p: &Path) -> bool {
use std::libc::consts::os::posix88::{S_IXUSR};
match p.get_mode() {
None => false,
Some(mode) => mode & S_IXUSR as uint == S_IXUSR as uint
}
}

View file

@ -8,9 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::{os, result};
use std::os;
use rustc::driver::{driver, session};
use rustc::metadata::filesearch;
use extra::getopts::groups::getopts;
use syntax::ast_util::*;
use syntax::codemap::{dummy_sp, spanned};
@ -19,10 +18,10 @@ use syntax::{ast, attr, codemap, diagnostic, fold};
use syntax::attr::AttrMetaMethods;
use rustc::back::link::output_type_exe;
use rustc::driver::session::{lib_crate, bin_crate};
use context::Ctx;
use context::{Ctx, in_target};
use package_id::PkgId;
use search::find_library_in_search_path;
use path_util::target_library_in_workspace;
use path_util::{target_library_in_workspace, U_RWX};
pub use target::{OutputType, Main, Lib, Bench, Test};
// It would be nice to have the list of commands in just one place -- for example,
@ -47,13 +46,6 @@ impl ToStr for Pkg {
}
}
pub fn root() -> Path {
match filesearch::get_rustpkg_root() {
result::Ok(path) => path,
result::Err(err) => fail!(err)
}
}
pub fn is_cmd(cmd: &str) -> bool {
COMMANDS.iter().any(|&c| c == cmd)
}
@ -162,25 +154,25 @@ pub fn ready_crate(sess: session::Session,
pub fn compile_input(ctxt: &Ctx,
pkg_id: &PkgId,
in_file: &Path,
out_dir: &Path,
workspace: &Path,
flags: &[~str],
cfgs: &[~str],
opt: bool,
what: OutputType) -> bool {
let workspace = out_dir.pop().pop();
assert!(in_file.components.len() > 1);
let input = driver::file_input((*in_file).clone());
debug!("compile_input: %s / %?", in_file.to_str(), what);
// tjc: by default, use the package ID name as the link name
// not sure if we should support anything else
let out_dir = workspace.push("build").push_rel(&*pkg_id.local_path);
let binary = os::args()[0].to_managed();
debug!("flags: %s", flags.connect(" "));
debug!("cfgs: %s", cfgs.connect(" "));
debug!("compile_input's sysroot = %?", ctxt.sysroot_opt);
debug!("out_dir = %s", out_dir.to_str());
let crate_type = match what {
Lib => lib_crate,
@ -196,12 +188,22 @@ pub fn compile_input(ctxt: &Ctx,
+ flags
+ cfgs.flat_map(|c| { ~[~"--cfg", (*c).clone()] }),
driver::optgroups()).unwrap();
// Hack so that rustpkg can run either out of a rustc target dir,
// or the host dir
let sysroot_to_use = if !in_target(ctxt.sysroot_opt) {
ctxt.sysroot_opt
}
else {
ctxt.sysroot_opt.map(|p| { @p.pop().pop().pop() })
};
debug!("compile_input's sysroot = %?", ctxt.sysroot_opt_str());
debug!("sysroot_to_use = %?", sysroot_to_use);
let options = @session::options {
crate_type: crate_type,
optimize: if opt { session::Aggressive } else { session::No },
test: what == Test || what == Bench,
maybe_sysroot: ctxt.sysroot_opt,
addl_lib_search_paths: @mut (~[(*out_dir).clone()]),
maybe_sysroot: sysroot_to_use,
addl_lib_search_paths: @mut (~[out_dir.clone()]),
// output_type should be conditional
output_type: output_type_exe, // Use this to get a library? That's weird
.. (*driver::build_session_options(binary, &matches, diagnostic::emit)).clone()
@ -211,7 +213,12 @@ pub fn compile_input(ctxt: &Ctx,
// Make sure all the library directories actually exist, since the linker will complain
// otherwise
for p in addl_lib_search_paths.iter() {
assert!(os::path_is_dir(p));
if os::path_exists(p) {
assert!(os::path_is_dir(p));
}
else {
assert!(os::mkdir_recursive(p, U_RWX));
}
}
let sess = driver::build_session(options, diagnostic::emit);
@ -224,35 +231,44 @@ pub fn compile_input(ctxt: &Ctx,
// Not really right. Should search other workspaces too, and the installed
// database (which doesn't exist yet)
find_and_install_dependencies(ctxt, sess, &workspace, crate,
find_and_install_dependencies(ctxt, sess, workspace, crate,
|p| {
debug!("a dependency: %s", p.to_str());
// Pass the directory containing a dependency
// as an additional lib search path
addl_lib_search_paths.push(p);
if !addl_lib_search_paths.contains(&p) {
// Might be inefficient, but this set probably
// won't get too large -- tjc
addl_lib_search_paths.push(p);
}
});
// Inject the link attributes so we get the right package name and version
if attr::find_linkage_metas(crate.attrs).is_empty() {
let short_name_to_use = match what {
Test => fmt!("%stest", pkg_id.short_name),
Bench => fmt!("%sbench", pkg_id.short_name),
_ => pkg_id.short_name.clone()
let name_to_use = match what {
Test => fmt!("%stest", pkg_id.local_path.to_str()).to_managed(),
Bench => fmt!("%sbench", pkg_id.local_path.to_str()).to_managed(),
_ => pkg_id.short_name.to_managed()
};
debug!("Injecting link name: %s", short_name_to_use);
debug!("Injecting link name: %s", name_to_use);
let link_options =
~[attr::mk_name_value_item_str(@"name", short_name_to_use.to_managed()),
attr::mk_name_value_item_str(@"vers", pkg_id.version.to_str().to_managed())];
~[attr::mk_name_value_item_str(@"name", name_to_use),
attr::mk_name_value_item_str(@"vers", pkg_id.version.to_str().to_managed())] +
if pkg_id.is_complex() {
~[attr::mk_name_value_item_str(@"package_id",
pkg_id.local_path.to_str().to_managed())]
} else { ~[] };
debug!("link options: %?", link_options);
crate = @ast::Crate {
attrs: ~[attr::mk_attr(attr::mk_list_item(@"link", link_options))],
.. (*crate).clone()
};
}
}
debug!("calling compile_crate_from_input, out_dir = %s,
debug!("calling compile_crate_from_input, workspace = %s,
building_library = %?", out_dir.to_str(), sess.building_library);
compile_crate_from_input(&input, out_dir, sess, crate);
compile_crate_from_input(&input, &out_dir, sess, crate);
true
}
@ -262,17 +278,22 @@ pub fn compile_input(ctxt: &Ctx,
// call compile_upto and return the crate
// also, too many arguments
pub fn compile_crate_from_input(input: &driver::input,
build_dir: &Path,
// should be of the form <workspace>/build/<pkg id's path>
out_dir: &Path,
sess: session::Session,
crate: @ast::Crate) {
debug!("Calling build_output_filenames with %s, building library? %?",
build_dir.to_str(), sess.building_library);
out_dir.to_str(), sess.building_library);
// bad copy
let outputs = driver::build_output_filenames(input, &Some((*build_dir).clone()), &None,
debug!("out_dir = %s", out_dir.to_str());
let outputs = driver::build_output_filenames(input, &Some(out_dir.clone()), &None,
crate.attrs, sess);
debug!("Outputs are %? and output type = %?", outputs, sess.opts.output_type);
debug!("Outputs are out_filename: %s and obj_filename: %s and output type = %?",
outputs.out_filename.to_str(),
outputs.obj_filename.to_str(),
sess.opts.output_type);
debug!("additional libraries:");
for lib in sess.opts.addl_lib_search_paths.iter() {
debug!("an additional library: %s", lib.to_str());
@ -298,15 +319,15 @@ pub fn exe_suffix() -> ~str { ~"" }
// Called by build_crates
// FIXME (#4432): Use workcache to only compile when needed
pub fn compile_crate(ctxt: &Ctx, pkg_id: &PkgId,
crate: &Path, dir: &Path,
crate: &Path, workspace: &Path,
flags: &[~str], cfgs: &[~str], opt: bool,
what: OutputType) -> bool {
debug!("compile_crate: crate=%s, dir=%s", crate.to_str(), dir.to_str());
debug!("compile_crate: crate=%s, workspace=%s", crate.to_str(), workspace.to_str());
debug!("compile_crate: short_name = %s, flags =...", pkg_id.to_str());
for fl in flags.iter() {
debug!("+++ %s", *fl);
}
compile_input(ctxt, pkg_id, crate, dir, flags, cfgs, opt, what)
compile_input(ctxt, pkg_id, crate, workspace, flags, cfgs, opt, what)
}
@ -327,19 +348,20 @@ pub fn find_and_install_dependencies(ctxt: &Ctx,
debug!("A view item!");
match vi.node {
// ignore metadata, I guess
ast::view_item_extern_mod(lib_ident, _, _) => {
ast::view_item_extern_mod(lib_ident, path_opt, _, _) => {
match my_ctxt.sysroot_opt {
Some(ref x) => debug!("sysroot: %s", x.to_str()),
Some(ref x) => debug!("*** sysroot: %s", x.to_str()),
None => debug!("No sysroot given")
};
let lib_name = sess.str_of(lib_ident);
let lib_name = match path_opt { // ???
Some(p) => p, None => sess.str_of(lib_ident) };
match find_library_in_search_path(my_ctxt.sysroot_opt, lib_name) {
Some(installed_path) => {
debug!("It exists: %s", installed_path.to_str());
}
None => {
// Try to install it
let pkg_id = PkgId::new(lib_name, &os::getcwd());
let pkg_id = PkgId::new(lib_name);
my_ctxt.install(&my_workspace, &pkg_id);
// Also, add an additional search path
debug!("let installed_path...")

View file

@ -17,6 +17,7 @@ use extra::semver;
use std::{char, os, result, run, str};
use package_path::RemotePath;
use extra::tempfile::mkdtemp;
use path_util::rust_path;
#[deriving(Clone)]
pub enum Version {
@ -92,19 +93,22 @@ pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> {
}
}
/// If `local_path` is a git repo, and the most recent tag in that repo denotes a version,
/// return it; otherwise, `None`
/// If `local_path` is a git repo in the RUST_PATH, and the most recent tag
/// in that repo denotes a version, return it; otherwise, `None`
pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
debug!("in try_getting_local_version");
let outp = run::process_output("git",
let rustpath = rust_path();
for rp in rustpath.iter() {
let local_path = rp.push_rel(local_path);
debug!("in try_getting_local_version");
let outp = run::process_output("git",
[fmt!("--git-dir=%s", local_path.push(".git").to_str()),
~"tag", ~"-l"]);
debug!("git --git-dir=%s tag -l ~~~> %?", local_path.push(".git").to_str(), outp.status);
debug!("git --git-dir=%s tag -l ~~~> %?", local_path.push(".git").to_str(), outp.status);
if outp.status != 0 {
return None;
}
if outp.status != 0 {
loop;
}
let mut output = None;
let output_text = str::from_bytes(outp.output);
@ -112,8 +116,13 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
if !l.is_whitespace() {
output = Some(l);
}
match output.chain(try_parsing_version) {
Some(v) => return Some(v),
None => ()
}
}
output.chain(try_parsing_version)
}
None
}
/// If `remote_path` refers to a git repo that can be downloaded,

View file

@ -12,9 +12,11 @@
use std::os;
use std::path::Path;
use path_util::{rust_path, workspace_contains_package_id};
use path_util::workspace_contains_package_id;
use package_id::PkgId;
use rustc::metadata::filesearch::rust_path;
pub fn each_pkg_parent_workspace(pkgid: &PkgId, action: &fn(&Path) -> bool) -> bool {
// Using the RUST_PATH, find workspaces that contain
// this package ID
@ -58,5 +60,5 @@ pub fn cwd_to_workspace() -> (Path, PkgId) {
let ws = cwd.pop().pop();
let cwd_ = cwd.clone();
let pkgid = cwd_.components.last().to_str();
(ws, PkgId::new(pkgid, &cwd))
(ws, PkgId::new(pkgid))
}