Skip to content

Commit

Permalink
rustpkg: Install to RUST_PATH
Browse files Browse the repository at this point in the history
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
  • Loading branch information
catamorphism committed Sep 13, 2013
1 parent 19c0735 commit b4b375c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/librustpkg/path_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,12 @@ pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> {
}
None
}

/// True if the user set RUST_PATH to something non-empty --
/// as opposed to the default paths that rustpkg adds automatically
pub fn user_set_rust_path() -> bool {
match os::getenv("RUST_PATH") {
None | Some(~"") => false,
Some(_) => true
}
}
33 changes: 24 additions & 9 deletions src/librustpkg/rustpkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ pub trait CtxMethods {
/// second is a list of declared and discovered inputs
fn install(&self, src: PkgSrc) -> (~[Path], ~[(~str, ~str)]);
/// Returns a list of installed files
fn install_no_build(&self, workspace: &Path, id: &PkgId) -> ~[Path];
fn install_no_build(&self,
source_workspace: &Path,
target_workspace: &Path,
id: &PkgId) -> ~[Path];
fn prefer(&self, _id: &str, _vers: Option<~str>);
fn test(&self);
fn uninstall(&self, _id: &str, _vers: Option<~str>);
Expand Down Expand Up @@ -464,28 +467,40 @@ impl CtxMethods for BuildContext {
// install to the first workspace in the RUST_PATH if there's
// a non-default RUST_PATH. This code installs to the same
// workspace the package was built in.
debug!("install: destination workspace = %s, id = %s",
destination_workspace, id_str);
let result = subself.install_no_build(&Path(destination_workspace), &sub_id);
let actual_workspace = if path_util::user_set_rust_path() {
default_workspace()
}
else {
Path(destination_workspace)
};
debug!("install: destination workspace = %s, id = %s, installing to %s",
destination_workspace, id_str, actual_workspace.to_str());
let result = subself.install_no_build(&Path(destination_workspace),
&actual_workspace,
&sub_id);
debug!("install: id = %s, about to call discover_outputs, %?",
id_str, result.to_str());

discover_outputs(exec, result.clone());
sub_files.write(|r| { *r = result.clone(); });
sub_inputs.write(|r| { *r = *r + exec.lookup_discovered_inputs() });
note(fmt!("Installed package %s to %s", id_str, actual_workspace.to_str()));
}
};
(installed_files.unwrap(), inputs.unwrap())
}

fn install_no_build(&self, workspace: &Path, id: &PkgId) -> ~[Path] {
fn install_no_build(&self,
source_workspace: &Path,
target_workspace: &Path,
id: &PkgId) -> ~[Path] {
use conditions::copy_failed::cond;

// Now copy stuff into the install dirs
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(id, workspace));
let maybe_executable = built_executable_in_workspace(id, source_workspace);
let maybe_library = built_library_in_workspace(id, source_workspace);
let target_exec = target_executable_in_workspace(id, target_workspace);
let target_lib = maybe_library.map(|_p| target_library_in_workspace(id, target_workspace));

debug!("target_exec = %s target_lib = %? \
maybe_executable = %? maybe_library = %?",
Expand Down
19 changes: 19 additions & 0 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,25 @@ fn test_recursive_deps() {
assert_lib_exists(&b_workspace, &Path("c"), NoVersion);
}

#[test]
fn test_install_to_rust_path() {
let p_id = PkgId::new("foo");
let second_workspace = create_local_package(&p_id);
let first_workspace = mk_empty_workspace(&Path("p"), &NoVersion, "dest");
let rust_path = Some(~[(~"RUST_PATH",
fmt!("%s:%s", first_workspace.to_str(),
second_workspace.to_str()))]);
debug!("RUST_PATH=%s:%s", first_workspace.to_str(), second_workspace.to_str());
command_line_test_with_env([test_sysroot().to_str(),
~"install",
~"foo"],
&os::getcwd(), rust_path);
assert!(!built_executable_exists(&first_workspace, "foo"));
assert!(built_executable_exists(&second_workspace, "foo"));
assert_executable_exists(&first_workspace, "foo");
assert!(!executable_exists(&second_workspace, "foo"));
}

/// Returns true if p exists and is executable
fn is_executable(p: &Path) -> bool {
use std::libc::consts::os::posix88::{S_IXUSR};
Expand Down

5 comments on commit b4b375c

@bors
Copy link
Contributor

@bors bors commented on b4b375c Sep 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from catamorphism, metajack
at catamorphism@b4b375c

@bors
Copy link
Contributor

@bors bors commented on b4b375c Sep 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging catamorphism/rust/rustpkg-install-to-rust-path = b4b375c into auto

@bors
Copy link
Contributor

@bors bors commented on b4b375c Sep 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catamorphism/rust/rustpkg-install-to-rust-path = b4b375c merged ok, testing candidate = c7657b7

@bors
Copy link
Contributor

@bors bors commented on b4b375c Sep 13, 2013

@bors
Copy link
Contributor

@bors bors commented on b4b375c Sep 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c7657b7

Please sign in to comment.