Address lints

Summary: Just going through all the lints that have popped up.

Reviewed By: jknoxville

Differential Revision: D24078571

fbshipit-source-id: 06504aafa969eea92ee934ac607d3daf51e47914
This commit is contained in:
Pascal Hartig
2020-10-02 06:35:43 -07:00
committed by Facebook GitHub Bot
parent 2bbd76803c
commit d477ed7818
4 changed files with 27 additions and 21 deletions

View File

@@ -1,5 +1,10 @@
[package] [package]
name = "flipper-packer" name = "flipper-packer"
description = "Helper tool that breaks down a Flipper release into smaller artifacts."
license = "MIT"
repository = "https://github.com/facebook/flipper.git"
keywords = ["flipper", "cli"]
categories = ["development-tools"]
version = "0.1.0" version = "0.1.0"
authors = ["Facebook, Inc."] authors = ["Facebook, Inc."]
edition = "2018" edition = "2018"

View File

@@ -20,14 +20,14 @@ impl std::error::Error for Error {}
impl fmt::Display for Error { impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Error::MissingPackFile(platform, pack_type, path) => write!( Self::MissingPackFile(platform, pack_type, path) => write!(
f, f,
"Couldn't open file to pack for platform {:?} and type {:?}: {}", "Couldn't open file to pack for platform {:?} and type {:?}: {}",
platform, platform,
pack_type, pack_type,
path.to_string_lossy() path.to_string_lossy()
), ),
Error::MissingPlatformDefinition(platform) => write!( Self::MissingPlatformDefinition(platform) => write!(
f, f,
"Platform {} is not defined in the given packlist.", "Platform {} is not defined in the given packlist.",
platform platform

View File

@@ -6,6 +6,8 @@
*/ */
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)] #![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
// This doesn't seem to cause any issues and nobody I know can read \u{1234} by heart.
#![allow(clippy::non_ascii_literal)]
mod error; mod error;
mod tarsum; mod tarsum;
@@ -53,7 +55,7 @@ fn default_progress_bar(len: u64) -> indicatif::ProgressBar {
} }
fn pack( fn pack(
platform: &Platform, platform: Platform,
dist_dir: &std::path::PathBuf, dist_dir: &std::path::PathBuf,
pack_list: &PackList, pack_list: &PackList,
output_directory: &std::path::PathBuf, output_directory: &std::path::PathBuf,
@@ -66,11 +68,11 @@ fn pack(
)); ));
let packtype_paths = pack_list let packtype_paths = pack_list
.0 .0
.get(platform) .get(&platform)
.ok_or_else(|| error::Error::MissingPlatformDefinition(*platform))?; .ok_or_else(|| error::Error::MissingPlatformDefinition(platform))?;
let res = packtype_paths let res = packtype_paths
.into_par_iter() .into_par_iter()
.map(|(pack_type, pack_files)| { .map(|(&pack_type, pack_files)| {
let output_path = path::Path::new(output_directory).join(format!("{}.tar", pack_type)); let output_path = path::Path::new(output_directory).join(format!("{}.tar", pack_type));
let mut tar = tar::Builder::new(File::create(&output_path).with_context(|| { let mut tar = tar::Builder::new(File::create(&output_path).with_context(|| {
format!( format!(
@@ -86,7 +88,7 @@ fn pack(
tar.finish()?; tar.finish()?;
pb.inc(1); pb.inc(1);
Ok((*pack_type, output_path)) Ok((pack_type, output_path))
}) })
.collect(); .collect();
@@ -95,10 +97,10 @@ fn pack(
} }
fn pack_platform( fn pack_platform(
platform: &Platform, platform: Platform,
dist_dir: &std::path::PathBuf, dist_dir: &std::path::PathBuf,
pack_files: &[path::PathBuf], pack_files: &[path::PathBuf],
pack_type: &PackType, pack_type: PackType,
tar_builder: &mut tar::Builder<File>, tar_builder: &mut tar::Builder<File>,
) -> Result<()> { ) -> Result<()> {
let base_dir = match platform { let base_dir = match platform {
@@ -112,7 +114,7 @@ fn pack_platform(
let full_path = path::Path::new(&base_dir).join(f); let full_path = path::Path::new(&base_dir).join(f);
if !full_path.exists() { if !full_path.exists() {
bail!(error::Error::MissingPackFile( bail!(error::Error::MissingPackFile(
*platform, *pack_type, full_path, platform, pack_type, full_path,
)); ));
} }
if full_path.is_file() { if full_path.is_file() {
@@ -169,13 +171,13 @@ fn main() -> Result<(), anyhow::Error> {
shellexpand::tilde(args.value_of("dist").expect("argument has default")).to_string(), shellexpand::tilde(args.value_of("dist").expect("argument has default")).to_string(),
); );
let compress = !args.is_present("no-compression"); let compress = !args.is_present("no-compression");
let pack_list_str = args let pack_list_str = args.value_of("packlist").map_or_else(
.value_of("packlist") || DEFAULT_PACKLIST.to_string(),
.map(|f| { |f| {
std::fs::read_to_string(f) std::fs::read_to_string(f)
.unwrap_or_else(|e| panic!("Failed to open packfile {}: {}", f, e)) .unwrap_or_else(|e| panic!("Failed to open packfile {}: {}", f, e))
}) },
.unwrap_or_else(|| DEFAULT_PACKLIST.to_string()); );
let pack_list: PackList = let pack_list: PackList =
serde_yaml::from_str(&pack_list_str).expect("Failed to deserialize YAML packlist."); serde_yaml::from_str(&pack_list_str).expect("Failed to deserialize YAML packlist.");
let output_directory = let output_directory =
@@ -186,13 +188,13 @@ fn main() -> Result<(), anyhow::Error> {
output_directory.to_string_lossy() output_directory.to_string_lossy()
) )
})?; })?;
let archive_paths = pack(&platform, &dist_dir, &pack_list, output_directory)?; let archive_paths = pack(platform, &dist_dir, &pack_list, output_directory)?;
let compressed_archive_paths = if compress { let compressed_archive_paths = if compress {
Some(compress_paths(&archive_paths)?) Some(compress_paths(&archive_paths)?)
} else { } else {
None None
}; };
manifest(&archive_paths, &compressed_archive_paths, &output_directory)?; manifest(&archive_paths, &compressed_archive_paths, output_directory)?;
Ok(()) Ok(())
} }
@@ -252,7 +254,7 @@ fn write_manifest(
let path = path::PathBuf::from(output_directory).join("manifest.json"); let path = path::PathBuf::from(output_directory).join("manifest.json");
let mut file = File::create(&path) let mut file = File::create(&path)
.with_context(|| format!("Failed to write manifest to {}", &path.to_string_lossy()))?; .with_context(|| format!("Failed to write manifest to {}", &path.to_string_lossy()))?;
file.write_all(&serde_json::to_string_pretty(archive_manifest)?.as_bytes())?; file.write_all(serde_json::to_string_pretty(archive_manifest)?.as_bytes())?;
Ok(path) Ok(path)
} }

View File

@@ -37,10 +37,9 @@ pub enum PackType {
impl Display for PackType { impl Display for PackType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use PackType::*;
match *self { match *self {
Frameworks => write!(f, "frameworks"), Self::Frameworks => write!(f, "frameworks"),
Core => write!(f, "core"), Self::Core => write!(f, "core"),
} }
} }
} }