Skip to content

Commit 9580aa0

Browse files
committed
---
yaml --- r: 144507 b: refs/heads/try2 c: b8d1fa3 h: refs/heads/master i: 144505: 4f59c56 144503: f9e6d2e v: v3
1 parent 3150f4b commit 9580aa0

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 4635644746034bd01306159cc952cbdda23b3703
8+
refs/heads/try2: b8d1fa399402c71331aefd634d710004e00b73a6
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/src/librustpkg/tests.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ fn package_script_with_default_build() {
696696
697697
#[test]
698698
fn rustpkg_build_no_arg() {
699-
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed");
699+
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed")
700+
.push(".rust");
700701
let package_dir = tmp.push("src").push("foo");
701702
assert!(os::mkdir_recursive(&package_dir, U_RWX));
702703
@@ -710,7 +711,8 @@ fn rustpkg_build_no_arg() {
710711
#[test]
711712
fn rustpkg_install_no_arg() {
712713
let tmp = mkdtemp(&os::tmpdir(),
713-
"rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed");
714+
"rustpkg_install_no_arg").expect("rustpkg_install_no_arg failed")
715+
.push(".rust");
714716
let package_dir = tmp.push("src").push("foo");
715717
assert!(os::mkdir_recursive(&package_dir, U_RWX));
716718
writeFile(&package_dir.push("lib.rs"),
@@ -722,7 +724,8 @@ fn rustpkg_install_no_arg() {
722724
723725
#[test]
724726
fn rustpkg_clean_no_arg() {
725-
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed");
727+
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed")
728+
.push(".rust");
726729
let package_dir = tmp.push("src").push("foo");
727730
assert!(os::mkdir_recursive(&package_dir, U_RWX));
728731

branches/try2/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)