Skip to content

Commit c7657b7

Browse files
committed
auto merge of #9147 : catamorphism/rust/rustpkg-install-to-rust-path, r=catamorphism,metajack
r? @metajack Install to the first directory in the RUST_PATH if the user set a RUST_PATH. In the case where RUST_PATH isn't set, the behavior remains unchanged. Closes #7402
2 parents 19c0735 + b4b375c commit c7657b7

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

src/librustpkg/path_util.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,12 @@ pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> {
399399
}
400400
None
401401
}
402+
403+
/// True if the user set RUST_PATH to something non-empty --
404+
/// as opposed to the default paths that rustpkg adds automatically
405+
pub fn user_set_rust_path() -> bool {
406+
match os::getenv("RUST_PATH") {
407+
None | Some(~"") => false,
408+
Some(_) => true
409+
}
410+
}

src/librustpkg/rustpkg.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ pub trait CtxMethods {
181181
/// second is a list of declared and discovered inputs
182182
fn install(&self, src: PkgSrc) -> (~[Path], ~[(~str, ~str)]);
183183
/// Returns a list of installed files
184-
fn install_no_build(&self, workspace: &Path, id: &PkgId) -> ~[Path];
184+
fn install_no_build(&self,
185+
source_workspace: &Path,
186+
target_workspace: &Path,
187+
id: &PkgId) -> ~[Path];
185188
fn prefer(&self, _id: &str, _vers: Option<~str>);
186189
fn test(&self);
187190
fn uninstall(&self, _id: &str, _vers: Option<~str>);
@@ -464,28 +467,40 @@ impl CtxMethods for BuildContext {
464467
// install to the first workspace in the RUST_PATH if there's
465468
// a non-default RUST_PATH. This code installs to the same
466469
// workspace the package was built in.
467-
debug!("install: destination workspace = %s, id = %s",
468-
destination_workspace, id_str);
469-
let result = subself.install_no_build(&Path(destination_workspace), &sub_id);
470+
let actual_workspace = if path_util::user_set_rust_path() {
471+
default_workspace()
472+
}
473+
else {
474+
Path(destination_workspace)
475+
};
476+
debug!("install: destination workspace = %s, id = %s, installing to %s",
477+
destination_workspace, id_str, actual_workspace.to_str());
478+
let result = subself.install_no_build(&Path(destination_workspace),
479+
&actual_workspace,
480+
&sub_id);
470481
debug!("install: id = %s, about to call discover_outputs, %?",
471482
id_str, result.to_str());
472483

473484
discover_outputs(exec, result.clone());
474485
sub_files.write(|r| { *r = result.clone(); });
475486
sub_inputs.write(|r| { *r = *r + exec.lookup_discovered_inputs() });
487+
note(fmt!("Installed package %s to %s", id_str, actual_workspace.to_str()));
476488
}
477489
};
478490
(installed_files.unwrap(), inputs.unwrap())
479491
}
480492

481-
fn install_no_build(&self, workspace: &Path, id: &PkgId) -> ~[Path] {
493+
fn install_no_build(&self,
494+
source_workspace: &Path,
495+
target_workspace: &Path,
496+
id: &PkgId) -> ~[Path] {
482497
use conditions::copy_failed::cond;
483498

484499
// Now copy stuff into the install dirs
485-
let maybe_executable = built_executable_in_workspace(id, workspace);
486-
let maybe_library = built_library_in_workspace(id, workspace);
487-
let target_exec = target_executable_in_workspace(id, workspace);
488-
let target_lib = maybe_library.map(|_p| target_library_in_workspace(id, workspace));
500+
let maybe_executable = built_executable_in_workspace(id, source_workspace);
501+
let maybe_library = built_library_in_workspace(id, source_workspace);
502+
let target_exec = target_executable_in_workspace(id, target_workspace);
503+
let target_lib = maybe_library.map(|_p| target_library_in_workspace(id, target_workspace));
489504

490505
debug!("target_exec = %s target_lib = %? \
491506
maybe_executable = %? maybe_library = %?",

src/librustpkg/tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,25 @@ fn test_recursive_deps() {
16031603
assert_lib_exists(&b_workspace, &Path("c"), NoVersion);
16041604
}
16051605
1606+
#[test]
1607+
fn test_install_to_rust_path() {
1608+
let p_id = PkgId::new("foo");
1609+
let second_workspace = create_local_package(&p_id);
1610+
let first_workspace = mk_empty_workspace(&Path("p"), &NoVersion, "dest");
1611+
let rust_path = Some(~[(~"RUST_PATH",
1612+
fmt!("%s:%s", first_workspace.to_str(),
1613+
second_workspace.to_str()))]);
1614+
debug!("RUST_PATH=%s:%s", first_workspace.to_str(), second_workspace.to_str());
1615+
command_line_test_with_env([test_sysroot().to_str(),
1616+
~"install",
1617+
~"foo"],
1618+
&os::getcwd(), rust_path);
1619+
assert!(!built_executable_exists(&first_workspace, "foo"));
1620+
assert!(built_executable_exists(&second_workspace, "foo"));
1621+
assert_executable_exists(&first_workspace, "foo");
1622+
assert!(!executable_exists(&second_workspace, "foo"));
1623+
}
1624+
16061625
/// Returns true if p exists and is executable
16071626
fn is_executable(p: &Path) -> bool {
16081627
use std::libc::consts::os::posix88::{S_IXUSR};

0 commit comments

Comments
 (0)