Skip to content

Commit

Permalink
auto merge of #7148 : catamorphism/rust/rustpkg_tests, r=graydon
Browse files Browse the repository at this point in the history
r? @graydon Automate more tests described in the commands.txt file,
and add infrastructure for running them. Right now, tests shell
out to call rustpkg. This is not ideal.

Goes part of the way towards addressing #5683
  • Loading branch information
bors committed Jun 15, 2013
2 parents 82f2e4d + e3c4104 commit eac0200
Show file tree
Hide file tree
Showing 11 changed files with 559 additions and 120 deletions.
1 change: 1 addition & 0 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,6 @@ pub fn collect_language_items(crate: @crate,
let mut collector = LanguageItemCollector(crate, session);
collector.collect();
let LanguageItemCollector { items, _ } = collector;
session.abort_if_errors();
items
}
40 changes: 40 additions & 0 deletions src/librustpkg/messages.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use extra::term;
use core::io;
use core::result::*;

pub fn note(msg: &str) {
pretty_message(msg, "note: ", term::color_green, io::stdout())
}

pub fn warn(msg: &str) {
pretty_message(msg, "warning: ", term::color_yellow, io::stdout())
}

pub fn error(msg: &str) {
pretty_message(msg, "error: ", term::color_red, io::stdout())
}

fn pretty_message<'a>(msg: &'a str, prefix: &'a str, color: u8, out: @io::Writer) {
let term = term::Terminal::new(out);
match term {
Ok(ref t) => {
t.fg(color);
out.write_str(prefix);
t.reset();
},
_ => {
out.write_str(prefix);
}
}
out.write_line(msg);
}
7 changes: 2 additions & 5 deletions src/librustpkg/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl PkgId {
}
};

debug!("local_path = %s, remote_path = %s", local_path.to_str(), remote_path.to_str());
PkgId {
local_path: local_path,
remote_path: remote_path,
Expand All @@ -90,11 +91,7 @@ impl PkgId {

impl ToStr for PkgId {
fn to_str(&self) -> ~str {
let maybe_dash = match self.version {
NoVersion => "",
_ => "-"
};
// should probably use the filestem and not the whole path
fmt!("%s%s%s", self.local_path.to_str(), maybe_dash, self.version.to_str())
fmt!("%s-%s", self.local_path.to_str(), self.version.to_str())
}
}
5 changes: 3 additions & 2 deletions src/librustpkg/package_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use core::option::*;
use core::{os, run, str, vec};
use context::*;
use crate::Crate;
use messages::*;
use path_util::pkgid_src_in_workspace;
use util::{compile_crate, note};
use util::compile_crate;
use version::{ExactRevision, SemanticVersion, NoVersion};

// An enumeration of the unpacked source of a package workspace.
Expand Down Expand Up @@ -95,7 +96,7 @@ impl PkgSrc {
};


note(fmt!("git clone %s %s %?", url, local.to_str(), branch_args));
note(fmt!("Fetching package: git clone %s %s %?", url, local.to_str(), branch_args));

if run::process_output("git",
~[~"clone", copy url, local.to_str()] + branch_args).status != 0 {
Expand Down
89 changes: 67 additions & 22 deletions src/librustpkg/path_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
// rustpkg utilities having to do with paths and directories

use core::prelude::*;
pub use package_path::{RemotePath, LocalPath};
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};
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
use core::os::mkdir_recursive;
use core::os;
use core::iterator::IteratorUtil;
use messages::*;
use package_id::*;

/// Returns the value of RUST_PATH, as a list
/// of Paths. In general this should be read from the
Expand All @@ -38,8 +42,39 @@ pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, u_rwx) }
/// True if there's a directory in <workspace> with
/// pkgid's short name
pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
let pkgpath = workspace.push("src").push(pkgid.remote_path.to_str());
os::path_is_dir(&pkgpath)
let src_dir = workspace.push("src");
for os::list_dir(&src_dir).each |&p| {
let p = Path(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 p == *pkgid.remote_path {
return true;
}
else {
let pf = p.filename();
for pf.iter().advance |&pf| {
let f_ = copy pf;
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;
}
}
None => ()
}
}
}
}
false
}

/// Returns a list of possible directories
Expand Down Expand Up @@ -114,31 +149,34 @@ fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Opt
/// Figure out what the library name for <pkgid> in <workspace>'s build
/// directory is, and if the file exists, return it.
pub fn built_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
// passing in local_path here sounds fishy
library_in_workspace(pkgid.local_path.to_str(), pkgid.short_name, Build,
workspace, "build")
library_in_workspace(&pkgid.local_path, pkgid.short_name,
Build, workspace, "build")
}

/// Does the actual searching stuff
pub fn installed_library_in_workspace(short_name: &str, workspace: &Path) -> Option<Path> {
library_in_workspace(short_name, short_name, Install, workspace, "lib")
library_in_workspace(&normalize(RemotePath(Path(short_name))),
short_name, Install, workspace, "lib")
}


/// This doesn't take a PkgId, so we can use it for `extern mod` inference, where we
/// don't know the entire package ID.
/// `full_name` is used to figure out the directory to search.
/// `workspace` is used to figure out the directory to search.
/// `short_name` is taken as the link name of the library.
fn library_in_workspace(full_name: &str, short_name: &str, where: Target,
pub fn library_in_workspace(path: &LocalPath, short_name: &str, where: Target,
workspace: &Path, prefix: &str) -> Option<Path> {
debug!("library_in_workspace: checking whether a library named %s exists",
short_name);

// We don't know what the hash is, so we have to search through the directory
// contents

debug!("short_name = %s where = %? workspace = %s \
prefix = %s", short_name, where, workspace.to_str(), prefix);

let dir_to_search = match where {
Build => workspace.push(prefix).push(full_name),
Build => workspace.push(prefix).push_rel(&**path),
Install => workspace.push(prefix)
};
debug!("Listing directory %s", dir_to_search.to_str());
Expand Down Expand Up @@ -193,7 +231,11 @@ fn library_in_workspace(full_name: &str, short_name: &str, where: Target,
// Return the filename that matches, which we now know exists
// (if result_filename != None)
match result_filename {
None => None,
None => {
warn(fmt!("library_in_workspace didn't find a library in %s for %s",
dir_to_search.to_str(), short_name));
None
}
Some(result_filename) => {
let absolute_path = dir_to_search.push_rel(&result_filename);
debug!("result_filename = %s", absolute_path.to_str());
Expand All @@ -210,17 +252,17 @@ pub fn target_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
}


/// Returns the installed path for <built_library> in <workspace>
/// Returns the executable that would be installed for <pkgid>
/// in <workspace>
/// As a side effect, creates the lib-dir if it doesn't exist
pub fn target_library_in_workspace(workspace: &Path,
built_library: &Path) -> Path {
pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
use conditions::bad_path::cond;
let result = workspace.push("lib");
if !os::path_exists(&result) && !mkdir_recursive(&result, u_rwx) {
cond.raise((copy result, ~"I couldn't create the library directory"));
if !os::path_is_dir(workspace) {
cond.raise((copy *workspace,
fmt!("Workspace supplied to target_library_in_workspace \
is not a directory! %s", workspace.to_str())));
}
result.push(built_library.filename().expect(fmt!("I don't know how to treat %s as a library",
built_library.to_str())))
target_file_in_workspace(pkgid, workspace, Lib, Install)
}

/// Returns the test executable that would be installed for <pkgid>
Expand Down Expand Up @@ -249,7 +291,9 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
};
let result = workspace.push(subdir);
if !os::path_exists(&result) && !mkdir_recursive(&result, u_rwx) {
cond.raise((copy result, fmt!("I couldn't create the %s dir", subdir)));
cond.raise((copy result, fmt!("target_file_in_workspace couldn't \
create the %s dir (pkgid=%s, workspace=%s, what=%?, where=%?",
subdir, pkgid.to_str(), workspace.to_str(), what, where)));
}
mk_output_path(what, where, pkgid, &result)
}
Expand All @@ -275,7 +319,8 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
/// given whether we're building a library and whether we're building tests
pub fn mk_output_path(what: OutputType, where: Target,
pkg_id: &PkgId, workspace: &Path) -> Path {
let short_name_with_version = pkg_id.short_name_with_version();
let short_name_with_version = fmt!("%s-%s", pkg_id.short_name,
pkg_id.version.to_str());
// Not local_path.dir_path()! For package foo/bar/blat/, we want
// the executable blat-0.5 to live under blat/
let dir = match where {
Expand All @@ -291,7 +336,7 @@ pub fn mk_output_path(what: OutputType, where: Target,
// this code is duplicated from elsewhere; fix this
Lib => dir.push(os::dll_filename(short_name_with_version)),
// executable names *aren't* versioned
_ => dir.push(fmt!("%s%s%s", copy pkg_id.short_name,
_ => dir.push(fmt!("%s%s%s", pkg_id.short_name,
match what {
Test => "test",
Bench => "bench",
Expand Down
41 changes: 30 additions & 11 deletions src/librustpkg/rustpkg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ use rustc::metadata::filesearch;
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;
use path_util::{u_rwx, rust_path};
use path_util::{built_executable_in_workspace, built_library_in_workspace};
use path_util::{target_executable_in_workspace, target_library_in_workspace};
use workspace::pkg_parent_workspaces;
use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces};
use context::Ctx;
use package_id::PkgId;
use package_source::PkgSrc;

mod conditions;
mod context;
mod crate;
mod messages;
mod package_id;
mod package_path;
mod package_source;
Expand Down Expand Up @@ -189,7 +191,7 @@ impl Ctx {
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(copy args[0]);
for pkg_parent_workspaces(&pkgid) |workspace| {
for each_pkg_parent_workspace(&pkgid) |workspace| {
self.build(workspace, &pkgid);
}
}
Expand Down Expand Up @@ -221,8 +223,19 @@ impl Ctx {
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(args[0]);
for pkg_parent_workspaces(&pkgid) |workspace| {
self.install(workspace, &pkgid);
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);
src.fetch_git();
self.install(&rp[0], &pkgid);
}
else {
for each_pkg_parent_workspace(&pkgid) |workspace| {
self.install(workspace, &pkgid);
}
}
}
"prefer" => {
Expand Down Expand Up @@ -259,6 +272,8 @@ impl Ctx {
}

fn build(&self, workspace: &Path, pkgid: &PkgId) {
debug!("build: workspace = %s pkgid = %s", workspace.to_str(),
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());
Expand Down Expand Up @@ -310,14 +325,14 @@ impl Ctx {
// Do something reasonable for now

let dir = build_pkg_id_in_workspace(id, workspace);
util::note(fmt!("Cleaning package %s (removing directory %s)",
note(fmt!("Cleaning package %s (removing directory %s)",
id.to_str(), dir.to_str()));
if os::path_exists(&dir) {
os::remove_dir_recursive(&dir);
util::note(fmt!("Removed directory %s", dir.to_str()));
note(fmt!("Removed directory %s", dir.to_str()));
}

util::note(fmt!("Cleaned package %s", id.to_str()));
note(fmt!("Cleaned package %s", id.to_str()));
}

fn info(&self) {
Expand All @@ -338,7 +353,7 @@ impl Ctx {
let maybe_executable = built_executable_in_workspace(id, workspace);
let maybe_library = built_library_in_workspace(id, workspace);
let target_exec = target_executable_in_workspace(id, workspace);
let target_lib = maybe_library.map(|p| target_library_in_workspace(workspace, p));
let target_lib = maybe_library.map(|_p| target_library_in_workspace(id, workspace));

debug!("target_exec = %s target_lib = %? \
maybe_executable = %? maybe_library = %?",
Expand Down Expand Up @@ -392,7 +407,7 @@ pub fn main() {
let matches = &match getopts::getopts(args, opts) {
result::Ok(m) => m,
result::Err(f) => {
util::error(fmt!("%s", getopts::fail_str(f)));
error(fmt!("%s", getopts::fail_str(f)));

return;
}
Expand Down Expand Up @@ -428,8 +443,12 @@ pub fn main() {
};
}

let sroot = match filesearch::get_rustpkg_sysroot() {
Ok(r) => Some(@r.pop().pop()), Err(_) => None
};
debug!("Using sysroot: %?", sroot);
Ctx {
sysroot_opt: None, // Currently, only tests override this
sysroot_opt: sroot, // Currently, only tests override this
json: json,
dep_cache: @mut HashMap::new()
}.run(cmd, args);
Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ pub fn find_library_in_search_path(sroot_opt: Option<@Path>, short_name: &str) -
}
None => None
}
}
}

0 comments on commit eac0200

Please sign in to comment.