@@ -26,10 +26,11 @@ tag _src {
26
26
}
27
27
28
28
type package = {
29
- source: _src,
29
+ // source: _src,
30
30
name: str ,
31
31
uuid: str,
32
- url: str
32
+ url: str,
33
+ method: str
33
34
} ;
34
35
35
36
type source = {
@@ -64,6 +65,10 @@ fn warn(msg: str) {
64
65
io:: stdout ( ) . write_line ( "warning: " + msg) ;
65
66
}
66
67
68
+ fn error ( msg : str ) {
69
+ io:: stdout ( ) . write_line ( "error: " + msg) ;
70
+ }
71
+
67
72
fn load_link ( mis : [ @ast:: meta_item ] ) -> ( option:: t < str > ,
68
73
option:: t < str > ,
69
74
option:: t < str > ) {
@@ -179,7 +184,7 @@ fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
179
184
}
180
185
}
181
186
182
- fn load_one_source_package ( c : cargo , src : source , p : map:: hashmap < str , json:: json > ) {
187
+ fn load_one_source_package ( & c: cargo , & src: source , p : map:: hashmap < str , json:: json > ) {
183
188
let name = alt p. find ( "name" ) {
184
189
some ( json:: string ( _n) ) { _n }
185
190
_ {
@@ -204,16 +209,25 @@ fn load_one_source_package(c: cargo, src: source, p: map::hashmap<str, json::jso
204
209
}
205
210
} ;
206
211
212
+ let method = alt p. find ( "method" ) {
213
+ some ( json:: string ( _n) ) { _n }
214
+ _ {
215
+ warn( "Malformed source json: " + src. name + " (missing method)" ) ;
216
+ ret;
217
+ }
218
+ } ;
219
+
207
220
vec:: grow ( src. packages , 1 u, {
208
- source: _source ( src) ,
221
+ // source: _source(src),
209
222
name: name,
210
223
uuid: uuid,
211
- url: url
224
+ url: url,
225
+ method: method
212
226
} ) ;
213
227
info ( " Loaded package: " + src. name + "/" + name) ;
214
228
}
215
229
216
- fn load_source_packages ( c : cargo , src : source ) {
230
+ fn load_source_packages ( & c: cargo , & src: source ) {
217
231
info ( "Loading source: " + src. name ) ;
218
232
let dir = fs:: connect ( c. sourcedir , src. name ) ;
219
233
let pkgfile = fs:: connect ( dir, "packages.json" ) ;
@@ -229,7 +243,6 @@ fn load_source_packages(c: cargo, src: source) {
229
243
}
230
244
_ {
231
245
warn( "Malformed source json: " + src. name + " (non-dict pkg)" ) ;
232
- ret;
233
246
}
234
247
}
235
248
}
@@ -269,17 +282,19 @@ fn configure() -> cargo {
269
282
need_dir ( c. libdir ) ;
270
283
need_dir ( c. bindir ) ;
271
284
272
- sources. values { |v|
273
- load_source_packages ( c, v) ;
285
+ sources. keys { |k|
286
+ let s = sources. get ( k) ;
287
+ load_source_packages ( c, s) ;
288
+ sources. insert ( k, s) ;
274
289
} ;
275
290
276
291
c
277
292
}
278
293
279
- fn for_each_package ( c : cargo , b : block ( package ) ) {
294
+ fn for_each_package ( c : cargo , b : block ( source , package ) ) {
280
295
c. sources . values ( { |v|
281
296
for p in v. packages {
282
- b ( p) ;
297
+ b ( v , p) ;
283
298
}
284
299
} )
285
300
}
@@ -335,14 +350,25 @@ fn install_source(c: cargo, path: str) {
335
350
}
336
351
}
337
352
338
- fn install_git ( c : cargo , wd : str , _path : str ) {
339
- run:: run_program ( "git" , [ "clone" , _path , wd] ) ;
353
+ fn install_git ( c : cargo , wd : str , url : str ) {
354
+ run:: run_program ( "git" , [ "clone" , url , wd] ) ;
340
355
install_source ( c, wd) ;
341
356
}
342
357
343
- fn install_file ( c : cargo , wd : str , _path : str ) {
358
+ fn install_curl ( c : cargo , wd : str , url : str ) {
359
+ let tarpath = fs:: connect ( wd, "pkg.tar" ) ;
360
+ let p = run:: program_output ( "curl" , [ "-f" , "-s" , "-o" ,
361
+ tarpath, url] ) ;
362
+ if p. status != 0 {
363
+ fail #fmt[ "Fetch of %s failed: %s" , url, p. err ] ;
364
+ }
344
365
run:: run_program ( "tar" , [ "-x" , "--strip-components=1" ,
345
- "-C" , wd, "-f" , _path] ) ;
366
+ "-C" , wd, "-f" , tarpath] ) ;
367
+ }
368
+
369
+ fn install_file ( c : cargo , wd : str , path : str ) {
370
+ run:: run_program ( "tar" , [ "-x" , "--strip-components=1" ,
371
+ "-C" , wd, "-f" , path] ) ;
346
372
install_source ( c, wd) ;
347
373
}
348
374
@@ -368,30 +394,90 @@ fn install_resolved(c: cargo, wd: str, key: str) {
368
394
}
369
395
}
370
396
397
+ fn install_package ( c : cargo , wd : str , pkg : package ) {
398
+ info ( "Installing with " + pkg. method + " from " + pkg. url + "..." ) ;
399
+ if pkg. method == "git" {
400
+ install_git ( c, wd, pkg. url ) ;
401
+ } else if pkg. method == "http" {
402
+ install_curl ( c, wd, pkg. url ) ;
403
+ } else if pkg. method == "file" {
404
+ install_file ( c, wd, pkg. url ) ;
405
+ }
406
+ }
407
+
371
408
fn install_uuid ( c : cargo , wd : str , uuid : str ) {
372
409
let ps = [ ] ;
373
- for_each_package ( c, { |p|
410
+ for_each_package ( c, { |s, p|
411
+ info ( #fmt[ "%s ? %s" , p. uuid , uuid] ) ;
374
412
if p. uuid == uuid {
375
- vec:: grow ( ps, 1 u, p ) ;
413
+ vec:: grow ( ps, 1 u, ( s , p ) ) ;
376
414
}
377
415
} ) ;
378
- info ( "Found:" ) ;
379
- for p in ps {
380
- info ( " " + p. source . name + "/" + p. name ) ;
416
+ if vec:: len ( ps) == 1 u {
417
+ let ( s, p) = ps[ 0 ] ;
418
+ install_package ( c, wd, p) ;
419
+ ret;
420
+ } else if vec:: len ( ps) == 0 u {
421
+ error ( "No packages." ) ;
422
+ ret;
423
+ }
424
+ error ( "Found multiple packages:" ) ;
425
+ for ( s, p) in ps {
426
+ info ( " " + s. name + "/" + p. uuid + " (" + p. name + ")" ) ;
381
427
}
382
428
}
383
429
384
430
fn install_named ( c : cargo , wd : str , name : str ) {
385
431
let ps = [ ] ;
386
- for_each_package ( c, { |p|
432
+ for_each_package ( c, { |s , p|
387
433
if p. name == name {
388
- vec:: grow ( ps, 1 u, p ) ;
434
+ vec:: grow ( ps, 1 u, ( s , p ) ) ;
389
435
}
390
436
} ) ;
391
- info ( "Found:" ) ;
392
- for p in ps {
393
- info ( " " + p. source . name + "/" + p. name ) ;
437
+ if vec:: len ( ps) == 1 u {
438
+ let ( s, p) = ps[ 0 ] ;
439
+ install_package ( c, wd, p) ;
440
+ ret;
441
+ } else if vec:: len ( ps) == 0 u {
442
+ error ( "No packages." ) ;
443
+ ret;
444
+ }
445
+ error ( "Found multiple packages:" ) ;
446
+ for ( s, p) in ps {
447
+ info ( " " + s. name + "/" + p. uuid + " (" + p. name + ")" ) ;
448
+ }
449
+ }
450
+
451
+ fn install_uuid_specific ( c : cargo , wd : str , src : str , uuid : str ) {
452
+ alt c. sources . find ( src) {
453
+ some ( s) {
454
+ if vec:: any ( s. packages , { |p|
455
+ if p. uuid == uuid {
456
+ install_package ( c, wd, p) ;
457
+ ret true;
458
+ }
459
+ ret false;
460
+ } ) { ret; }
461
+ }
462
+ _ { }
394
463
}
464
+ error ( "Can't find package " + src + "/" + uuid) ;
465
+ }
466
+
467
+ fn install_named_specific ( c : cargo , wd : str , src : str , name : str ) {
468
+ alt c. sources . find ( src) {
469
+ some ( s) {
470
+ if vec:: any ( s. packages , { |p|
471
+ if p. name == name {
472
+ install_package ( c, wd, p) ;
473
+ ret true;
474
+ }
475
+ ret false;
476
+ } ) { ret; }
477
+ }
478
+ _ { }
479
+ }
480
+ error ( "Can't find package " + src + "/" + name) ;
395
481
}
396
482
397
483
fn cmd_install ( c : cargo , argv : [ str ] ) {
@@ -406,19 +492,26 @@ fn cmd_install(c: cargo, argv: [str]) {
406
492
none. { fail "needed temp dir" ; }
407
493
} ;
408
494
409
- if str:: starts_with ( argv[ 2 ] , "git:" ) {
410
- install_git ( c, wd, argv[ 2 ] ) ;
411
- } else if str:: starts_with ( argv[ 2 ] , "github:" ) {
412
- let path = rest ( argv[ 2 ] , 7 u) ;
413
- install_git ( c, wd, "git://github.com/" + path) ;
414
- } else if str:: starts_with ( argv[ 2 ] , "file:" ) {
415
- let path = rest ( argv[ 2 ] , 5 u) ;
416
- install_file ( c, wd, path) ;
417
- } else if str:: starts_with ( argv[ 2 ] , "uuid:" ) {
495
+ if str:: starts_with ( argv[ 2 ] , "uuid:" ) {
418
496
let uuid = rest ( argv[ 2 ] , 5 u) ;
419
- install_uuid ( c, wd, uuid) ;
497
+ let idx = str:: index ( uuid, '/' as u8 ) ;
498
+ if idx != -1 {
499
+ let source = str:: slice ( uuid, 0 u, idx as uint ) ;
500
+ uuid = str:: slice ( uuid, idx as uint + 1 u, str:: byte_len ( uuid) ) ;
501
+ install_uuid_specific ( c, wd, source, uuid) ;
502
+ } else {
503
+ install_uuid ( c, wd, uuid) ;
504
+ }
420
505
} else {
421
- install_named ( c, wd, argv[ 2 ] ) ;
506
+ let name = argv[ 2 ] ;
507
+ let idx = str:: index ( name, '/' as u8 ) ;
508
+ if idx != -1 {
509
+ let source = str:: slice ( name, 0 u, idx as uint ) ;
510
+ name = str:: slice ( name, idx as uint + 1 u, str:: byte_len ( name) ) ;
511
+ install_named_specific ( c, wd, source, name) ;
512
+ } else {
513
+ install_named ( c, wd, name) ;
514
+ }
422
515
}
423
516
}
424
517
@@ -427,6 +520,7 @@ fn sync_one(c: cargo, name: str, src: source) {
427
520
let pkgfile = fs:: connect ( dir, "packages.json" ) ;
428
521
let url = src. url ;
429
522
need_dir ( dir) ;
523
+ info ( #fmt[ "fetching source %s..." , name] ) ;
430
524
let p = run:: program_output ( "curl" , [ "-f" , "-s" , "-o" , pkgfile, url] ) ;
431
525
if p. status != 0 {
432
526
warn ( #fmt[ "fetch for source %s (url %s) failed" , name, url] ) ;
0 commit comments