1
- // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2
- // file at the top-level directory of this distribution and at
3
- // http://rust-lang.org/COPYRIGHT.
4
- //
5
- // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
- // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
- // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
- // option. This file may not be copied, modified, or distributed
9
- // except according to those terms.
10
-
11
1
use std:: io:: { Read , Write } ;
12
2
use std:: path:: Path ;
3
+
13
4
use flate2:: read:: GzDecoder ;
14
5
use tar:: Archive ;
15
6
16
7
use crate :: errors:: * ;
8
+ use crate :: util:: * ;
17
9
use super :: Scripter ;
18
10
use super :: Tarballer ;
19
- use crate :: util:: * ;
20
11
21
12
actor ! {
22
13
#[ derive( Debug ) ]
23
14
pub struct Combiner {
24
- /// The name of the product, for display
15
+ /// The name of the product, for display.
25
16
product_name: String = "Product" ,
26
17
27
- /// The name of the package, tarball
18
+ /// The name of the package tarball.
28
19
package_name: String = "package" ,
29
20
30
- /// The directory under lib/ where the manifest lives
21
+ /// The directory under lib/ where the manifest lives.
31
22
rel_manifest_dir: String = "packagelib" ,
32
23
33
- /// The string to print after successful installation
24
+ /// The string to print after successful installation.
34
25
success_message: String = "Installed." ,
35
26
36
- /// Places to look for legacy manifests to uninstall
27
+ /// Places to look for legacy manifests to uninstall.
37
28
legacy_manifest_dirs: String = "" ,
38
29
39
- /// Installers to combine
30
+ /// Installers to combine.
40
31
input_tarballs: String = "" ,
41
32
42
- /// Directory containing files that should not be installed
33
+ /// Directory containing files that should not be installed.
43
34
non_installed_overlay: String = "" ,
44
35
45
- /// The directory to do temporary work
36
+ /// The directory to do temporary work.
46
37
work_dir: String = "./workdir" ,
47
38
48
- /// The location to put the final image and tarball
39
+ /// The location to put the final image and tarball.
49
40
output_dir: String = "./dist" ,
50
41
}
51
42
}
52
43
53
44
impl Combiner {
54
- /// Combine the installer tarballs
45
+ /// Combines the installer tarballs.
55
46
pub fn run ( self ) -> Result < ( ) > {
56
47
create_dir_all ( & self . work_dir ) ?;
57
48
@@ -61,7 +52,7 @@ impl Combiner {
61
52
}
62
53
create_dir_all ( & package_dir) ?;
63
54
64
- // Merge each installer into the work directory of the new installer
55
+ // Merge each installer into the work directory of the new installer.
65
56
let components = create_new_file ( package_dir. join ( "components" ) ) ?;
66
57
for input_tarball in self . input_tarballs . split ( ',' ) . map ( str:: trim) . filter ( |s| !s. is_empty ( ) ) {
67
58
// Extract the input tarballs
@@ -74,7 +65,7 @@ impl Combiner {
74
65
let pkg_name = Path :: new ( pkg_name) . file_name ( ) . unwrap ( ) ;
75
66
let pkg_dir = Path :: new ( & self . work_dir ) . join ( & pkg_name) ;
76
67
77
- // Verify the version number
68
+ // Verify the version number.
78
69
let mut version = String :: new ( ) ;
79
70
open_file ( pkg_dir. join ( "rust-installer-version" ) )
80
71
. and_then ( |mut file| file. read_to_string ( & mut version) . map_err ( Error :: from) )
@@ -83,37 +74,37 @@ impl Combiner {
83
74
bail ! ( "incorrect installer version in {}" , input_tarball) ;
84
75
}
85
76
86
- // Copy components to the new combined installer
77
+ // Copy components to the new combined installer.
87
78
let mut pkg_components = String :: new ( ) ;
88
79
open_file ( pkg_dir. join ( "components" ) )
89
80
. and_then ( |mut file| file. read_to_string ( & mut pkg_components) . map_err ( Error :: from) )
90
81
. chain_err ( || format ! ( "failed to read components in '{}'" , input_tarball) ) ?;
91
82
for component in pkg_components. split_whitespace ( ) {
92
- // All we need to do is copy the component directory. We could
83
+ // All we need to do is copy the component directory. We could
93
84
// move it, but rustbuild wants to reuse the unpacked package
94
85
// dir for OS-specific installers on macOS and Windows.
95
86
let component_dir = package_dir. join ( & component) ;
96
87
create_dir ( & component_dir) ?;
97
88
copy_recursive ( & pkg_dir. join ( & component) , & component_dir) ?;
98
89
99
- // Merge the component name
90
+ // Merge the component name.
100
91
writeln ! ( & components, "{}" , component)
101
92
. chain_err ( || "failed to write new components" ) ?;
102
93
}
103
94
}
104
95
drop ( components) ;
105
96
106
- // Write the installer version
97
+ // Write the installer version.
107
98
let version = package_dir. join ( "rust-installer-version" ) ;
108
99
writeln ! ( create_new_file( version) ?, "{}" , crate :: RUST_INSTALLER_VERSION )
109
100
. chain_err ( || "failed to write new installer version" ) ?;
110
101
111
- // Copy the overlay
102
+ // Copy the overlay.
112
103
if !self . non_installed_overlay . is_empty ( ) {
113
104
copy_recursive ( self . non_installed_overlay . as_ref ( ) , & package_dir) ?;
114
105
}
115
106
116
- // Generate the install script
107
+ // Generate the install script.
117
108
let output_script = package_dir. join ( "install.sh" ) ;
118
109
let mut scripter = Scripter :: default ( ) ;
119
110
scripter. product_name ( self . product_name )
@@ -123,7 +114,7 @@ impl Combiner {
123
114
. output_script ( path_to_str ( & output_script) ?) ;
124
115
scripter. run ( ) ?;
125
116
126
- // Make the tarballs
117
+ // Make the tarballs.
127
118
create_dir_all ( & self . output_dir ) ?;
128
119
let output = Path :: new ( & self . output_dir ) . join ( & self . package_name ) ;
129
120
let mut tarballer = Tarballer :: default ( ) ;
0 commit comments