diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-08-23 11:51:45 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-08-26 15:23:06 -0700 |
| commit | 3e4e1a274a7b3bf760c7a09d1a004728c8590362 (patch) | |
| tree | 1c30b2194fa837aa67dddb57aadc68ea538ec704 /src/librustpkg | |
| parent | 9cd91c8cc4e87f3abd9201515eefe24f0124810c (diff) | |
rustpkg: Test that different copies of the same package ID can exist in multiple workspaces
The test checks that rustpkg uses the first one, rather than complaining about multiple matches. Closes #7241
Diffstat (limited to 'src/librustpkg')
| -rw-r--r-- | src/librustpkg/path_util.rs | 6 | ||||
| -rw-r--r-- | src/librustpkg/rustpkg.rs | 2 | ||||
| -rw-r--r-- | src/librustpkg/search.rs | 18 | ||||
| -rw-r--r-- | src/librustpkg/tests.rs | 31 | ||||
| -rw-r--r-- | src/librustpkg/util.rs | 35 | ||||
| -rw-r--r-- | src/librustpkg/version.rs | 6 |
6 files changed, 80 insertions, 18 deletions
diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs index 2dbd054ef60..467477ca479 100644 --- a/src/librustpkg/path_util.rs +++ b/src/librustpkg/path_util.rs @@ -49,6 +49,9 @@ 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 { + debug!("Checking in src dir of %s for %s", + workspace.to_str(), pkgid.to_str()); + let src_dir = workspace.push("src"); let mut found = false; @@ -81,6 +84,9 @@ pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool { } true }; + + debug!(if found { fmt!("Found %s in %s", pkgid.to_str(), workspace.to_str()) } + else { fmt!("Didn't find %s in %s", pkgid.to_str(), workspace.to_str()) }); found } diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index f5dc17851e5..b78460dc224 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -250,6 +250,8 @@ impl CtxMethods for Ctx { // argument let pkgid = PkgId::new(args[0]); let workspaces = pkg_parent_workspaces(&pkgid); + debug!("package ID = %s, found it in %? workspaces", + pkgid.to_str(), workspaces.len()); if workspaces.is_empty() { let rp = rust_path(); assert!(!rp.is_empty()); diff --git a/src/librustpkg/search.rs b/src/librustpkg/search.rs index ea0389fed77..9862f870bca 100644 --- a/src/librustpkg/search.rs +++ b/src/librustpkg/search.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use path_util::installed_library_in_workspace; +use path_util::{installed_library_in_workspace, rust_path}; +use version::Version; /// If a library with path `p` matching pkg_id's name exists under sroot_opt, /// return Some(p). Return None if there's no such path or if sroot_opt is None. @@ -19,3 +20,18 @@ pub fn find_library_in_search_path(sroot_opt: Option<@Path>, short_name: &str) - installed_library_in_workspace(short_name, sroot) } } + +/// If some workspace `p` in the RUST_PATH contains a package matching short_name, +/// return Some(p) (returns the first one of there are multiple matches.) Return +/// None if there's no such path. +/// FIXME #8711: This ignores the desired version. +pub fn find_installed_library_in_rust_path(short_name: &str, _version: &Version) -> Option<Path> { + let rp = rust_path(); + for p in rp.iter() { + match installed_library_in_workspace(short_name, p) { + Some(path) => return Some(path), + None => () + } + } + None +} diff --git a/src/librustpkg/tests.rs b/src/librustpkg/tests.rs index 0efa0782da9..fc40c2cd5f7 100644 --- a/src/librustpkg/tests.rs +++ b/src/librustpkg/tests.rs @@ -686,7 +686,7 @@ fn package_script_with_default_build() { push("testsuite").push("pass").push("src").push("fancy-lib").push("pkg.rs"); debug!("package_script_with_default_build: %s", source.to_str()); if !os::copy_file(&source, - & dir.push("src").push("fancy-lib-0.1").push("pkg.rs")) { + &dir.push("src").push("fancy-lib-0.1").push("pkg.rs")) { fail!("Couldn't copy file"); } command_line_test([~"install", ~"fancy-lib"], &dir); @@ -890,20 +890,28 @@ fn no_rebuilding_dep() { assert!(bar_date < foo_date); } +// n.b. The following two tests are ignored; they worked "accidentally" before, +// when the behavior was "always rebuild libraries" (now it's "never rebuild +// libraries if they already exist"). They can be un-ignored once #7075 is done. #[test] +#[ignore(reason = "Workcache not yet implemented -- see #7075")] fn do_rebuild_dep_dates_change() { 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")); + let bar_lib_name = lib_output_file_name(&workspace, "build", "bar"); + let bar_date = datestamp(&bar_lib_name); + debug!("Datestamp on %s is %?", bar_lib_name.to_str(), bar_date); touch_source_file(&workspace, &dep_id); command_line_test([~"build", ~"foo"], &workspace); - let new_bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar")); + let new_bar_date = datestamp(&bar_lib_name); + debug!("Datestamp on %s is %?", bar_lib_name.to_str(), new_bar_date); assert!(new_bar_date > bar_date); } #[test] +#[ignore(reason = "Workcache not yet implemented -- see #7075")] fn do_rebuild_dep_only_contents_change() { let p_id = PkgId::new("foo"); let dep_id = PkgId::new("bar"); @@ -1060,6 +1068,23 @@ fn test_macro_pkg_script() { os::EXE_SUFFIX)))); } +#[test] +fn multiple_workspaces() { +// Make a package foo; build/install in directory A +// Copy the exact same package into directory B and install it +// Set the RUST_PATH to A:B +// Make a third package that uses foo, make sure we can build/install it + let a_loc = mk_temp_workspace(&Path("foo"), &NoVersion).pop().pop(); + let b_loc = mk_temp_workspace(&Path("foo"), &NoVersion).pop().pop(); + debug!("Trying to install foo in %s", a_loc.to_str()); + command_line_test([~"install", ~"foo"], &a_loc); + debug!("Trying to install foo in %s", b_loc.to_str()); + command_line_test([~"install", ~"foo"], &b_loc); + let env = Some(~[(~"RUST_PATH", fmt!("%s:%s", a_loc.to_str(), b_loc.to_str()))]); + let c_loc = create_local_package_with_dep(&PkgId::new("bar"), &PkgId::new("foo")); + command_line_test_with_env([~"install", ~"bar"], &c_loc, env); +} + /// Returns true if p exists and is executable fn is_executable(p: &Path) -> bool { use std::libc::consts::os::posix88::{S_IXUSR}; diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 41c1c7e31ae..4bdb442c1e6 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -20,9 +20,10 @@ use rustc::back::link::output_type_exe; use rustc::driver::session::{lib_crate, bin_crate}; use context::{Ctx, in_target}; use package_id::PkgId; -use search::find_library_in_search_path; +use search::{find_library_in_search_path, find_installed_library_in_rust_path}; use path_util::{target_library_in_workspace, U_RWX}; pub use target::{OutputType, Main, Lib, Bench, Test}; +use version::NoVersion; // It would be nice to have the list of commands in just one place -- for example, // you could update the match in rustpkg.rc but forget to update this list. I think @@ -360,18 +361,32 @@ pub fn find_and_install_dependencies(ctxt: &Ctx, debug!("It exists: %s", installed_path.to_str()); } None => { - // Try to install it - let pkg_id = PkgId::new(lib_name); - my_ctxt.install(&my_workspace, &pkg_id); - // Also, add an additional search path - debug!("let installed_path...") - let installed_path = target_library_in_workspace(&pkg_id, + // FIXME #8711: need to parse version out of path_opt + match find_installed_library_in_rust_path(lib_name, &NoVersion) { + Some(installed_path) => { + debug!("Found library %s, not rebuilding it", + installed_path.to_str()); + // Once workcache is implemented, we'll actually check + // whether or not the library at installed_path is fresh + save(installed_path.pop()); + } + None => { + debug!("Trying to install library %s, rebuilding it", + lib_name.to_str()); + // Try to install it + let pkg_id = PkgId::new(lib_name); + my_ctxt.install(&my_workspace, &pkg_id); + // Also, add an additional search path + debug!("let installed_path...") + let installed_path = target_library_in_workspace(&pkg_id, &my_workspace).pop(); - debug!("Great, I installed %s, and it's in %s", - lib_name, installed_path.to_str()); - save(installed_path); + debug!("Great, I installed %s, and it's in %s", + lib_name, installed_path.to_str()); + save(installed_path); + } } } + } } // Ignore `use`s _ => () diff --git a/src/librustpkg/version.rs b/src/librustpkg/version.rs index f8658517cdf..4528a02db19 100644 --- a/src/librustpkg/version.rs +++ b/src/librustpkg/version.rs @@ -213,11 +213,9 @@ fn is_url_like(p: &Path) -> bool { pub fn split_version<'a>(s: &'a str) -> Option<(&'a str, Version)> { // Check for extra '#' characters separately if s.split_iter('#').len() > 2 { - None - } - else { - split_version_general(s, '#') + return None; } + split_version_general(s, '#') } pub fn split_version_general<'a>(s: &'a str, sep: char) -> Option<(&'a str, Version)> { |
