Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cosmetic improvements #90

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions src/combiner.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,48 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::io::{Read, Write};
use std::path::Path;

use flate2::read::GzDecoder;
use tar::Archive;

use crate::errors::*;
use crate::util::*;
use super::Scripter;
use super::Tarballer;
use crate::util::*;

actor!{
#[derive(Debug)]
pub struct Combiner {
/// The name of the product, for display
/// The name of the product, for display.
product_name: String = "Product",

/// The name of the package, tarball
/// The name of the package tarball.
package_name: String = "package",

/// The directory under lib/ where the manifest lives
/// The directory under lib/ where the manifest lives.
rel_manifest_dir: String = "packagelib",

/// The string to print after successful installation
/// The string to print after successful installation.
success_message: String = "Installed.",

/// Places to look for legacy manifests to uninstall
/// Places to look for legacy manifests to uninstall.
legacy_manifest_dirs: String = "",

/// Installers to combine
/// Installers to combine.
input_tarballs: String = "",

/// Directory containing files that should not be installed
/// Directory containing files that should not be installed.
non_installed_overlay: String = "",

/// The directory to do temporary work
/// The directory to do temporary work.
work_dir: String = "./workdir",

/// The location to put the final image and tarball
/// The location to put the final image and tarball.
output_dir: String = "./dist",
}
}

impl Combiner {
/// Combine the installer tarballs
/// Combines the installer tarballs.
pub fn run(self) -> Result<()> {
create_dir_all(&self.work_dir)?;

Expand All @@ -61,7 +52,7 @@ impl Combiner {
}
create_dir_all(&package_dir)?;

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

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

// Copy components to the new combined installer
// Copy components to the new combined installer.
let mut pkg_components = String::new();
open_file(pkg_dir.join("components"))
.and_then(|mut file| file.read_to_string(&mut pkg_components).map_err(Error::from))
.chain_err(|| format!("failed to read components in '{}'", input_tarball))?;
for component in pkg_components.split_whitespace() {
// All we need to do is copy the component directory. We could
// All we need to do is copy the component directory. We could
// move it, but rustbuild wants to reuse the unpacked package
// dir for OS-specific installers on macOS and Windows.
let component_dir = package_dir.join(&component);
create_dir(&component_dir)?;
copy_recursive(&pkg_dir.join(&component), &component_dir)?;

// Merge the component name
// Merge the component name.
writeln!(&components, "{}", component)
.chain_err(|| "failed to write new components")?;
}
}
drop(components);

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

// Copy the overlay
// Copy the overlay.
if !self.non_installed_overlay.is_empty() {
copy_recursive(self.non_installed_overlay.as_ref(), &package_dir)?;
}

// Generate the install script
// Generate the install script.
let output_script = package_dir.join("install.sh");
let mut scripter = Scripter::default();
scripter.product_name(self.product_name)
Expand All @@ -123,7 +114,7 @@ impl Combiner {
.output_script(path_to_str(&output_script)?);
scripter.run()?;

// Make the tarballs
// Make the tarballs.
create_dir_all(&self.output_dir)?;
let output = Path::new(&self.output_dir).join(&self.package_name);
let mut tarballer = Tarballer::default();
Expand Down
12 changes: 1 addition & 11 deletions src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::io::Write;
use std::path::Path;

Expand Down Expand Up @@ -55,7 +45,7 @@ actor!{
}

impl Generator {
/// Generate the actual installer tarball
/// Generates the actual installer tarball
pub fn run(self) -> Result<()> {
create_dir_all(&self.work_dir)?;

Expand Down
10 changes: 0 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use]
extern crate error_chain;

Expand Down
12 changes: 1 addition & 11 deletions src/remove_dir_all.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(non_snake_case)]

use std::path::Path;
Expand Down Expand Up @@ -67,7 +57,7 @@ mod win {
// already need write permission in this dir to delete the directory. And it
// should be on the same volume.
//
// To handle files with names like `CON` and `morse .. .`, and when a
// To handle files with names like `CON` and `morse .. .`, and when a
// directory structure is so deep it needs long path names the path is first
// converted to a `//?/`-path with `get_path()`.
//
Expand Down
16 changes: 3 additions & 13 deletions src/scripter.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::io::Write;

use crate::errors::*;
Expand Down Expand Up @@ -37,14 +27,14 @@ actor!{
}

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

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

let script = TEMPLATE
Expand Down
32 changes: 11 additions & 21 deletions src/tarballer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::fs::{read_link, symlink_metadata};
use std::io::{self, empty, Write, BufWriter};
use std::path::Path;
Expand All @@ -25,24 +15,24 @@ use crate::util::*;
actor!{
#[derive(Debug)]
pub struct Tarballer {
/// The input folder to be compressed
/// The input folder to be compressed.
input: String = "package",

/// The prefix of the tarballs
/// The prefix of the tarballs.
output: String = "./dist",

/// The folder in which the input is to be found
/// The folder in which the input is to be found.
work_dir: String = "./workdir",
}
}

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

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

// Prepare the .tar.gz file
// Prepare the `.tar.gz` file.
let gz = GzEncoder::new(create_new_file(tar_gz)?, flate2::Compression::best());

// Prepare the .tar.xz file
// Prepare the `.tar.xz` file.
let xz = XzEncoder::new(create_new_file(tar_xz)?, 6);

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

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

/// Returns all `(directories, files)` under the source path
/// Returns all `(directories, files)` under the source path.
fn get_recursive_paths<P, Q>(root: P, name: Q) -> Result<(Vec<String>, Vec<String>)>
where P: AsRef<Path>, Q: AsRef<Path>
{
Expand Down
Loading