Skip to content

Commit a13adb5

Browse files
committed
---
yaml --- r: 85890 b: refs/heads/dist-snap c: f22b4b1 h: refs/heads/master v: v3
1 parent 005ef35 commit a13adb5

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 578e68047736167239c52fa1aba0347011ff1bc3
9+
refs/heads/dist-snap: f22b4b169854c8a4ba86c16ee43327d6bcf94562
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustpkg/rustpkg.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use path_util::{U_RWX, in_rust_path};
4343
use path_util::{built_executable_in_workspace, built_library_in_workspace, default_workspace};
4444
use path_util::{target_executable_in_workspace, target_library_in_workspace};
4545
use source_control::is_git_dir;
46-
use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces, in_workspace, cwd_to_workspace};
46+
use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces, cwd_to_workspace};
4747
use context::Ctx;
4848
use package_id::PkgId;
4949
use package_source::PkgSrc;
@@ -190,11 +190,10 @@ impl CtxMethods for Ctx {
190190
match cmd {
191191
"build" => {
192192
if args.len() < 1 {
193-
if !in_workspace(|| { usage::build() } ) {
194-
return;
193+
match cwd_to_workspace() {
194+
None => { usage::build(); return }
195+
Some((ws, pkgid)) => self.build(&ws, &pkgid)
195196
}
196-
let (workspace, pkgid) = cwd_to_workspace();
197-
self.build(&workspace, &pkgid);
198197
}
199198
else {
200199
// The package id is presumed to be the first command-line
@@ -210,13 +209,12 @@ impl CtxMethods for Ctx {
210209
}
211210
"clean" => {
212211
if args.len() < 1 {
213-
if !in_workspace(|| { usage::clean() } ) {
214-
return;
212+
match cwd_to_workspace() {
213+
None => { usage::clean(); return }
214+
// tjc: Maybe clean should clean all the packages in the
215+
// current workspace, though?
216+
Some((ws, pkgid)) => self.clean(&ws, &pkgid)
215217
}
216-
// tjc: Maybe clean should clean all the packages in the
217-
// current workspace, though?
218-
let (workspace, pkgid) = cwd_to_workspace();
219-
self.clean(&workspace, &pkgid);
220218

221219
}
222220
else {
@@ -239,11 +237,10 @@ impl CtxMethods for Ctx {
239237
}
240238
"install" => {
241239
if args.len() < 1 {
242-
if !in_workspace(|| { usage::install() }) {
243-
return;
240+
match cwd_to_workspace() {
241+
None => { usage::install(); return }
242+
Some((ws, pkgid)) => self.install(&ws, &pkgid)
244243
}
245-
let (workspace, pkgid) = cwd_to_workspace();
246-
self.install(&workspace, &pkgid);
247244
}
248245
else {
249246
// The package id is presumed to be the first command-line

branches/dist-snap/src/librustpkg/tests.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ fn package_script_with_default_build() {
695695
696696
#[test]
697697
fn rustpkg_build_no_arg() {
698-
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed");
698+
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed")
699+
.push(".rust");
699700
let package_dir = tmp.push("src").push("foo");
700701
assert!(os::mkdir_recursive(&package_dir, U_RWX));
701702
@@ -709,7 +710,8 @@ fn rustpkg_build_no_arg() {
709710
#[test]
710711
fn rustpkg_install_no_arg() {
711712
let tmp = mkdtemp(&os::tmpdir(),
712-
"rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed");
713+
"rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed")
714+
.push(".rust");
713715
let package_dir = tmp.push("src").push("foo");
714716
assert!(os::mkdir_recursive(&package_dir, U_RWX));
715717
writeFile(&package_dir.push("lib.rs"),
@@ -721,7 +723,8 @@ fn rustpkg_install_no_arg() {
721723
722724
#[test]
723725
fn rustpkg_clean_no_arg() {
724-
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed");
726+
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed")
727+
.push(".rust");
725728
let package_dir = tmp.push("src").push("foo");
726729
assert!(os::mkdir_recursive(&package_dir, U_RWX));
727730

branches/dist-snap/src/librustpkg/workspace.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
// rustpkg utilities having to do with workspaces
1212

13-
use std::os;
13+
use std::{os,util};
1414
use std::path::Path;
1515
use path_util::workspace_contains_package_id;
1616
use package_id::PkgId;
1717

18-
use rustc::metadata::filesearch::rust_path;
18+
use path_util::rust_path;
1919

2020
pub fn each_pkg_parent_workspace(pkgid: &PkgId, action: &fn(&Path) -> bool) -> bool {
2121
// Using the RUST_PATH, find workspaces that contain
@@ -42,23 +42,22 @@ pub fn pkg_parent_workspaces(pkgid: &PkgId) -> ~[Path] {
4242
.collect()
4343
}
4444

45-
pub fn in_workspace(complain: &fn()) -> bool {
46-
let dir_part = os::getcwd().pop().components.clone();
47-
if *(dir_part.last()) != ~"src" {
48-
complain();
49-
false
50-
}
51-
else {
52-
true
53-
}
54-
}
55-
5645
/// Construct a workspace and package-ID name based on the current directory.
5746
/// This gets used when rustpkg gets invoked without a package-ID argument.
58-
pub fn cwd_to_workspace() -> (Path, PkgId) {
47+
pub fn cwd_to_workspace() -> Option<(Path, PkgId)> {
5948
let cwd = os::getcwd();
60-
let ws = cwd.pop().pop();
61-
let cwd_ = cwd.clone();
62-
let pkgid = cwd_.components.last().to_str();
63-
(ws, PkgId::new(pkgid))
49+
for path in rust_path().move_iter() {
50+
let srcpath = path.push("src");
51+
if srcpath.is_ancestor_of(&cwd) {
52+
// I'd love to use srcpath.get_relative_to(cwd) but it behaves wrong
53+
// I'd say broken, but it has tests enforcing the wrong behavior.
54+
// instead, just hack up the components vec
55+
let mut pkgid = cwd;
56+
pkgid.is_absolute = false;
57+
let comps = util::replace(&mut pkgid.components, ~[]);
58+
pkgid.components = comps.move_iter().skip(srcpath.components.len()).collect();
59+
return Some((path, PkgId::new(pkgid.components.connect("/"))))
60+
}
61+
}
62+
None
6463
}

0 commit comments

Comments
 (0)