@@ -33,7 +33,6 @@ use core::hashmap::HashMap;
33
33
use core::io::WriterUtil;
34
34
use rustc::driver::{driver, session};
35
35
use rustc::metadata::filesearch;
36
- use std::net::url;
37
36
use std::{getopts};
38
37
use syntax::{ast, diagnostic};
39
38
use util::*;
@@ -244,16 +243,21 @@ impl Ctx {
244
243
src.build(&dst_dir, cfgs);
245
244
}
246
245
~"clean" => {
247
- self.clean();
246
+ if args.len() < 1 {
247
+ return usage::build();
248
+ }
249
+ // The package id is presumed to be the first command-line
250
+ // argument
251
+ let pkgid = PkgId::new(args[0]);
252
+
253
+ self.clean(pkgid);
248
254
}
249
255
~"do" => {
250
256
if args.len() < 2 {
251
257
return usage::do_cmd();
252
258
}
253
259
254
- if !self.do_cmd(args[0], args[1]) {
255
- fail!(~"a command failed!");
256
- }
260
+ self.do_cmd(args[0], args[1]);
257
261
}
258
262
~"info" => {
259
263
self.info();
@@ -298,12 +302,11 @@ impl Ctx {
298
302
}
299
303
}
300
304
301
- fn do_cmd(&self, cmd: ~str, pkgname: ~str) -> bool {
305
+ fn do_cmd(&self, cmd: ~str, pkgname: ~str) {
302
306
match cmd {
303
307
~"build" | ~"test" => {
304
308
util::error(~"that command cannot be manually called");
305
-
306
- return false;
309
+ fail!(~"do_cmd");
307
310
}
308
311
_ => {}
309
312
}
@@ -319,16 +322,15 @@ impl Ctx {
319
322
Some(script_path) => {
320
323
let script = PkgScript::parse(script_path, pkgid);
321
324
let (_, status) = script.run_custom(cmd); // Ignore cfgs?
322
- if status == 42 { // ???
325
+ if status == 42 {
323
326
util::error(~"no fns are listening for that cmd");
324
- return false ;
327
+ fail!(~"do_cmd") ;
325
328
}
326
- status == 0
327
329
}
328
330
None => {
329
331
util::error(fmt!("invoked `do`, but there is no package script in %s",
330
332
cwd.to_str()));
331
- false
333
+ fail!(~"do_cmd");
332
334
}
333
335
}
334
336
}
@@ -341,128 +343,44 @@ impl Ctx {
341
343
}
342
344
343
345
fn compile(&self, _crate: &Path, _dir: &Path, _flags: ~[~str],
344
- _cfgs: ~[~str], _opt: bool, _test: bool) -> bool {
346
+ _cfgs: ~[~str], _opt: bool, _test: bool) {
345
347
// What's the difference between build and compile?
346
348
fail!(~"compile not yet implemented");
347
349
}
348
350
349
- fn clean(&self) -> bool {
350
- // stub
351
- fail!();
351
+ fn clean(&self, id: PkgId) {
352
+ // Could also support a custom build hook in the pkg
353
+ // script for cleaning files rustpkg doesn't know about.
354
+ // Do something reasonable for now
355
+
356
+ let dir = dest_dir(id);
357
+ util::note(fmt!("Cleaning package %s (removing directory %s)",
358
+ id.to_str(), dir.to_str()));
359
+ if os::path_exists(&dir) {
360
+ util::remove_dir_r(&dir);
361
+ util::note(fmt!("Removed directory %s", dir.to_str()));
362
+ }
363
+
364
+ util::note(fmt!("Cleaned package %s", id.to_str()));
352
365
}
353
366
354
367
fn info(&self) {
355
368
// stub
356
- fail!();
369
+ fail!(~"info not yet implemented" );
357
370
}
358
371
359
- fn install(&self, url: Option<~str>,
360
- target: Option<~str>, cache: bool) -> bool {
361
- let dir = match url {
362
- None => {
363
- util::note(~"installing from the cwd");
364
- os::getcwd()
365
- }
366
- Some(url) => {
367
- let hash = util::hash(if !target.is_none() {
368
- url + target.get()
369
- }
370
- else { url });
371
-
372
- if self.dep_cache.contains_key(&hash) {
373
- util::warn(~"already installed dep this run");
374
- return true;
375
- }
376
-
377
- self.dep_cache.insert(hash, true);
378
-
379
- let dir = util::root().push(~"tmp").push(hash);
380
-
381
- if cache && os::path_exists(&dir) {
382
- return true;
383
- }
384
-
385
- if !self.fetch(&dir, url, target) {
386
- return false;
387
- }
388
- dir
389
- }
390
- };
391
-
392
- let script = match self.build(&dir, false, true, false) {
393
- Some(script) => script,
394
- None => {
395
- return false;
396
- }
397
- };
398
- let work_dir = script.build_dir;
399
- let from_bin_dir = work_dir.push(~"bin");
400
- let from_lib_dir = work_dir.push(~"lib");
401
- let to_bin_dir = util::root().push(~"bin");
402
- let to_lib_dir = util::root().push(~"lib");
403
- let mut bins = ~[];
404
- let mut libs = ~[];
405
-
406
- for os::walk_dir(&from_bin_dir) |bin| {
407
- let to = to_bin_dir.push_rel(&bin.file_path());
408
-
409
- os::copy_file(bin, &to);
410
- bins.push(to.to_str());
411
- }
412
-
413
- for os::walk_dir(&from_lib_dir) |lib| {
414
- let to = to_lib_dir.push_rel(&lib.file_path());
415
-
416
- os::copy_file(lib, &to);
417
- libs.push(to.to_str());
418
- }
419
-
420
- let package = Pkg {
421
- id: script.id,
422
- bins: bins,
423
- libs: libs
424
- };
425
-
426
- util::note(fmt!("installed %s", script.id.to_str()));
427
- util::add_pkg(&package);
428
-
429
- true
372
+ fn install(&self, _url: Option<~str>,
373
+ _target: Option<~str>, _cache: bool) {
374
+ // stub
375
+ fail!(~"install not yet implemented");
430
376
}
431
377
432
- fn fetch(&self, dir: &Path, url: ~str, target: Option<~str>) -> bool {
433
- let url = if str::find_str(url, "://").is_none() {
434
- ~"http://" + url }
435
- else { url };
436
- let url = match url::from_str(url) {
437
- result::Ok(url) => url,
438
- result::Err(err) => {
439
- util::error(fmt!("failed parsing %s", err.to_lower()));
440
-
441
- return false;
442
- }
443
- };
444
- let str = url.to_str();
445
-
446
- match Path(url.path).filetype() {
447
- Some(ext) => {
448
- if ext == ~".git" {
449
- return self.fetch_git(dir, str, target);
450
- }
451
- }
452
- None => {}
453
- }
454
-
455
- match url.scheme {
456
- ~"git" => self.fetch_git(dir, str, target),
457
- ~"http" | ~"ftp" | ~"file" => self.fetch_curl(dir, str),
458
- _ => {
459
- util::warn(~"unknown url scheme to fetch, using curl");
460
- self.fetch_curl(dir, str)
461
- }
462
- }
378
+ fn fetch(&self, _dir: &Path, _url: ~str, _target: Option<~str>) {
379
+ // stub
380
+ fail!(~"fetch not yet implemented");
463
381
}
464
382
465
- fn fetch_curl(&self, dir: &Path, url: ~str) -> bool {
383
+ fn fetch_curl(&self, dir: &Path, url: ~str) {
466
384
util::note(fmt!("fetching from %s using curl", url));
467
385
468
386
let tar = dir.dir_path().push(&dir.file_path().to_str() + ~".tar");
@@ -472,7 +390,7 @@ impl Ctx {
472
390
url]).status != 0 {
473
391
util::error(~"fetching failed: downloading using curl failed");
474
392
475
- return false ;
393
+ fail!() ;
476
394
}
477
395
478
396
if run::program_output(~"tar", ~[~"-x", ~"--strip-components=1",
@@ -481,13 +399,11 @@ impl Ctx {
481
399
util::error(~"fetching failed: extracting using tar failed" +
482
400
~"(is it a valid tar archive?)");
483
401
484
- return false ;
402
+ fail!() ;
485
403
}
486
-
487
- true
488
404
}
489
405
490
- fn fetch_git(&self, dir: &Path, url: ~str, target: Option<~str>) -> bool {
406
+ fn fetch_git(&self, dir: &Path, url: ~str, target: Option<~str>) {
491
407
util::note(fmt!("fetching from %s using git", url));
492
408
493
409
// Git can't clone into a non-empty directory
@@ -496,8 +412,7 @@ impl Ctx {
496
412
if run::program_output(~"git", ~[~"clone", url,
497
413
dir.to_str()]).status != 0 {
498
414
util::error(~"fetching failed: can't clone repository");
499
-
500
- return false;
415
+ fail!();
501
416
}
502
417
503
418
if !target.is_none() {
@@ -511,21 +426,17 @@ impl Ctx {
511
426
512
427
if !success {
513
428
util::error(~"fetching failed: can't checkout target");
514
-
515
- return false;
429
+ fail!();
516
430
}
517
431
}
518
-
519
- true
520
432
}
521
433
522
- fn prefer(&self, id: ~str, vers: Option<~str>) -> bool {
434
+ fn prefer(&self, id: ~str, vers: Option<~str>) {
523
435
let package = match util::get_pkg(id, vers) {
524
436
result::Ok(package) => package,
525
437
result::Err(err) => {
526
438
util::error(err);
527
-
528
- return false;
439
+ fail!(); // Condition?
529
440
}
530
441
};
531
442
let name = package.id.path.to_str(); // ???
@@ -548,29 +459,18 @@ impl Ctx {
548
459
}
549
460
550
461
util::note(fmt!("preferred %s v%s", name, package.id.version.to_str()));
551
-
552
- true
553
462
}
554
463
555
- fn test(&self) -> bool {
556
- let script = match self.build(&os::getcwd(), false, false, true) {
557
- Some(script) => script,
558
- None => {
559
- return false;
560
- }
561
- };
562
-
563
- // To do
564
- util::note(fmt!("Would test %s, but this is a dry run",
565
- script.id.to_str()));
566
- false
464
+ fn test(&self) {
465
+ // stub
466
+ fail!(~"test not yet implemented");
567
467
}
568
468
569
- fn uninstall(&self, _id: ~str, _vers: Option<~str>) -> bool {
469
+ fn uninstall(&self, _id: ~str, _vers: Option<~str>) {
570
470
fail!(~"uninstall not yet implemented");
571
471
}
572
472
573
- fn unprefer(&self, _id: ~str, _vers: Option<~str>) -> bool {
473
+ fn unprefer(&self, _id: ~str, _vers: Option<~str>) {
574
474
fail!(~"unprefer not yet implemented");
575
475
}
576
476
}
@@ -839,14 +739,19 @@ impl PkgSrc {
839
739
prefix, pth),
840
740
Some(~"bench.rs") => push_crate(&mut self.benchs,
841
741
prefix, pth),
842
- _ => {
843
- util::note(~"Couldn't infer any crates to build.\n\
844
- Try naming a crate `main.rs`, `lib.rs`, \
845
- `test.rs`, or `bench.rs`.");
846
- fail!(~"Failed to infer crates to build");
847
- }
742
+ _ => ()
848
743
}
849
744
}
745
+
746
+ if self.libs.is_empty() && self.mains.is_empty()
747
+ && self.tests.is_empty() && self.benchs.is_empty() {
748
+
749
+ util::note(~"Couldn't infer any crates to build.\n\
750
+ Try naming a crate `main.rs`, `lib.rs`, \
751
+ `test.rs`, or `bench.rs`.");
752
+ fail!(~"Failed to infer crates to build");
753
+ }
754
+
850
755
debug!("found %u libs, %u mains, %u tests, %u benchs",
851
756
self.libs.len(),
852
757
self.mains.len(),
0 commit comments