@@ -1324,7 +1324,7 @@ impl Build {
1324
1324
match & self . config . channel [ ..] {
1325
1325
"stable" => num. to_string ( ) ,
1326
1326
"beta" => {
1327
- if self . rust_info ( ) . is_managed_git_subrepository ( ) && !self . config . omit_git_hash {
1327
+ if !self . config . omit_git_hash {
1328
1328
format ! ( "{}-beta.{}" , num, self . beta_prerelease_version( ) )
1329
1329
} else {
1330
1330
format ! ( "{}-beta" , num)
@@ -1336,18 +1336,28 @@ impl Build {
1336
1336
}
1337
1337
1338
1338
fn beta_prerelease_version ( & self ) -> u32 {
1339
+ fn extract_beta_rev_from_file < P : AsRef < Path > > ( version_file : P ) -> Option < String > {
1340
+ let version = fs:: read_to_string ( version_file) . ok ( ) ?;
1341
+
1342
+ extract_beta_rev ( & version)
1343
+ }
1344
+
1339
1345
if let Some ( s) = self . prerelease_version . get ( ) {
1340
1346
return s;
1341
1347
}
1342
1348
1343
- // Figure out how many merge commits happened since we branched off master.
1344
- // That's our beta number!
1345
- // (Note that we use a `..` range, not the `...` symmetric difference.)
1346
- let count =
1349
+ // First check if there is a version file available.
1350
+ // If available, we read the beta revision from that file.
1351
+ // This only happens when building from a source tarball when Git should not be used.
1352
+ let count = extract_beta_rev_from_file ( self . src . join ( "version" ) ) . unwrap_or_else ( || {
1353
+ // Figure out how many merge commits happened since we branched off master.
1354
+ // That's our beta number!
1355
+ // (Note that we use a `..` range, not the `...` symmetric difference.)
1347
1356
output ( self . config . git ( ) . arg ( "rev-list" ) . arg ( "--count" ) . arg ( "--merges" ) . arg ( format ! (
1348
1357
"refs/remotes/origin/{}..HEAD" ,
1349
1358
self . config. stage0_metadata. config. nightly_branch
1350
- ) ) ) ;
1359
+ ) ) )
1360
+ } ) ;
1351
1361
let n = count. trim ( ) . parse ( ) . unwrap ( ) ;
1352
1362
self . prerelease_version . set ( Some ( n) ) ;
1353
1363
n
@@ -1707,6 +1717,17 @@ to download LLVM rather than building it.
1707
1717
}
1708
1718
}
1709
1719
1720
+ /// Extract the beta revision from the full version string.
1721
+ ///
1722
+ /// The full version string looks like "a.b.c-beta.y". And we need to extract
1723
+ /// the "y" part from the string.
1724
+ pub fn extract_beta_rev ( version : & str ) -> Option < String > {
1725
+ let parts = version. splitn ( 2 , "-beta." ) . collect :: < Vec < _ > > ( ) ;
1726
+ let count = parts. get ( 1 ) . and_then ( |s| s. find ( ' ' ) . map ( |p| ( & s[ ..p] ) . to_string ( ) ) ) ;
1727
+
1728
+ count
1729
+ }
1730
+
1710
1731
#[ cfg( unix) ]
1711
1732
fn chmod ( path : & Path , perms : u32 ) {
1712
1733
use std:: os:: unix:: fs:: * ;
0 commit comments