From f3d9248c222aea421ebf463cabcec893d7a773f4 Mon Sep 17 00:00:00 2001 From: klensy Date: Fri, 23 Jun 2023 10:34:06 +0300 Subject: [PATCH] rust-installer and rls no longer submodule, so fix rustfmt.toml --- rustfmt.toml | 4 +-- src/tools/rust-installer/src/combiner.rs | 25 +++++-------------- src/tools/rust-installer/src/generator.rs | 30 +++++------------------ src/tools/rust-installer/src/main.rs | 8 ++++-- src/tools/rust-installer/src/scripter.rs | 5 +--- src/tools/rust-installer/src/tarballer.rs | 11 ++------- src/tools/rust-installer/src/util.rs | 17 ++++++------- 7 files changed, 31 insertions(+), 69 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 597ef5b9052..88700779e87 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -16,6 +16,8 @@ ignore = [ "tests", # do not format submodules + # FIXME: sync submodule list with tidy/bootstrap/etc + # tidy/src/walk.rs:filter_dirs "library/backtrace", "library/portable-simd", "library/stdarch", @@ -31,10 +33,8 @@ ignore = [ "src/tools/cargo", "src/tools/clippy", "src/tools/miri", - "src/tools/rls", "src/tools/rust-analyzer", "src/tools/rustfmt", - "src/tools/rust-installer", # these are ignored by a standard cargo fmt run "compiler/rustc_codegen_cranelift/y.rs", # running rustfmt breaks this file diff --git a/src/tools/rust-installer/src/combiner.rs b/src/tools/rust-installer/src/combiner.rs index 19466f63fed..565d19d863f 100644 --- a/src/tools/rust-installer/src/combiner.rs +++ b/src/tools/rust-installer/src/combiner.rs @@ -71,25 +71,16 @@ impl Combiner { // 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()) + for input_tarball in self.input_tarballs.split(',').map(str::trim).filter(|s| !s.is_empty()) { // Extract the input tarballs let compression = CompressionFormat::detect_from_path(input_tarball).ok_or_else(|| { anyhow::anyhow!("couldn't figure out the format of {}", input_tarball) })?; - Archive::new(compression.decode(input_tarball)?) - .unpack(&self.work_dir) - .with_context(|| { - format!( - "unable to extract '{}' into '{}'", - &input_tarball, self.work_dir - ) - })?; + Archive::new(compression.decode(input_tarball)?).unpack(&self.work_dir).with_context( + || format!("unable to extract '{}' into '{}'", &input_tarball, self.work_dir), + )?; let pkg_name = input_tarball.trim_end_matches(&format!(".tar.{}", compression.extension())); @@ -126,12 +117,8 @@ impl Combiner { // Write the installer version. let version = package_dir.join("rust-installer-version"); - writeln!( - create_new_file(version)?, - "{}", - crate::RUST_INSTALLER_VERSION - ) - .context("failed to write new installer version")?; + writeln!(create_new_file(version)?, "{}", crate::RUST_INSTALLER_VERSION) + .context("failed to write new installer version")?; // Copy the overlay. if !self.non_installed_overlay.is_empty() { diff --git a/src/tools/rust-installer/src/generator.rs b/src/tools/rust-installer/src/generator.rs index 45f8c49d03e..b101e67d8df 100644 --- a/src/tools/rust-installer/src/generator.rs +++ b/src/tools/rust-installer/src/generator.rs @@ -86,12 +86,8 @@ impl Generator { // Write the installer version (only used by combine-installers.sh) let version = package_dir.join("rust-installer-version"); - writeln!( - create_new_file(version)?, - "{}", - crate::RUST_INSTALLER_VERSION - ) - .context("failed to write new installer version")?; + writeln!(create_new_file(version)?, "{}", crate::RUST_INSTALLER_VERSION) + .context("failed to write new installer version")?; // Copy the overlay if !self.non_installed_overlay.is_empty() { @@ -128,33 +124,19 @@ impl Generator { /// Copies the `src` directory recursively to `dst`, writing `manifest.in` too. fn copy_and_manifest(src: &Path, dst: &Path, bulk_dirs: &str) -> Result<()> { let mut manifest = create_new_file(dst.join("manifest.in"))?; - let bulk_dirs: Vec<_> = bulk_dirs - .split(',') - .filter(|s| !s.is_empty()) - .map(Path::new) - .collect(); + let bulk_dirs: Vec<_> = bulk_dirs.split(',').filter(|s| !s.is_empty()).map(Path::new).collect(); let mut paths = BTreeSet::new(); copy_with_callback(src, dst, |path, file_type| { // We need paths to be compatible with both Unix and Windows. - if path - .components() - .filter_map(|c| c.as_os_str().to_str()) - .any(|s| s.contains('\\')) - { - bail!( - "rust-installer doesn't support '\\' in path components: {:?}", - path - ); + if path.components().filter_map(|c| c.as_os_str().to_str()).any(|s| s.contains('\\')) { + bail!("rust-installer doesn't support '\\' in path components: {:?}", path); } // Normalize to Unix-style path separators. let normalized_string; let mut string = path.to_str().ok_or_else(|| { - format_err!( - "rust-installer doesn't support non-Unicode paths: {:?}", - path - ) + format_err!("rust-installer doesn't support non-Unicode paths: {:?}", path) })?; if string.contains('\\') { normalized_string = string.replace('\\', "/"); diff --git a/src/tools/rust-installer/src/main.rs b/src/tools/rust-installer/src/main.rs index be8a0d68343..99acecdd43c 100644 --- a/src/tools/rust-installer/src/main.rs +++ b/src/tools/rust-installer/src/main.rs @@ -19,8 +19,12 @@ fn main() -> Result<()> { let command_line = CommandLine::parse(); match command_line.command { Subcommand::Combine(combiner) => combiner.run().context("failed to combine installers")?, - Subcommand::Generate(generator) => generator.run().context("failed to generate installer")?, - Subcommand::Script(scripter) => scripter.run().context("failed to generate installation script")?, + Subcommand::Generate(generator) => { + generator.run().context("failed to generate installer")? + } + Subcommand::Script(scripter) => { + scripter.run().context("failed to generate installation script")? + } Subcommand::Tarball(tarballer) => tarballer.run().context("failed to generate tarballs")?, } Ok(()) diff --git a/src/tools/rust-installer/src/scripter.rs b/src/tools/rust-installer/src/scripter.rs index 8180f925cb0..3ce2d68c8bd 100644 --- a/src/tools/rust-installer/src/scripter.rs +++ b/src/tools/rust-installer/src/scripter.rs @@ -44,10 +44,7 @@ impl Scripter { .replace("%%TEMPLATE_PRODUCT_NAME%%", &sh_quote(&product_name)) .replace("%%TEMPLATE_REL_MANIFEST_DIR%%", &self.rel_manifest_dir) .replace("%%TEMPLATE_SUCCESS_MESSAGE%%", &sh_quote(&success_message)) - .replace( - "%%TEMPLATE_LEGACY_MANIFEST_DIRS%%", - &sh_quote(&self.legacy_manifest_dirs), - ) + .replace("%%TEMPLATE_LEGACY_MANIFEST_DIRS%%", &sh_quote(&self.legacy_manifest_dirs)) .replace( "%%TEMPLATE_RUST_INSTALLER_VERSION%%", &sh_quote(&crate::RUST_INSTALLER_VERSION), diff --git a/src/tools/rust-installer/src/tarballer.rs b/src/tools/rust-installer/src/tarballer.rs index c60d5f648ff..7572dc6dcf8 100644 --- a/src/tools/rust-installer/src/tarballer.rs +++ b/src/tools/rust-installer/src/tarballer.rs @@ -58,10 +58,7 @@ impl Tarballer { let buf = BufWriter::with_capacity(1024 * 1024, encoder); let mut builder = Builder::new(buf); - let pool = rayon::ThreadPoolBuilder::new() - .num_threads(2) - .build() - .unwrap(); + let pool = rayon::ThreadPoolBuilder::new().num_threads(2).build().unwrap(); pool.install(move || { for path in dirs { let src = Path::new(&self.work_dir).join(&path); @@ -122,11 +119,7 @@ where let name = name.as_ref(); if !name.is_relative() && !name.starts_with(root) { - bail!( - "input '{}' is not in work dir '{}'", - name.display(), - root.display() - ); + bail!("input '{}' is not in work dir '{}'", name.display(), root.display()); } let mut dirs = vec![]; diff --git a/src/tools/rust-installer/src/util.rs b/src/tools/rust-installer/src/util.rs index 4eb2e75fd7e..47ca0cfa3cc 100644 --- a/src/tools/rust-installer/src/util.rs +++ b/src/tools/rust-installer/src/util.rs @@ -15,8 +15,7 @@ use std::os::windows::fs::symlink_file; /// Converts a `&Path` to a UTF-8 `&str`. pub fn path_to_str(path: &Path) -> Result<&str> { - path.to_str() - .ok_or_else(|| format_err!("path is not valid UTF-8 '{}'", path.display())) + path.to_str().ok_or_else(|| format_err!("path is not valid UTF-8 '{}'", path.display())) } /// Wraps `fs::copy` with a nicer error message. @@ -27,11 +26,7 @@ pub fn copy, Q: AsRef>(from: P, to: Q) -> Result { Ok(0) } else { let amt = fs::copy(&from, &to).with_context(|| { - format!( - "failed to copy '{}' to '{}'", - from.as_ref().display(), - to.as_ref().display() - ) + format!("failed to copy '{}' to '{}'", from.as_ref().display(), to.as_ref().display()) })?; Ok(amt) } @@ -123,8 +118,12 @@ where } macro_rules! actor_field_default { - () => { Default::default() }; - (= $expr:expr) => { $expr.into() } + () => { + Default::default() + }; + (= $expr:expr) => { + $expr.into() + }; } /// Creates an "actor" with default values, setters for all fields, and Clap parser support.