Skip to content

Commit 5afc008

Browse files
authored
Merge pull request #90 from alexreg/cosmetic-2
Various cosmetic improvements
2 parents ded5704 + 0fe48c3 commit 5afc008

File tree

7 files changed

+48
-117
lines changed

7 files changed

+48
-117
lines changed

src/combiner.rs

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,48 @@
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-
111
use std::io::{Read, Write};
122
use std::path::Path;
3+
134
use flate2::read::GzDecoder;
145
use tar::Archive;
156

167
use crate::errors::*;
8+
use crate::util::*;
179
use super::Scripter;
1810
use super::Tarballer;
19-
use crate::util::*;
2011

2112
actor!{
2213
#[derive(Debug)]
2314
pub struct Combiner {
24-
/// The name of the product, for display
15+
/// The name of the product, for display.
2516
product_name: String = "Product",
2617

27-
/// The name of the package, tarball
18+
/// The name of the package tarball.
2819
package_name: String = "package",
2920

30-
/// The directory under lib/ where the manifest lives
21+
/// The directory under lib/ where the manifest lives.
3122
rel_manifest_dir: String = "packagelib",
3223

33-
/// The string to print after successful installation
24+
/// The string to print after successful installation.
3425
success_message: String = "Installed.",
3526

36-
/// Places to look for legacy manifests to uninstall
27+
/// Places to look for legacy manifests to uninstall.
3728
legacy_manifest_dirs: String = "",
3829

39-
/// Installers to combine
30+
/// Installers to combine.
4031
input_tarballs: String = "",
4132

42-
/// Directory containing files that should not be installed
33+
/// Directory containing files that should not be installed.
4334
non_installed_overlay: String = "",
4435

45-
/// The directory to do temporary work
36+
/// The directory to do temporary work.
4637
work_dir: String = "./workdir",
4738

48-
/// The location to put the final image and tarball
39+
/// The location to put the final image and tarball.
4940
output_dir: String = "./dist",
5041
}
5142
}
5243

5344
impl Combiner {
54-
/// Combine the installer tarballs
45+
/// Combines the installer tarballs.
5546
pub fn run(self) -> Result<()> {
5647
create_dir_all(&self.work_dir)?;
5748

@@ -61,7 +52,7 @@ impl Combiner {
6152
}
6253
create_dir_all(&package_dir)?;
6354

64-
// Merge each installer into the work directory of the new installer
55+
// Merge each installer into the work directory of the new installer.
6556
let components = create_new_file(package_dir.join("components"))?;
6657
for input_tarball in self.input_tarballs.split(',').map(str::trim).filter(|s| !s.is_empty()) {
6758
// Extract the input tarballs
@@ -74,7 +65,7 @@ impl Combiner {
7465
let pkg_name = Path::new(pkg_name).file_name().unwrap();
7566
let pkg_dir = Path::new(&self.work_dir).join(&pkg_name);
7667

77-
// Verify the version number
68+
// Verify the version number.
7869
let mut version = String::new();
7970
open_file(pkg_dir.join("rust-installer-version"))
8071
.and_then(|mut file| file.read_to_string(&mut version).map_err(Error::from))
@@ -83,37 +74,37 @@ impl Combiner {
8374
bail!("incorrect installer version in {}", input_tarball);
8475
}
8576

86-
// Copy components to the new combined installer
77+
// Copy components to the new combined installer.
8778
let mut pkg_components = String::new();
8879
open_file(pkg_dir.join("components"))
8980
.and_then(|mut file| file.read_to_string(&mut pkg_components).map_err(Error::from))
9081
.chain_err(|| format!("failed to read components in '{}'", input_tarball))?;
9182
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
9384
// move it, but rustbuild wants to reuse the unpacked package
9485
// dir for OS-specific installers on macOS and Windows.
9586
let component_dir = package_dir.join(&component);
9687
create_dir(&component_dir)?;
9788
copy_recursive(&pkg_dir.join(&component), &component_dir)?;
9889

99-
// Merge the component name
90+
// Merge the component name.
10091
writeln!(&components, "{}", component)
10192
.chain_err(|| "failed to write new components")?;
10293
}
10394
}
10495
drop(components);
10596

106-
// Write the installer version
97+
// Write the installer version.
10798
let version = package_dir.join("rust-installer-version");
10899
writeln!(create_new_file(version)?, "{}", crate::RUST_INSTALLER_VERSION)
109100
.chain_err(|| "failed to write new installer version")?;
110101

111-
// Copy the overlay
102+
// Copy the overlay.
112103
if !self.non_installed_overlay.is_empty() {
113104
copy_recursive(self.non_installed_overlay.as_ref(), &package_dir)?;
114105
}
115106

116-
// Generate the install script
107+
// Generate the install script.
117108
let output_script = package_dir.join("install.sh");
118109
let mut scripter = Scripter::default();
119110
scripter.product_name(self.product_name)
@@ -123,7 +114,7 @@ impl Combiner {
123114
.output_script(path_to_str(&output_script)?);
124115
scripter.run()?;
125116

126-
// Make the tarballs
117+
// Make the tarballs.
127118
create_dir_all(&self.output_dir)?;
128119
let output = Path::new(&self.output_dir).join(&self.package_name);
129120
let mut tarballer = Tarballer::default();

src/generator.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
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-
111
use std::io::Write;
122
use std::path::Path;
133

@@ -55,7 +45,7 @@ actor!{
5545
}
5646

5747
impl Generator {
58-
/// Generate the actual installer tarball
48+
/// Generates the actual installer tarball
5949
pub fn run(self) -> Result<()> {
6050
create_dir_all(&self.work_dir)?;
6151

src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
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-
111
#[macro_use]
122
extern crate error_chain;
133

src/remove_dir_all.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2014 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-
111
#![allow(non_snake_case)]
122

133
use std::path::Path;
@@ -67,7 +57,7 @@ mod win {
6757
// already need write permission in this dir to delete the directory. And it
6858
// should be on the same volume.
6959
//
70-
// To handle files with names like `CON` and `morse .. .`, and when a
60+
// To handle files with names like `CON` and `morse .. .`, and when a
7161
// directory structure is so deep it needs long path names the path is first
7262
// converted to a `//?/`-path with `get_path()`.
7363
//

src/scripter.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
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-
111
use std::io::Write;
122

133
use crate::errors::*;
@@ -37,14 +27,14 @@ actor!{
3727
}
3828

3929
impl Scripter {
40-
/// Generate the actual installer script
30+
/// Generates the actual installer script
4131
pub fn run(self) -> Result<()> {
4232
// Replace dashes in the success message with spaces (our arg handling botches spaces)
43-
// (TODO: still needed? kept for compatibility for now...)
33+
// TODO: still needed? Kept for compatibility for now.
4434
let product_name = self.product_name.replace('-', " ");
4535

4636
// Replace dashes in the success message with spaces (our arg handling botches spaces)
47-
// (TODO: still needed? kept for compatibility for now...)
37+
// TODO: still needed? Kept for compatibility for now.
4838
let success_message = self.success_message.replace('-', " ");
4939

5040
let script = TEMPLATE

src/tarballer.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
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-
111
use std::fs::{read_link, symlink_metadata};
122
use std::io::{self, empty, Write, BufWriter};
133
use std::path::Path;
@@ -25,24 +15,24 @@ use crate::util::*;
2515
actor!{
2616
#[derive(Debug)]
2717
pub struct Tarballer {
28-
/// The input folder to be compressed
18+
/// The input folder to be compressed.
2919
input: String = "package",
3020

31-
/// The prefix of the tarballs
21+
/// The prefix of the tarballs.
3222
output: String = "./dist",
3323

34-
/// The folder in which the input is to be found
24+
/// The folder in which the input is to be found.
3525
work_dir: String = "./workdir",
3626
}
3727
}
3828

3929
impl Tarballer {
40-
/// Generate the actual tarballs
30+
/// Generates the actual tarballs
4131
pub fn run(self) -> Result<()> {
4232
let tar_gz = self.output.clone() + ".tar.gz";
4333
let tar_xz = self.output.clone() + ".tar.xz";
4434

45-
// Remove any existing files
35+
// Remove any existing files.
4636
for file in &[&tar_gz, &tar_xz] {
4737
if Path::new(file).exists() {
4838
remove_file(file)?;
@@ -56,14 +46,14 @@ impl Tarballer {
5646
.chain_err(|| "failed to collect file paths")?;
5747
files.sort_by(|a, b| a.bytes().rev().cmp(b.bytes().rev()));
5848

59-
// Prepare the .tar.gz file
49+
// Prepare the `.tar.gz` file.
6050
let gz = GzEncoder::new(create_new_file(tar_gz)?, flate2::Compression::best());
6151

62-
// Prepare the .tar.xz file
52+
// Prepare the `.tar.xz` file.
6353
let xz = XzEncoder::new(create_new_file(tar_xz)?, 6);
6454

65-
// Write the tar into both encoded files. We write all directories
66-
// first, so files may be directly created. (see rustup.rs#1092)
55+
// Write the tar into both encoded files. We write all directories
56+
// first, so files may be directly created. (See rust-lang/rustup.rs#1092.)
6757
let tee = RayonTee(xz, gz);
6858
let buf = BufWriter::with_capacity(1024 * 1024, tee);
6959
let mut builder = Builder::new(buf);
@@ -84,7 +74,7 @@ impl Tarballer {
8474
.chain_err(|| "failed to finish writing .tar stream")?
8575
.into_inner().ok().unwrap();
8676

87-
// Finish both encoded files
77+
// Finish both encoded files.
8878
let (rxz, rgz) = rayon::join(
8979
|| xz.finish().chain_err(|| "failed to finish .tar.xz file"),
9080
|| gz.finish().chain_err(|| "failed to finish .tar.gz file"),
@@ -120,7 +110,7 @@ fn append_path<W: Write>(builder: &mut Builder<W>, src: &Path, path: &String) ->
120110
Ok(())
121111
}
122112

123-
/// Returns all `(directories, files)` under the source path
113+
/// Returns all `(directories, files)` under the source path.
124114
fn get_recursive_paths<P, Q>(root: P, name: Q) -> Result<(Vec<String>, Vec<String>)>
125115
where P: AsRef<Path>, Q: AsRef<Path>
126116
{

0 commit comments

Comments
 (0)