Skip to content

Commit

Permalink
rustpkg: Make checked-out source files read-only, and overhaul where …
Browse files Browse the repository at this point in the history
…temporary files are stored

rustpkg now makes source files that it checks out automatically read-only, and stores
them under build/.

Also, refactored the `PkgSrc` type to keep track of separate source and destination
workspaces, as well as to have a `build_workspace` method that returns the workspace
to put temporary files in (usually the source, sometimes the destination -- see
comments for more details).

Closes #6480
  • Loading branch information
catamorphism committed Oct 10, 2013
1 parent 8b8a41a commit 8854b78
Show file tree
Hide file tree
Showing 11 changed files with 539 additions and 293 deletions.
9 changes: 8 additions & 1 deletion doc/rustpkg.md
Expand Up @@ -137,6 +137,9 @@ and builds it in any workspace(s) where it finds one.
Supposing such packages are found in workspaces X, Y, and Z,
the command leaves behind files in `X`'s, `Y`'s, and `Z`'s `build` directories,
but not in their `lib` or `bin` directories.
(The exception is when rustpkg fetches a package `foo`'s sources from a remote repository.
In that case, it stores both the sources *and* the build artifacts for `foo`
in the workspace that `foo` will install to (see ##install below)).

## clean

Expand All @@ -148,7 +151,11 @@ but not in their `lib` or `bin` directories.
If `RUST_PATH` is declared as an environment variable, then rustpkg installs the
libraries and executables into the `lib` and `bin` subdirectories
of the first entry in `RUST_PATH`.
Otherwise, it installs them into `foo`'s `lib` and `bin` directories.
Otherwise, if the current working directory CWD is a workspace,
it installs them into CWD's `lib` and `bin` subdirectories.
Otherwise, if the current working directory is CWD,
it installs them into the .rust/lib and .rust/bin subdirectories of CWD
(creating them if necessary).

## test

Expand Down
28 changes: 17 additions & 11 deletions src/librustpkg/api.rs
Expand Up @@ -16,6 +16,8 @@ use target::*;
use version::Version;
use workcache_support::*;

pub use source_control::{safe_git_clone, git_clone_url};

use std::os;
use extra::arc::{Arc,RWArc};
use extra::workcache;
Expand Down Expand Up @@ -68,23 +70,27 @@ pub fn build_lib(sysroot: Path, root: Path, name: ~str, version: Version,
lib: Path) {
let cx = default_context(sysroot);
let pkg_src = PkgSrc {
workspace: root.clone(),
start_dir: root.push("src").push(name),
id: PkgId{ version: version, ..PkgId::new(name)},
// n.b. This assumes the package only has one crate
libs: ~[mk_crate(lib)],
mains: ~[],
tests: ~[],
benchs: ~[]
};
source_workspace: root.clone(),
build_in_destination: false,
destination_workspace: root.clone(),
start_dir: root.push("src").push(name),
id: PkgId{ version: version, ..PkgId::new(name)},
// n.b. This assumes the package only has one crate
libs: ~[mk_crate(lib)],
mains: ~[],
tests: ~[],
benchs: ~[]
};
pkg_src.build(&cx, ~[]);
}

pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
main: Path) {
let cx = default_context(sysroot);
let pkg_src = PkgSrc {
workspace: root.clone(),
source_workspace: root.clone(),
build_in_destination: false,
destination_workspace: root.clone(),
start_dir: root.push("src").push(name),
id: PkgId{ version: version, ..PkgId::new(name)},
libs: ~[],
Expand All @@ -100,7 +106,7 @@ pub fn build_exe(sysroot: Path, root: Path, name: ~str, version: Version,
pub fn install_pkg(sysroot: Path, workspace: Path, name: ~str, version: Version) {
let cx = default_context(sysroot);
let pkgid = PkgId{ version: version, ..PkgId::new(name)};
cx.install(PkgSrc::new(workspace, false, pkgid), &Everything);
cx.install(PkgSrc::new(workspace.clone(), workspace, false, pkgid), &Everything);
}

fn mk_crate(p: Path) -> Crate {
Expand Down
4 changes: 4 additions & 0 deletions src/librustpkg/conditions.rs
Expand Up @@ -50,3 +50,7 @@ condition! {
condition! {
pub failed_to_create_temp_dir: (~str) -> Path;
}

condition! {
pub git_checkout_failed: (~str, Path) -> ();
}
12 changes: 8 additions & 4 deletions src/librustpkg/package_id.rs
Expand Up @@ -102,10 +102,7 @@ impl PkgId {
}

pub fn prefixes_iter(&self) -> Prefixes {
Prefixes {
components: self.path.components().to_owned(),
remaining: ~[]
}
prefixes_iter(&self.path)
}

// This is the workcache function name for the *installed*
Expand All @@ -116,6 +113,13 @@ impl PkgId {
}
}

pub fn prefixes_iter(p: &Path) -> Prefixes {
Prefixes {
components: p.components().to_owned(),
remaining: ~[]
}
}

struct Prefixes {
priv components: ~[~str],
priv remaining: ~[~str]
Expand Down

5 comments on commit 8854b78

@bors
Copy link
Contributor

@bors bors commented on 8854b78 Oct 11, 2013

Choose a reason for hiding this comment

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

saw approval from brson
at catamorphism@8854b78

@bors
Copy link
Contributor

@bors bors commented on 8854b78 Oct 11, 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-read-only = 8854b78 into auto

@bors
Copy link
Contributor

@bors bors commented on 8854b78 Oct 11, 2013

Choose a reason for hiding this comment

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

catamorphism/rust/rustpkg-read-only = 8854b78 merged ok, testing candidate = 2e1df8e

@bors
Copy link
Contributor

@bors bors commented on 8854b78 Oct 11, 2013

@bors
Copy link
Contributor

@bors bors commented on 8854b78 Oct 11, 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 = 2e1df8e

Please sign in to comment.