@@ -11,6 +11,7 @@ use std::ffi::OsStr;
1111use std:: fs;
1212use std:: io;
1313use std:: path:: { Path , PathBuf } ;
14+ use std:: str:: FromStr ;
1415
1516use crate :: builder:: { Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
1617use crate :: cache:: { Interned , INTERNER } ;
@@ -400,6 +401,18 @@ impl Step for Standalone {
400401 }
401402}
402403
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+
403416#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
404417pub struct Std {
405418 pub stage : u32 ,
@@ -430,10 +443,12 @@ impl Step for Std {
430443 t ! ( fs:: create_dir_all( & out) ) ;
431444 t ! ( fs:: copy( builder. src. join( "src/doc/rust.css" ) , out. join( "rust.css" ) ) ) ;
432445
446+ let version = get_doc_max_version ( & builder) ;
447+
433448 let content = t ! ( fs:: read_to_string( builder. src. join( "src/doc/version-switcher.js" ) ) ) ;
434449 t ! ( fs:: write(
435450 out. join( "version-switcher.js" ) ,
436- content. replace( "/* VERSION TO BE REPLACED */" , & builder . version) ,
451+ content. replace( "/* VERSION TO BE REPLACED */" , & version) ,
437452 ) ) ;
438453
439454 let index_page = builder. src . join ( "src/doc/index.md" ) . into_os_string ( ) ;
0 commit comments