Skip to content

Commit

Permalink
rust-installer and rls no longer submodule, so fix rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
klensy committed Jul 4, 2023
1 parent cd68ead commit f3d9248
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 69 deletions.
4 changes: 2 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
25 changes: 6 additions & 19 deletions src/tools/rust-installer/src/combiner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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() {
Expand Down
30 changes: 6 additions & 24 deletions src/tools/rust-installer/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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('\\', "/");
Expand Down
8 changes: 6 additions & 2 deletions src/tools/rust-installer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
5 changes: 1 addition & 4 deletions src/tools/rust-installer/src/scripter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 2 additions & 9 deletions src/tools/rust-installer/src/tarballer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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![];
Expand Down
17 changes: 8 additions & 9 deletions src/tools/rust-installer/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -27,11 +26,7 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
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)
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f3d9248

Please sign in to comment.