4
4
//! via `x.py dist hash-and-sign`; the cmdline arguments are set up
5
5
//! by rustbuild (in `src/bootstrap/dist.rs`).
6
6
7
- use serde :: Serialize ;
7
+ mod versions ;
8
8
9
+ use crate :: versions:: { PkgType , Versions } ;
10
+ use serde:: Serialize ;
9
11
use std:: collections:: BTreeMap ;
10
12
use std:: collections:: HashMap ;
11
13
use std:: env;
@@ -226,14 +228,7 @@ macro_rules! t {
226
228
}
227
229
228
230
struct Builder {
229
- rust_release : String ,
230
- cargo_release : String ,
231
- rls_release : String ,
232
- rust_analyzer_release : String ,
233
- clippy_release : String ,
234
- rustfmt_release : String ,
235
- llvm_tools_release : String ,
236
- miri_release : String ,
231
+ versions : Versions ,
237
232
238
233
input : PathBuf ,
239
234
output : PathBuf ,
@@ -242,24 +237,6 @@ struct Builder {
242
237
s3_address : String ,
243
238
date : String ,
244
239
245
- rust_version : Option < String > ,
246
- cargo_version : Option < String > ,
247
- rls_version : Option < String > ,
248
- rust_analyzer_version : Option < String > ,
249
- clippy_version : Option < String > ,
250
- rustfmt_version : Option < String > ,
251
- llvm_tools_version : Option < String > ,
252
- miri_version : Option < String > ,
253
-
254
- rust_git_commit_hash : Option < String > ,
255
- cargo_git_commit_hash : Option < String > ,
256
- rls_git_commit_hash : Option < String > ,
257
- rust_analyzer_git_commit_hash : Option < String > ,
258
- clippy_git_commit_hash : Option < String > ,
259
- rustfmt_git_commit_hash : Option < String > ,
260
- llvm_tools_git_commit_hash : Option < String > ,
261
- miri_git_commit_hash : Option < String > ,
262
-
263
240
should_sign : bool ,
264
241
}
265
242
@@ -280,15 +257,9 @@ fn main() {
280
257
let input = PathBuf :: from ( args. next ( ) . unwrap ( ) ) ;
281
258
let output = PathBuf :: from ( args. next ( ) . unwrap ( ) ) ;
282
259
let date = args. next ( ) . unwrap ( ) ;
283
- let rust_release = args. next ( ) . unwrap ( ) ;
284
260
let s3_address = args. next ( ) . unwrap ( ) ;
285
- let cargo_release = args. next ( ) . unwrap ( ) ;
286
- let rls_release = args. next ( ) . unwrap ( ) ;
287
- let rust_analyzer_release = args. next ( ) . unwrap ( ) ;
288
- let clippy_release = args. next ( ) . unwrap ( ) ;
289
- let miri_release = args. next ( ) . unwrap ( ) ;
290
- let rustfmt_release = args. next ( ) . unwrap ( ) ;
291
- let llvm_tools_release = args. next ( ) . unwrap ( ) ;
261
+ let channel = args. next ( ) . unwrap ( ) ;
262
+ let monorepo_path = args. next ( ) . unwrap ( ) ;
292
263
293
264
// Do not ask for a passphrase while manually testing
294
265
let mut passphrase = String :: new ( ) ;
@@ -298,14 +269,7 @@ fn main() {
298
269
}
299
270
300
271
Builder {
301
- rust_release,
302
- cargo_release,
303
- rls_release,
304
- rust_analyzer_release,
305
- clippy_release,
306
- rustfmt_release,
307
- llvm_tools_release,
308
- miri_release,
272
+ versions : Versions :: new ( & channel, & input, Path :: new ( & monorepo_path) ) . unwrap ( ) ,
309
273
310
274
input,
311
275
output,
@@ -314,87 +278,21 @@ fn main() {
314
278
s3_address,
315
279
date,
316
280
317
- rust_version : None ,
318
- cargo_version : None ,
319
- rls_version : None ,
320
- rust_analyzer_version : None ,
321
- clippy_version : None ,
322
- rustfmt_version : None ,
323
- llvm_tools_version : None ,
324
- miri_version : None ,
325
-
326
- rust_git_commit_hash : None ,
327
- cargo_git_commit_hash : None ,
328
- rls_git_commit_hash : None ,
329
- rust_analyzer_git_commit_hash : None ,
330
- clippy_git_commit_hash : None ,
331
- rustfmt_git_commit_hash : None ,
332
- llvm_tools_git_commit_hash : None ,
333
- miri_git_commit_hash : None ,
334
-
335
281
should_sign,
336
282
}
337
283
. build ( ) ;
338
284
}
339
285
340
- enum PkgType {
341
- RustSrc ,
342
- Cargo ,
343
- Rls ,
344
- RustAnalyzer ,
345
- Clippy ,
346
- Rustfmt ,
347
- LlvmTools ,
348
- Miri ,
349
- Other ,
350
- }
351
-
352
- impl PkgType {
353
- fn from_component ( component : & str ) -> Self {
354
- use PkgType :: * ;
355
- match component {
356
- "rust-src" => RustSrc ,
357
- "cargo" => Cargo ,
358
- "rls" | "rls-preview" => Rls ,
359
- "rust-analyzer" | "rust-analyzer-preview" => RustAnalyzer ,
360
- "clippy" | "clippy-preview" => Clippy ,
361
- "rustfmt" | "rustfmt-preview" => Rustfmt ,
362
- "llvm-tools" | "llvm-tools-preview" => LlvmTools ,
363
- "miri" | "miri-preview" => Miri ,
364
- _ => Other ,
365
- }
366
- }
367
- }
368
-
369
286
impl Builder {
370
287
fn build ( & mut self ) {
371
- self . rust_version = self . version ( "rust" , "x86_64-unknown-linux-gnu" ) ;
372
- self . cargo_version = self . version ( "cargo" , "x86_64-unknown-linux-gnu" ) ;
373
- self . rls_version = self . version ( "rls" , "x86_64-unknown-linux-gnu" ) ;
374
- self . rust_analyzer_version = self . version ( "rust-analyzer" , "x86_64-unknown-linux-gnu" ) ;
375
- self . clippy_version = self . version ( "clippy" , "x86_64-unknown-linux-gnu" ) ;
376
- self . rustfmt_version = self . version ( "rustfmt" , "x86_64-unknown-linux-gnu" ) ;
377
- self . llvm_tools_version = self . version ( "llvm-tools" , "x86_64-unknown-linux-gnu" ) ;
378
- self . miri_version = self . version ( "miri" , "x86_64-unknown-linux-gnu" ) ;
379
-
380
- self . rust_git_commit_hash = self . git_commit_hash ( "rust" , "x86_64-unknown-linux-gnu" ) ;
381
- self . cargo_git_commit_hash = self . git_commit_hash ( "cargo" , "x86_64-unknown-linux-gnu" ) ;
382
- self . rls_git_commit_hash = self . git_commit_hash ( "rls" , "x86_64-unknown-linux-gnu" ) ;
383
- self . rust_analyzer_git_commit_hash =
384
- self . git_commit_hash ( "rust-analyzer" , "x86_64-unknown-linux-gnu" ) ;
385
- self . clippy_git_commit_hash = self . git_commit_hash ( "clippy" , "x86_64-unknown-linux-gnu" ) ;
386
- self . rustfmt_git_commit_hash = self . git_commit_hash ( "rustfmt" , "x86_64-unknown-linux-gnu" ) ;
387
- self . llvm_tools_git_commit_hash =
388
- self . git_commit_hash ( "llvm-tools" , "x86_64-unknown-linux-gnu" ) ;
389
- self . miri_git_commit_hash = self . git_commit_hash ( "miri" , "x86_64-unknown-linux-gnu" ) ;
390
-
391
288
self . check_toolstate ( ) ;
392
289
self . digest_and_sign ( ) ;
393
290
let manifest = self . build_manifest ( ) ;
394
- self . write_channel_files ( & self . rust_release , & manifest) ;
395
291
396
- if self . rust_release != "beta" && self . rust_release != "nightly" {
397
- self . write_channel_files ( "stable" , & manifest) ;
292
+ let rust_version = self . versions . package_version ( & PkgType :: Rust ) . unwrap ( ) ;
293
+ self . write_channel_files ( self . versions . channel ( ) , & manifest) ;
294
+ if self . versions . channel ( ) != rust_version {
295
+ self . write_channel_files ( & rust_version, & manifest) ;
398
296
}
399
297
}
400
298
@@ -415,8 +313,7 @@ impl Builder {
415
313
// Mark some tools as missing based on toolstate.
416
314
if toolstates. get ( "miri" ) . map ( |s| & * s as & str ) != Some ( "test-pass" ) {
417
315
println ! ( "Miri tests are not passing, removing component" ) ;
418
- self . miri_version = None ;
419
- self . miri_git_commit_hash = None ;
316
+ self . versions . disable_version ( & PkgType :: Miri ) ;
420
317
}
421
318
}
422
319
@@ -501,7 +398,7 @@ impl Builder {
501
398
// The compiler libraries are not stable for end users, and they're also huge, so we only
502
399
// `rustc-dev` for nightly users, and only in the "complete" profile. It's still possible
503
400
// for users to install the additional component manually, if needed.
504
- if self . rust_release == "nightly" {
401
+ if self . versions . channel ( ) == "nightly" {
505
402
self . extend_profile ( "complete" , & mut manifest. profiles , & [ "rustc-dev" ] ) ;
506
403
self . extend_profile ( "complete" , & mut manifest. profiles , & [ "rustc-docs" ] ) ;
507
404
}
@@ -518,13 +415,10 @@ impl Builder {
518
415
}
519
416
520
417
fn rust_package ( & mut self , manifest : & Manifest ) -> Package {
418
+ let version_info = self . versions . version ( & PkgType :: Rust ) . expect ( "missing Rust tarball" ) ;
521
419
let mut pkg = Package {
522
- version : self
523
- . cached_version ( "rust" )
524
- . as_ref ( )
525
- . expect ( "Couldn't find Rust version" )
526
- . clone ( ) ,
527
- git_commit_hash : self . cached_git_commit_hash ( "rust" ) . clone ( ) ,
420
+ version : version_info. version . expect ( "missing Rust version" ) ,
421
+ git_commit_hash : version_info. git_commit ,
528
422
target : BTreeMap :: new ( ) ,
529
423
} ;
530
424
for host in HOSTS {
@@ -539,7 +433,7 @@ impl Builder {
539
433
}
540
434
541
435
fn target_host_combination ( & mut self , host : & str , manifest : & Manifest ) -> Option < Target > {
542
- let filename = self . filename ( "rust" , host) ;
436
+ let filename = self . versions . tarball_name ( & PkgType :: Rust , host) . unwrap ( ) ;
543
437
let digest = self . digests . remove ( & filename) ?;
544
438
let xz_filename = filename. replace ( ".tar.gz" , ".tar.xz" ) ;
545
439
let xz_digest = self . digests . remove ( & xz_filename) ;
@@ -630,15 +524,14 @@ impl Builder {
630
524
}
631
525
632
526
fn package ( & mut self , pkgname : & str , dst : & mut BTreeMap < String , Package > , targets : & [ & str ] ) {
633
- let ( version, mut is_present) = self
634
- . cached_version ( pkgname)
635
- . as_ref ( )
636
- . cloned ( )
637
- . map ( |version| ( version, true ) )
638
- . unwrap_or_default ( ) ; // `is_present` defaults to `false` here.
527
+ let version_info = self
528
+ . versions
529
+ . version ( & PkgType :: from_component ( pkgname) )
530
+ . expect ( "failed to load package version" ) ;
531
+ let mut is_present = version_info. present ;
639
532
640
533
// Never ship nightly-only components for other trains.
641
- if self . rust_release != "nightly" && NIGHTLY_ONLY_COMPONENTS . contains ( & pkgname) {
534
+ if self . versions . channel ( ) != "nightly" && NIGHTLY_ONLY_COMPONENTS . contains ( & pkgname) {
642
535
is_present = false ; // Pretend the component is entirely missing.
643
536
}
644
537
@@ -647,7 +540,10 @@ impl Builder {
647
540
. map ( |name| {
648
541
if is_present {
649
542
// The component generally exists, but it might still be missing for this target.
650
- let filename = self . filename ( pkgname, name) ;
543
+ let filename = self
544
+ . versions
545
+ . tarball_name ( & PkgType :: from_component ( pkgname) , name)
546
+ . unwrap ( ) ;
651
547
let digest = match self . digests . remove ( & filename) {
652
548
Some ( digest) => digest,
653
549
// This component does not exist for this target -- skip it.
@@ -679,8 +575,8 @@ impl Builder {
679
575
dst. insert (
680
576
pkgname. to_string ( ) ,
681
577
Package {
682
- version,
683
- git_commit_hash : self . cached_git_commit_hash ( pkgname ) . clone ( ) ,
578
+ version : version_info . version . unwrap_or_default ( ) ,
579
+ git_commit_hash : version_info . git_commit ,
684
580
target : targets,
685
581
} ,
686
582
) ;
@@ -690,77 +586,6 @@ impl Builder {
690
586
format ! ( "{}/{}/{}" , self . s3_address, self . date, filename)
691
587
}
692
588
693
- fn filename ( & self , component : & str , target : & str ) -> String {
694
- use PkgType :: * ;
695
- match PkgType :: from_component ( component) {
696
- RustSrc => format ! ( "rust-src-{}.tar.gz" , self . rust_release) ,
697
- Cargo => format ! ( "cargo-{}-{}.tar.gz" , self . cargo_release, target) ,
698
- Rls => format ! ( "rls-{}-{}.tar.gz" , self . rls_release, target) ,
699
- RustAnalyzer => {
700
- format ! ( "rust-analyzer-{}-{}.tar.gz" , self . rust_analyzer_release, target)
701
- }
702
- Clippy => format ! ( "clippy-{}-{}.tar.gz" , self . clippy_release, target) ,
703
- Rustfmt => format ! ( "rustfmt-{}-{}.tar.gz" , self . rustfmt_release, target) ,
704
- LlvmTools => format ! ( "llvm-tools-{}-{}.tar.gz" , self . llvm_tools_release, target) ,
705
- Miri => format ! ( "miri-{}-{}.tar.gz" , self . miri_release, target) ,
706
- Other => format ! ( "{}-{}-{}.tar.gz" , component, self . rust_release, target) ,
707
- }
708
- }
709
-
710
- fn cached_version ( & self , component : & str ) -> & Option < String > {
711
- use PkgType :: * ;
712
- match PkgType :: from_component ( component) {
713
- Cargo => & self . cargo_version ,
714
- Rls => & self . rls_version ,
715
- RustAnalyzer => & self . rust_analyzer_version ,
716
- Clippy => & self . clippy_version ,
717
- Rustfmt => & self . rustfmt_version ,
718
- LlvmTools => & self . llvm_tools_version ,
719
- Miri => & self . miri_version ,
720
- _ => & self . rust_version ,
721
- }
722
- }
723
-
724
- fn cached_git_commit_hash ( & self , component : & str ) -> & Option < String > {
725
- use PkgType :: * ;
726
- match PkgType :: from_component ( component) {
727
- Cargo => & self . cargo_git_commit_hash ,
728
- Rls => & self . rls_git_commit_hash ,
729
- RustAnalyzer => & self . rust_analyzer_git_commit_hash ,
730
- Clippy => & self . clippy_git_commit_hash ,
731
- Rustfmt => & self . rustfmt_git_commit_hash ,
732
- LlvmTools => & self . llvm_tools_git_commit_hash ,
733
- Miri => & self . miri_git_commit_hash ,
734
- _ => & self . rust_git_commit_hash ,
735
- }
736
- }
737
-
738
- fn version ( & self , component : & str , target : & str ) -> Option < String > {
739
- self . untar ( component, target, |filename| format ! ( "{}/version" , filename) )
740
- }
741
-
742
- fn git_commit_hash ( & self , component : & str , target : & str ) -> Option < String > {
743
- self . untar ( component, target, |filename| format ! ( "{}/git-commit-hash" , filename) )
744
- }
745
-
746
- fn untar < F > ( & self , component : & str , target : & str , dir : F ) -> Option < String >
747
- where
748
- F : FnOnce ( String ) -> String ,
749
- {
750
- let mut cmd = Command :: new ( "tar" ) ;
751
- let filename = self . filename ( component, target) ;
752
- cmd. arg ( "xf" )
753
- . arg ( self . input . join ( & filename) )
754
- . arg ( dir ( filename. replace ( ".tar.gz" , "" ) ) )
755
- . arg ( "-O" ) ;
756
- let output = t ! ( cmd. output( ) ) ;
757
- if output. status . success ( ) {
758
- Some ( String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) )
759
- } else {
760
- None
761
- }
762
- }
763
-
764
589
fn hash ( & self , path : & Path ) -> String {
765
590
let sha = t ! ( Command :: new( "shasum" )
766
591
. arg( "-a" )
0 commit comments