Skip to content

Commit 2554009

Browse files
committed
---
yaml --- r: 142995 b: refs/heads/try2 c: 96c1082 h: refs/heads/master i: 142993: 7897499 142991: a2dfae6 v: v3
1 parent 1202f12 commit 2554009

File tree

10 files changed

+102
-221
lines changed

10 files changed

+102
-221
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: fdbd56ca38c4a58377056c63e0b03b0d4e131f2c
8+
refs/heads/try2: 96c1082f0fdbbe5258cfc1dc37f83052feff8421
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustpkg/installed_packages.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,11 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
1818
for workspaces.iter().advance |p| {
1919
let binfiles = os::list_dir(&p.push("bin"));
2020
for binfiles.iter().advance() |exec| {
21-
let exec_path = Path(*exec).filestem();
22-
do exec_path.iter().advance |s| {
23-
f(&PkgId::new(*s, p))
24-
};
21+
f(&PkgId::new(*exec, p));
2522
}
2623
let libfiles = os::list_dir(&p.push("lib"));
2724
for libfiles.iter().advance() |lib| {
28-
debug!("Full name: %s", *lib);
29-
let lib_path = Path(*lib).filestem();
30-
do lib_path.iter().advance |s| {
31-
f(&PkgId::new(*s, p))
32-
};
25+
f(&PkgId::new(*lib, p));
3326
}
3427
}
3528
true

branches/try2/src/librustpkg/path_util.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,11 @@ pub fn rust_path() -> ~[Path] {
5454
};
5555
let cwd = os::getcwd();
5656
// now add in default entries
57+
env_rust_path.push(cwd.push(".rust"));
5758
env_rust_path.push(cwd.clone());
5859
do cwd.each_parent() |p| { push_if_exists(&mut env_rust_path, p) };
5960
let h = os::homedir();
60-
// Avoid adding duplicates
61-
// could still add dups if someone puts one of these in the RUST_PATH
62-
// manually, though...
63-
for h.iter().advance |hdir| {
64-
if !(cwd.is_ancestor_of(hdir) || hdir.is_ancestor_of(&cwd)) {
65-
push_if_exists(&mut env_rust_path, hdir);
66-
}
67-
}
61+
for h.iter().advance |h| { push_if_exists(&mut env_rust_path, h); }
6862
env_rust_path
6963
}
7064

branches/try2/src/librustpkg/rustpkg.rs

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use path_util::{U_RWX, rust_path, in_rust_path};
4242
use path_util::{built_executable_in_workspace, built_library_in_workspace, default_workspace};
4343
use path_util::{target_executable_in_workspace, target_library_in_workspace};
4444
use source_control::is_git_dir;
45-
use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces, in_workspace, cwd_to_workspace};
45+
use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces};
4646
use context::Ctx;
4747
use package_id::PkgId;
4848
use package_source::PkgSrc;
@@ -199,41 +199,26 @@ impl CtxMethods for Ctx {
199199
match cmd {
200200
"build" => {
201201
if args.len() < 1 {
202-
if !in_workspace(|| { usage::build() } ) {
203-
return;
204-
}
205-
let (workspace, pkgid) = cwd_to_workspace();
206-
self.build(&workspace, &pkgid);
202+
return usage::build();
207203
}
208-
else {
209-
// The package id is presumed to be the first command-line
210-
// argument
211-
let pkgid = PkgId::new(args[0].clone(), &os::getcwd());
212-
for each_pkg_parent_workspace(&pkgid) |workspace| {
213-
debug!("found pkg %s in workspace %s, trying to build",
214-
pkgid.to_str(), workspace.to_str());
215-
self.build(workspace, &pkgid);
216-
}
204+
// The package id is presumed to be the first command-line
205+
// argument
206+
let pkgid = PkgId::new(args[0].clone(), &os::getcwd());
207+
for each_pkg_parent_workspace(&pkgid) |workspace| {
208+
debug!("found pkg %s in workspace %s, trying to build",
209+
pkgid.to_str(), workspace.to_str());
210+
self.build(workspace, &pkgid);
217211
}
218212
}
219213
"clean" => {
220214
if args.len() < 1 {
221-
if !in_workspace(|| { usage::clean() } ) {
222-
return;
223-
}
224-
// tjc: Maybe clean should clean all the packages in the
225-
// current workspace, though?
226-
let (workspace, pkgid) = cwd_to_workspace();
227-
self.clean(&workspace, &pkgid);
228-
229-
}
230-
else {
231-
// The package id is presumed to be the first command-line
232-
// argument
233-
let pkgid = PkgId::new(args[0].clone(), &os::getcwd());
234-
let cwd = os::getcwd();
235-
self.clean(&cwd, &pkgid); // tjc: should use workspace, not cwd
215+
return usage::build();
236216
}
217+
// The package id is presumed to be the first command-line
218+
// argument
219+
let pkgid = PkgId::new(args[0].clone(), &os::getcwd());
220+
let cwd = os::getcwd();
221+
self.clean(&cwd, &pkgid); // tjc: should use workspace, not cwd
237222
}
238223
"do" => {
239224
if args.len() < 2 {
@@ -247,36 +232,37 @@ impl CtxMethods for Ctx {
247232
}
248233
"install" => {
249234
if args.len() < 1 {
250-
if !in_workspace(|| { usage::install() }) {
251-
return;
252-
}
253-
let (workspace, pkgid) = cwd_to_workspace();
254-
self.install(&workspace, &pkgid);
235+
return usage::install();
236+
}
237+
238+
// The package id is presumed to be the first command-line
239+
// argument
240+
let pkgid = PkgId::new(args[0], &os::getcwd());
241+
let workspaces = pkg_parent_workspaces(&pkgid);
242+
if workspaces.is_empty() {
243+
debug!("install! workspaces was empty");
244+
let rp = rust_path();
245+
assert!(!rp.is_empty());
246+
let src = PkgSrc::new(&rp[0], &build_pkg_id_in_workspace(&pkgid, &rp[0]),
247+
&pkgid);
248+
src.fetch_git();
249+
self.install(&rp[0], &pkgid);
255250
}
256251
else {
257-
// The package id is presumed to be the first command-line
258-
// argument
259-
let pkgid = PkgId::new(args[0], &os::getcwd());
260-
let workspaces = pkg_parent_workspaces(&pkgid);
261-
if workspaces.is_empty() {
262-
let rp = rust_path();
263-
assert!(!rp.is_empty());
264-
let src = PkgSrc::new(&rp[0], &build_pkg_id_in_workspace(&pkgid, &rp[0]),
265-
&pkgid);
266-
src.fetch_git();
267-
self.install(&rp[0], &pkgid);
268-
}
269-
else {
270-
for each_pkg_parent_workspace(&pkgid) |workspace| {
271-
self.install(workspace, &pkgid);
272-
}
252+
for each_pkg_parent_workspace(&pkgid) |workspace| {
253+
debug!("install: found pkg %s in workspace %s, trying to build",
254+
pkgid.to_str(), workspace.to_str());
255+
256+
self.install(workspace, &pkgid);
273257
}
274258
}
275259
}
276260
"list" => {
277261
io::println("Installed packages:");
278262
for installed_packages::list_installed_packages |pkg_id| {
279-
io::println(pkg_id.local_path.to_str());
263+
io::println(fmt!("%s-%s",
264+
pkg_id.local_path.to_str(),
265+
pkg_id.version.to_str()));
280266
}
281267
}
282268
"prefer" => {

branches/try2/src/librustpkg/tests.rs

Lines changed: 23 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ fn command_line_test(args: &[~str], cwd: &Path) -> ProcessOutput {
218218
fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~str)]>)
219219
-> ProcessOutput {
220220
let cmd = test_sysroot().push("bin").push("rustpkg").to_str();
221+
let cwd = normalize(RemotePath((*cwd).clone()));
221222
debug!("About to run command: %? %? in %s", cmd, args, cwd.to_str());
222223
assert!(os::path_is_dir(&*cwd));
223224
let cwd = (*cwd).clone();
@@ -321,14 +322,6 @@ fn assert_executable_exists(repo: &Path, short_name: &str) {
321322
assert!(is_rwx(&exec));
322323
}
323324

324-
fn assert_built_executable_exists(repo: &Path, short_name: &str) {
325-
debug!("assert_built_executable_exists: repo = %s, short_name = %s", repo.to_str(), short_name);
326-
let exec = built_executable_in_workspace(&PkgId::new(short_name, repo),
327-
repo).expect("assert_built_executable_exists failed");
328-
assert!(os::path_exists(&exec));
329-
assert!(is_rwx(&exec));
330-
}
331-
332325
fn command_line_test_output(args: &[~str]) -> ~[~str] {
333326
let mut result = ~[];
334327
let p_output = command_line_test(args, &os::getcwd());
@@ -497,29 +490,30 @@ fn test_install_git() {
497490
// should have test, bench, lib, and main
498491
command_line_test([~"install", temp_pkg_id.local_path.to_str()], &repo);
499492
// Check that all files exist
500-
debug!("Checking for files in %s", repo.to_str());
501-
let exec = target_executable_in_workspace(&temp_pkg_id, &repo);
493+
let ws = repo.push(".rust");
494+
debug!("Checking for files in %s", ws.to_str());
495+
let exec = target_executable_in_workspace(&temp_pkg_id, &ws);
502496
debug!("exec = %s", exec.to_str());
503497
assert!(os::path_exists(&exec));
504498
assert!(is_rwx(&exec));
505499
let _built_lib =
506500
built_library_in_workspace(&temp_pkg_id,
507-
&repo).expect("test_install_git: built lib should exist");
508-
let lib = target_library_in_workspace(&temp_pkg_id, &repo);
501+
&ws).expect("test_install_git: built lib should exist");
502+
let lib = target_library_in_workspace(&temp_pkg_id, &ws);
509503
debug!("lib = %s", lib.to_str());
510504
assert!(os::path_exists(&lib));
511505
assert!(is_rwx(&lib));
512506
let built_test = built_test_in_workspace(&temp_pkg_id,
513-
&repo).expect("test_install_git: built test should exist");
507+
&ws).expect("test_install_git: built test should exist");
514508
assert!(os::path_exists(&built_test));
515509
let built_bench = built_bench_in_workspace(&temp_pkg_id,
516-
&repo).expect("test_install_git: built bench should exist");
510+
&ws).expect("test_install_git: built bench should exist");
517511
assert!(os::path_exists(&built_bench));
518512
// And that the test and bench executables aren't installed
519-
let test = target_test_in_workspace(&temp_pkg_id, &repo);
513+
let test = target_test_in_workspace(&temp_pkg_id, &ws);
520514
assert!(!os::path_exists(&test));
521515
debug!("test = %s", test.to_str());
522-
let bench = target_bench_in_workspace(&temp_pkg_id, &repo);
516+
let bench = target_bench_in_workspace(&temp_pkg_id, &ws);
523517
debug!("bench = %s", bench.to_str());
524518
assert!(!os::path_exists(&bench));
525519
}
@@ -592,12 +586,12 @@ fn test_package_version() {
592586
command_line_test([~"install", ~"mockgithub.com/catamorphism/test_pkg_version"],
593587
&repo);
594588
assert!(match built_library_in_workspace(&temp_pkg_id,
595-
&repo) {
589+
&repo.push(".rust")) {
596590
Some(p) => p.to_str().ends_with(fmt!("0.4%s", os::consts::DLL_SUFFIX)),
597591
None => false
598592
});
599-
assert!(built_executable_in_workspace(&temp_pkg_id, &repo)
600-
== Some(repo.push("build").
593+
assert!(built_executable_in_workspace(&temp_pkg_id, &repo.push(".rust"))
594+
== Some(repo.push(".rust").push("build").
601595
push("mockgithub.com").
602596
push("catamorphism").
603597
push("test_pkg_version").
@@ -695,7 +689,7 @@ fn rustpkg_library_target() {
695689
696690
add_git_tag(&package_dir, ~"1.0");
697691
command_line_test([~"install", ~"foo"], &foo_repo);
698-
assert_lib_exists(&foo_repo, "foo", ExactRevision(~"1.0"));
692+
assert_lib_exists(&foo_repo.push(".rust"), "foo", ExactRevision(~"1.0"));
699693
}
700694
701695
#[test]
@@ -722,55 +716,14 @@ fn package_script_with_default_build() {
722716
assert!(os::path_exists(&dir.push("build").push("fancy_lib").push("generated.rs")));
723717
}
724718
725-
#[test]
726-
fn rustpkg_build_no_arg() {
727-
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_build_no_arg").expect("rustpkg_build_no_arg failed");
728-
let package_dir = tmp.push("src").push("foo");
729-
assert!(os::mkdir_recursive(&package_dir, U_RWX));
730-
731-
writeFile(&package_dir.push("main.rs"),
732-
"fn main() { let _x = (); }");
733-
debug!("build_no_arg: dir = %s", package_dir.to_str());
734-
command_line_test([~"build"], &package_dir);
735-
assert_built_executable_exists(&tmp, "foo");
736-
}
737-
738-
#[test]
739-
fn rustpkg_install_no_arg() {
740-
let tmp = mkdtemp(&os::tmpdir(),
741-
"rustpkg_install_no_arg").expect("rustpkg_build_no_arg failed");
742-
let package_dir = tmp.push("src").push("foo");
743-
assert!(os::mkdir_recursive(&package_dir, U_RWX));
744-
writeFile(&package_dir.push("lib.rs"),
745-
"fn main() { let _x = (); }");
746-
debug!("install_no_arg: dir = %s", package_dir.to_str());
747-
command_line_test([~"install"], &package_dir);
748-
assert_lib_exists(&tmp, "foo", NoVersion);
749-
}
750-
751-
#[test]
752-
fn rustpkg_clean_no_arg() {
753-
let tmp = mkdtemp(&os::tmpdir(), "rustpkg_clean_no_arg").expect("rustpkg_clean_no_arg failed");
754-
let package_dir = tmp.push("src").push("foo");
755-
assert!(os::mkdir_recursive(&package_dir, U_RWX));
756-
757-
writeFile(&package_dir.push("main.rs"),
758-
"fn main() { let _x = (); }");
759-
debug!("clean_no_arg: dir = %s", package_dir.to_str());
760-
command_line_test([~"build"], &package_dir);
761-
assert_built_executable_exists(&tmp, "foo");
762-
command_line_test([~"clean"], &package_dir);
763-
assert!(!built_executable_in_workspace(&PkgId::new("foo", &package_dir),
764-
&tmp).map_default(false, |m| { os::path_exists(m) }));
765-
}
766-
767719
#[test]
768720
#[ignore (reason = "Un-ignore when #7071 is fixed")]
769721
fn rust_path_test() {
770722
let dir_for_path = mkdtemp(&os::tmpdir(), "more_rust").expect("rust_path_test failed");
771723
let dir = mk_workspace(&dir_for_path, &normalize(RemotePath(Path("foo"))), &NoVersion);
772724
debug!("dir = %s", dir.to_str());
773-
writeFile(&dir.push("main.rs"), "fn main() { let _x = (); }");
725+
writeFile(&Path("/Users/tjc/more_rust/src/foo-0.1/main.rs"),
726+
"fn main() { let _x = (); }");
774727
775728
let cwd = os::getcwd();
776729
debug!("cwd = %s", cwd.to_str());
@@ -828,24 +781,21 @@ fn test_list() {
828781
let quux = PkgId::new("quux", &dir);
829782
create_local_package_in(&quux, &dir);
830783
831-
// NOTE Not really great output, though...
832-
// NOTE do any tests need to be unignored?
833784
command_line_test([~"install", ~"foo"], &dir);
834785
let env_arg = ~[(~"RUST_PATH", dir.to_str())];
835-
debug!("RUST_PATH = %s", dir.to_str());
836786
let list_output = command_line_test_output_with_env([~"list"], env_arg.clone());
837-
assert!(list_output.iter().any(|x| x.starts_with("libfoo_")));
787+
assert!(list_output.iter().any(|x| x.starts_with("foo-")));
838788
839789
command_line_test([~"install", ~"bar"], &dir);
840790
let list_output = command_line_test_output_with_env([~"list"], env_arg.clone());
841-
assert!(list_output.iter().any(|x| x.starts_with("libfoo_")));
842-
assert!(list_output.iter().any(|x| x.starts_with("libbar_")));
791+
assert!(list_output.iter().any(|x| x.starts_with("foo-")));
792+
assert!(list_output.iter().any(|x| x.starts_with("bar-")));
843793
844794
command_line_test([~"install", ~"quux"], &dir);
845795
let list_output = command_line_test_output_with_env([~"list"], env_arg);
846-
assert!(list_output.iter().any(|x| x.starts_with("libfoo_")));
847-
assert!(list_output.iter().any(|x| x.starts_with("libbar_")));
848-
assert!(list_output.iter().any(|x| x.starts_with("libquux_")));
796+
assert!(list_output.iter().any(|x| x.starts_with("foo-")));
797+
assert!(list_output.iter().any(|x| x.starts_with("bar-")));
798+
assert!(list_output.iter().any(|x| x.starts_with("quux-")));
849799
}
850800
851801
#[test]
@@ -886,7 +836,7 @@ fn install_check_duplicates() {
886836
let mut contents = ~[];
887837
let check_dups = |p: &PkgId| {
888838
if contents.contains(p) {
889-
fail!("package %s appears in `list` output more than once", p.local_path.to_str());
839+
fail!("package database contains duplicate ID");
890840
}
891841
else {
892842
contents.push((*p).clone());

branches/try2/src/librustpkg/usage.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ Options:
2323
}
2424

2525
pub fn build() {
26-
io::println("rustpkg [options..] build [package-ID]
26+
io::println("rustpkg [options..] build
2727
28-
Build the given package ID if specified. With no package ID argument,
29-
build the package in the current directory. In that case, the current
30-
directory must be a direct child of an `src` directory in a workspace.
28+
Build all targets described in the package script in the current
29+
directory.
3130
3231
Options:
3332
-c, --cfg Pass a cfg flag to the package script");

0 commit comments

Comments
 (0)