@@ -331,6 +331,100 @@ impl DocBuilder {
331
331
package. manifest( ) . version( ) ) ) ;
332
332
add_path_into_database ( conn, & prefix, crate_doc_path)
333
333
}
334
+
335
+
336
+ /// This function will build an empty crate and will add essential documentation files.
337
+ ///
338
+ /// It is required to run after every rustc update. cratesfyi is not keeping this files
339
+ /// for every crate to avoid duplications.
340
+ ///
341
+ /// List of the files:
342
+ ///
343
+ /// * rustdoc.css (with rustc version)
344
+ /// * main.css (with rustc version)
345
+ /// * main.js (with rustc version)
346
+ /// * jquery.js (with rustc version)
347
+ /// * playpen.js (with rustc version)
348
+ /// * normalize.css
349
+ /// * FiraSans-Medium.woff
350
+ /// * FiraSans-Regular.woff
351
+ /// * Heuristica-Italic.woff
352
+ /// * SourceCodePro-Regular.woff
353
+ /// * SourceCodePro-Semibold.woff
354
+ /// * SourceSerifPro-Bold.woff
355
+ /// * SourceSerifPro-Regular.woff
356
+ pub fn add_essential_files ( & self ) -> Result < ( ) , DocBuilderError > {
357
+ use std:: fs:: { copy, create_dir_all} ;
358
+
359
+ // acme-client-0.0.0 is an empty library crate and it will always build
360
+ let pkg = try!( get_package ( "acme-client" , Some ( "=0.0.0" ) ) ) ;
361
+ let res = self . build_package_in_chroot ( & pkg) ;
362
+ let rustc_version = parse_rustc_version ( & res. rustc_version ) ;
363
+
364
+ if !res. build_success {
365
+ return Err ( DocBuilderError :: GenericError ( format ! ( "Failed to build empty crate for: {}" ,
366
+ res. rustc_version) ) ) ;
367
+ }
368
+
369
+ info ! ( "Copying essential files for: {}" , res. rustc_version) ;
370
+
371
+ let files = (
372
+ // files require rustc version subfix
373
+ [ "rustdoc.css" ,
374
+ "main.css" ,
375
+ "main.js" ,
376
+ "jquery.js" ,
377
+ "playpen.js" ] ,
378
+ // files doesn't require rustc version subfix
379
+ [ "normalize.css" ,
380
+ "FiraSans-Medium.woff" ,
381
+ "normalize.css" ,
382
+ "FiraSans-Medium.woff" ,
383
+ "FiraSans-Regular.woff" ,
384
+ "Heuristica-Italic.woff" ,
385
+ "SourceCodePro-Regular.woff" ,
386
+ "SourceCodePro-Semibold.woff" ,
387
+ "SourceSerifPro-Bold.woff" ,
388
+ "SourceSerifPro-Regular.woff" ,
389
+ ] ,
390
+ ) ;
391
+
392
+ let source = PathBuf :: from ( & self . options . chroot_path )
393
+ . join ( "home" )
394
+ . join ( & self . options . chroot_user )
395
+ . join ( canonical_name ( & pkg) )
396
+ . join ( "doc" ) ;
397
+
398
+ // use copy_documentation destination directory so self.clean can remove it when
399
+ // we are done
400
+ let destination = PathBuf :: from ( & self . options . destination )
401
+ . join ( format ! ( "{}/{}" ,
402
+ pkg. manifest( ) . name( ) ,
403
+ pkg. manifest( ) . version( ) ) ) ;
404
+ try!( create_dir_all ( & destination) ) ;
405
+
406
+ for file in files. 0 . iter ( ) {
407
+ let source_path = source. join ( file) ;
408
+ let destination_path = {
409
+ let spl: Vec < & str > = file. split ( '.' ) . collect ( ) ;
410
+ destination. join ( format ! ( "{}-{}.{}" , spl[ 0 ] , rustc_version, spl[ 1 ] ) )
411
+ } ;
412
+ try!( copy ( source_path, destination_path) ) ;
413
+ }
414
+
415
+ for file in files. 1 . iter ( ) {
416
+ let source_path = source. join ( file) ;
417
+ let destination_path = destination. join ( file) ;
418
+ try!( copy ( source_path, destination_path) ) ;
419
+ }
420
+
421
+ let conn = try!( connect_db ( ) ) ;
422
+ try!( add_path_into_database ( & conn, "" , destination) ) ;
423
+
424
+ try!( self . clean ( & pkg) ) ;
425
+
426
+ Ok ( ( ) )
427
+ }
334
428
}
335
429
336
430
@@ -416,4 +510,14 @@ mod test {
416
510
assert_eq ! ( parse_rustc_version( "cratesfyi 0.2.0 (ba9ae23 2016-05-26)" ) ,
417
511
"20160526-0.2.0-ba9ae23" ) ;
418
512
}
513
+
514
+ #[ test]
515
+ #[ ignore]
516
+ fn test_add_essential_files ( ) {
517
+ let _ = env_logger:: init ( ) ;
518
+ let options = DocBuilderOptions :: from_prefix ( PathBuf :: from ( "../cratesfyi-prefix" ) ) ;
519
+ let docbuilder = DocBuilder :: new ( options) ;
520
+
521
+ docbuilder. add_essential_files ( ) . unwrap ( ) ;
522
+ }
419
523
}
0 commit comments