pub no_rust_path: (~str) -> Path;
}
-condition! {
- pub not_a_workspace: (~str) -> Path;
-}
-
condition! {
pub failed_to_create_temp_dir: (~str) -> Path;
}
use messages::*;
use source_control::{safe_git_clone, git_clone_url, DirToUse, CheckedOutSources};
use source_control::make_read_only;
-use path_util::{find_dir_using_rust_path_hack, make_dir_rwx_recursive};
-use path_util::{target_build_dir, versionize};
+use path_util::{find_dir_using_rust_path_hack, make_dir_rwx_recursive, default_workspace};
+use path_util::{target_build_dir, versionize, dir_has_crate_file};
use util::{compile_crate, DepMap};
use workcache_support;
use workcache_support::crate_tag;
match ok_d {
Some(d) => d,
None => {
- if use_rust_path_hack {
+ // See if the sources are in $CWD
+ let cwd = os::getcwd();
+ if dir_has_crate_file(&cwd) {
+ return PkgSrc {
+ // In this case, source_workspace isn't really a workspace.
+ // This data structure needs yet more refactoring.
+ source_workspace: cwd.clone(),
+ destination_workspace: default_workspace(),
+ build_in_destination: true,
+ start_dir: cwd,
+ id: id,
+ libs: ~[],
+ mains: ~[],
+ benchs: ~[],
+ tests: ~[]
+ }
+ } else if use_rust_path_hack {
match find_dir_using_rust_path_hack(&id) {
Some(d) => d,
None => {
}
+pub fn dir_has_crate_file(dir: &Path) -> bool {
+ dir_has_file(dir, "lib.rs") || dir_has_file(dir, "main.rs")
+ || dir_has_file(dir, "test.rs") || dir_has_file(dir, "bench.rs")
+}
+
fn dir_has_file(dir: &Path, file: &str) -> bool {
assert!(dir.is_absolute());
os::path_exists(&dir.join(file))
// has a name that's a single component
if dir.ends_with_path(&p.path) || dir.ends_with_path(&versionize(&p.path, &p.version)) {
debug2!("In find_dir_using_rust_path_hack: checking dir {}", dir.display());
- if dir_has_file(dir, "lib.rs") || dir_has_file(dir, "main.rs")
- || dir_has_file(dir, "test.rs") || dir_has_file(dir, "bench.rs") {
+ if dir_has_crate_file(dir) {
debug2!("Did find id {} in dir {}", p.to_str(), dir.display());
return Some(dir.clone());
}
use path_util::{build_pkg_id_in_workspace, built_test_in_workspace};
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 path_util::{target_executable_in_workspace, target_library_in_workspace, dir_has_crate_file};
use source_control::{CheckedOutSources, is_git_dir, make_read_only};
use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces, cwd_to_workspace};
use workspace::determine_destination;
use package_id::PkgId;
use package_source::PkgSrc;
use target::{WhatToBuild, Everything, is_lib, is_main, is_test, is_bench, Tests};
-// use workcache_support::{discover_outputs, digest_only_date};
use workcache_support::digest_only_date;
use exit_codes::{COPY_FAILED_CODE, BAD_FLAG_CODE};
impl CtxMethods for BuildContext {
fn build_args(&self, args: ~[~str], what: &WhatToBuild) -> Option<(PkgId, Path)> {
+ let cwd = os::getcwd();
+
if args.len() < 1 {
match cwd_to_workspace() {
- None if self.context.use_rust_path_hack => {
- let cwd = os::getcwd();
+ None if dir_has_crate_file(&cwd) => {
// FIXME (#9639): This needs to handle non-utf8 paths
let pkgid = PkgId::new(cwd.filename_str().unwrap());
let mut pkg_src = PkgSrc::new(cwd, default_workspace(), true, pkgid);
}
}
fn run(&self, cmd: &str, args: ~[~str]) {
+ let cwd = os::getcwd();
match cmd {
"build" => {
self.build_args(args, &Everything);
// The package id is presumed to be the first command-line
// argument
let pkgid = PkgId::new(args[0].clone());
- let cwd = os::getcwd();
self.clean(&cwd, &pkgid); // tjc: should use workspace, not cwd
}
}
"install" => {
if args.len() < 1 {
match cwd_to_workspace() {
- None if self.context.use_rust_path_hack => {
- let cwd = os::getcwd();
+ None if dir_has_crate_file(&cwd) => {
// FIXME (#9639): This needs to handle non-utf8 paths
+
let inferred_pkgid =
PkgId::new(cwd.filename_str().unwrap());
self.install(PkgSrc::new(cwd, default_workspace(),
assert!(os::remove_dir_recursive(&dir));
}
+// n.b. I ignored the next two tests for now because something funny happens on linux
+// and I don't want to debug the issue right now (calling into the rustpkg lib directly
+// is a little sketchy anyway)
#[test]
+#[ignore]
fn test_install_valid() {
use path_util::installed_library_in_workspace;
}
#[test]
+#[ignore]
fn test_install_invalid() {
let sysroot = test_sysroot();
let pkgid = fake_pkg();
assert!(result == Err(()));
}
-// Tests above should (maybe) be converted to shell out to rustpkg, too
+#[test]
+fn test_install_valid_external() {
+ let temp_pkg_id = PkgId::new("foo");
+ let (tempdir, _) = mk_temp_workspace(&temp_pkg_id.path,
+ &temp_pkg_id.version);
+ let temp_workspace = tempdir.path();
+ command_line_test([~"install", ~"foo"], temp_workspace);
+
+ // Check that all files exist
+ let exec = target_executable_in_workspace(&temp_pkg_id, temp_workspace);
+ debug2!("exec = {}", exec.display());
+ assert!(os::path_exists(&exec));
+ assert!(is_rwx(&exec));
+
+ let lib = installed_library_in_workspace(&temp_pkg_id.path, temp_workspace);
+ debug2!("lib = {:?}", lib);
+ assert!(lib.as_ref().map_default(false, |l| os::path_exists(l)));
+ assert!(lib.as_ref().map_default(false, |l| is_rwx(l)));
+
+ // And that the test and bench executables aren't installed
+ assert!(!os::path_exists(&target_test_in_workspace(&temp_pkg_id, temp_workspace)));
+ let bench = target_bench_in_workspace(&temp_pkg_id, temp_workspace);
+ debug2!("bench = {}", bench.display());
+ assert!(!os::path_exists(&bench));
+
+}
+
+#[test]
+#[ignore(reason = "9994")]
+fn test_install_invalid_external() {
+ let cwd = os::getcwd();
+ command_line_test_expect_fail([~"install", ~"foo"],
+ &cwd,
+ None,
+ // FIXME #3408: Should be NONEXISTENT_PACKAGE_CODE
+ COPY_FAILED_CODE);
+}
+
#[test]
fn test_install_git() {
let temp_pkg_id = git_repo_pkg();
assert!(!built_executable_exists(workspace, "foo"));
}
+// Notice that this is the only test case where the --rust-path-hack
+// flag is actually needed
#[test]
fn test_rust_path_can_contain_package_dirs_with_flag() {
/*
}
#[test]
-#[ignore(reason = "Issue 9441")]
fn test_rebuild_when_needed() {
let foo_id = PkgId::new("foo");
let foo_workspace = create_local_package(&foo_id);
}
}
+#[test]
+fn find_sources_in_cwd() {
+ let temp_dir = TempDir::new("sources").expect("find_sources_in_cwd failed");
+ let temp_dir = temp_dir.path();
+ let source_dir = temp_dir.join("foo");
+ os::mkdir_recursive(&source_dir, U_RWX);
+ writeFile(&source_dir.join("main.rs"),
+ "fn main() { let _x = (); }");
+ command_line_test([~"install", ~"foo"], &source_dir);
+ assert_executable_exists(&source_dir.join(".rust"), "foo");
+}
+
/// Returns true if p exists and is executable
fn is_executable(p: &Path) -> bool {
use std::libc::consts::os::posix88::{S_IXUSR};