@@ -11,6 +11,7 @@ use std::ffi::OsStr;
11
11
use std:: fs;
12
12
use std:: io;
13
13
use std:: path:: { Path , PathBuf } ;
14
+ use std:: str:: FromStr ;
14
15
15
16
use crate :: builder:: { Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
16
17
use crate :: cache:: { Interned , INTERNER } ;
@@ -400,6 +401,18 @@ impl Step for Standalone {
400
401
}
401
402
}
402
403
404
+ fn get_doc_max_version ( builder : & Builder < ' _ > ) -> String {
405
+ let reduce_by = match builder. config . channel . as_str ( ) {
406
+ "dev" => 3 ,
407
+ "nightly" => 2 ,
408
+ "beta" => 1 ,
409
+ _ => 0 ,
410
+ } ;
411
+ let parts = builder. version . split ( "." ) . collect :: < Vec < _ > > ( ) ;
412
+ let medium = t ! ( u32 :: from_str( parts[ 1 ] ) ) ;
413
+ format ! ( "{}.{}.{}" , parts[ 0 ] , medium - reduce_by, parts[ 2 ..] . join( "." ) )
414
+ }
415
+
403
416
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
404
417
pub struct Std {
405
418
pub stage : u32 ,
@@ -430,10 +443,12 @@ impl Step for Std {
430
443
t ! ( fs:: create_dir_all( & out) ) ;
431
444
t ! ( fs:: copy( builder. src. join( "src/doc/rust.css" ) , out. join( "rust.css" ) ) ) ;
432
445
446
+ let version = get_doc_max_version ( & builder) ;
447
+
433
448
let content = t ! ( fs:: read_to_string( builder. src. join( "src/doc/version-switcher.js" ) ) ) ;
434
449
t ! ( fs:: write(
435
450
out. join( "version-switcher.js" ) ,
436
- content. replace( "/* VERSION TO BE REPLACED */" , & builder . version) ,
451
+ content. replace( "/* VERSION TO BE REPLACED */" , & version) ,
437
452
) ) ;
438
453
439
454
let index_page = builder. src . join ( "src/doc/index.md" ) . into_os_string ( ) ;
0 commit comments