diff --git a/.github/workflows/check-on-push.yml b/.github/workflows/check-on-push.yml index a4cd43b70..85f3392c5 100644 --- a/.github/workflows/check-on-push.yml +++ b/.github/workflows/check-on-push.yml @@ -25,6 +25,11 @@ jobs: env: TAURI_DIST_DIR: ${{ runner.workspace }}/tauri/tauri/examples/communication/dist TAURI_DIR: ${{ runner.workspace }}/tauri/tauri/examples/communication/src-tauri + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --manifest-path ./cli/tauri-bundler/Cargo.toml --all-targets -- -D warnings + name: bundler - uses: actions-rs/toolchain@v1 with: profile: minimal diff --git a/cli/tauri-bundler/src/bundle/appimage_bundle.rs b/cli/tauri-bundler/src/bundle/appimage_bundle.rs index 1734c76c5..b8d6cebed 100644 --- a/cli/tauri-bundler/src/bundle/appimage_bundle.rs +++ b/cli/tauri-bundler/src/bundle/appimage_bundle.rs @@ -59,7 +59,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { std::fs::create_dir_all(output_path.clone())?; let app_dir_path = output_path.join(format!("{}.AppDir", settings.main_binary_name())); let appimage_path = output_path.join(format!("{}.AppImage", settings.main_binary_name())); - path_utils::create(app_dir_path.clone(), true)?; + path_utils::create(app_dir_path, true)?; let upcase_app_name = settings.main_binary_name().to_uppercase(); diff --git a/cli/tauri-bundler/src/bundle/category.rs b/cli/tauri-bundler/src/bundle/category.rs index f52793742..ae260803f 100644 --- a/cli/tauri-bundler/src/bundle/category.rs +++ b/cli/tauri-bundler/src/bundle/category.rs @@ -133,7 +133,7 @@ impl AppCategory { /// Map an AppCategory to the closest set of GNOME desktop registered /// categories that matches that category. - pub fn gnome_desktop_categories(&self) -> &'static str { + pub fn gnome_desktop_categories(self) -> &'static str { match &self { AppCategory::Business => "Office;", AppCategory::DeveloperTool => "Development;", @@ -180,7 +180,7 @@ impl AppCategory { /// Map an AppCategory to the closest LSApplicationCategoryType value that /// matches that category. - pub fn osx_application_category_type(&self) -> &'static str { + pub fn osx_application_category_type(self) -> &'static str { match &self { AppCategory::Business => "public.app-category.business", AppCategory::DeveloperTool => "public.app-category.developer-tools", diff --git a/cli/tauri-bundler/src/bundle/common.rs b/cli/tauri-bundler/src/bundle/common.rs index cce5c8ed9..37611f923 100644 --- a/cli/tauri-bundler/src/bundle/common.rs +++ b/cli/tauri-bundler/src/bundle/common.rs @@ -150,7 +150,7 @@ pub fn print_bundling(filename: &str) -> crate::Result<()> { /// Prints a message to stderr, in the same format that `cargo` uses, /// indicating that we have finished the the given bundles. -pub fn print_finished(output_paths: &Vec) -> crate::Result<()> { +pub fn print_finished(output_paths: &[PathBuf]) -> crate::Result<()> { let pluralised = if output_paths.len() == 1 { "bundle" } else { @@ -167,29 +167,30 @@ pub fn print_finished(output_paths: &Vec) -> crate::Result<()> { /// Safely adds the terminal attribute to the terminal output. /// If the terminal doesn't support the attribute, does nothing. fn safe_term_attr( - output: &mut Box, + output: &mut T, attr: term::Attr, ) -> term::Result<()> { - match output.supports_attr(attr) { - true => output.attr(attr), - false => Ok(()), + if output.supports_attr(attr) { + output.attr(attr) + } else { + Ok(()) } } /// Prints a formatted bundle progress to stderr. fn print_progress(step: &str, msg: &str) -> crate::Result<()> { if let Some(mut output) = term::stderr() { - safe_term_attr(&mut output, term::Attr::Bold)?; + safe_term_attr(&mut *output, term::Attr::Bold)?; output.fg(term::color::GREEN)?; write!(output, " {}", step)?; output.reset()?; - write!(output, " {}\n", msg)?; + writeln!(output, " {}", msg)?; output.flush()?; Ok(()) } else { let mut output = io::stderr(); write!(output, " {}", step)?; - write!(output, " {}\n", msg)?; + writeln!(output, " {}", msg)?; output.flush()?; Ok(()) } @@ -198,17 +199,17 @@ fn print_progress(step: &str, msg: &str) -> crate::Result<()> { /// Prints a warning message to stderr, in the same format that `cargo` uses. pub fn print_warning(message: &str) -> crate::Result<()> { if let Some(mut output) = term::stderr() { - safe_term_attr(&mut output, term::Attr::Bold)?; + safe_term_attr(&mut *output, term::Attr::Bold)?; output.fg(term::color::YELLOW)?; write!(output, "warning:")?; output.reset()?; - write!(output, " {}\n", message)?; + writeln!(output, " {}", message)?; output.flush()?; Ok(()) } else { let mut output = io::stderr(); write!(output, "warning:")?; - write!(output, " {}\n", message)?; + writeln!(output, " {}", message)?; output.flush()?; Ok(()) } @@ -217,17 +218,17 @@ pub fn print_warning(message: &str) -> crate::Result<()> { /// Prints a Info message to stderr. pub fn print_info(message: &str) -> crate::Result<()> { if let Some(mut output) = term::stderr() { - safe_term_attr(&mut output, term::Attr::Bold)?; + safe_term_attr(&mut *output, term::Attr::Bold)?; output.fg(term::color::GREEN)?; write!(output, "info:")?; output.reset()?; - write!(output, " {}\n", message)?; + writeln!(output, " {}", message)?; output.flush()?; Ok(()) } else { let mut output = io::stderr(); write!(output, "info:")?; - write!(output, " {}\n", message)?; + writeln!(output, " {}", message)?; output.flush()?; Ok(()) } @@ -236,11 +237,11 @@ pub fn print_info(message: &str) -> crate::Result<()> { /// Prints an error to stderr, in the same format that `cargo` uses. pub fn print_error(error: &anyhow::Error) -> crate::Result<()> { if let Some(mut output) = term::stderr() { - safe_term_attr(&mut output, term::Attr::Bold)?; + safe_term_attr(&mut *output, term::Attr::Bold)?; output.fg(term::color::RED)?; write!(output, "error:")?; output.reset()?; - safe_term_attr(&mut output, term::Attr::Bold)?; + safe_term_attr(&mut *output, term::Attr::Bold)?; writeln!(output, " {}", error)?; output.reset()?; for cause in error.chain().skip(1) { @@ -304,7 +305,7 @@ mod tests { { let mut file = create_file(&tmp.path().join("parent/file.txt")).expect("Failed to create file"); - write!(file, "Hello, world!\n").expect("unable to write file"); + writeln!(file, "Hello, world!").expect("unable to write file"); } assert!(tmp.path().join("parent").is_dir()); assert!(tmp.path().join("parent/file.txt").is_file()); @@ -321,7 +322,7 @@ mod tests { { let mut file = create_file(&tmp.path().join("orig/sub/file.txt")).expect("Unable to create file"); - write!(file, "Hello, world!\n").expect("Unable to write to file"); + writeln!(file, "Hello, world!").expect("Unable to write to file"); } symlink_file( &PathBuf::from("sub/file.txt"), diff --git a/cli/tauri-bundler/src/bundle/deb_bundle.rs b/cli/tauri-bundler/src/bundle/deb_bundle.rs index dd423967f..8eb9b7adc 100644 --- a/cli/tauri-bundler/src/bundle/deb_bundle.rs +++ b/cli/tauri-bundler/src/bundle/deb_bundle.rs @@ -190,29 +190,29 @@ fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result< let file = &mut common::create_file(&desktop_file_path)?; // For more information about the format of this file, see // https://developer.gnome.org/integration-guide/stable/desktop-files.html.en - write!(file, "[Desktop Entry]\n")?; - write!(file, "Encoding=UTF-8\n")?; + writeln!(file, "[Desktop Entry]")?; + writeln!(file, "Encoding=UTF-8")?; if let Some(category) = settings.app_category() { - write!(file, "Categories={}\n", category.gnome_desktop_categories())?; + write!(file, "Categories={}", category.gnome_desktop_categories())?; } if !settings.short_description().is_empty() { - write!(file, "Comment={}\n", settings.short_description())?; + writeln!(file, "Comment={}", settings.short_description())?; } let use_bootstrapper = settings.debian_use_bootstrapper(); - write!( + writeln!( file, - "Exec={}\n", + "Exec={}", if use_bootstrapper { format!("__{}-bootstrapper", bin_name) } else { bin_name.to_string() } )?; - write!(file, "Icon={}\n", bin_name)?; - write!(file, "Name={}\n", settings.bundle_name())?; - write!(file, "Terminal=false\n")?; - write!(file, "Type=Application\n")?; - write!(file, "Version={}\n", settings.version_string())?; + writeln!(file, "Icon={}", bin_name)?; + writeln!(file, "Name={}", settings.bundle_name())?; + writeln!(file, "Terminal=false")?; + writeln!(file, "Type=Application")?; + writeln!(file, "Version={}", settings.version_string())?; Ok(()) } @@ -235,7 +235,9 @@ fn generate_control_file( writeln!(&mut file, "Version: {}", settings.version_string())?; writeln!(&mut file, "Architecture: {}", arch)?; writeln!(&mut file, "Installed-Size: {}", total_dir_size(data_dir)?)?; - let authors = settings.authors_comma_separated().unwrap_or(String::new()); + let authors = settings + .authors_comma_separated() + .unwrap_or_else(String::new); writeln!(&mut file, "Maintainer: {}", authors)?; if !settings.homepage_url().is_empty() { writeln!(&mut file, "Homepage: {}", settings.homepage_url())?; @@ -287,7 +289,7 @@ fn generate_md5sums(control_dir: &Path, data_dir: &Path) -> crate::Result<()> { let msg = format!("Non-UTF-8 path: {:?}", rel_path); io::Error::new(io::ErrorKind::InvalidData, msg) })?; - write!(md5sums_file, " {}\n", path_str)?; + writeln!(md5sums_file, " {}", path_str)?; } Ok(()) } diff --git a/cli/tauri-bundler/src/bundle/dmg_bundle.rs b/cli/tauri-bundler/src/bundle/dmg_bundle.rs index be1b4999b..a6f2f8327 100644 --- a/cli/tauri-bundler/src/bundle/dmg_bundle.rs +++ b/cli/tauri-bundler/src/bundle/dmg_bundle.rs @@ -70,7 +70,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { .arg("777") .arg(&bundle_script_path) .arg(&license_script_path) - .current_dir(output_path.clone()) + .current_dir(output_path) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() @@ -102,13 +102,10 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { // Issue #592 - Building MacOS dmg files on CI // https://github.com/tauri-apps/tauri/issues/592 - match env::var_os("CI") { - Some(value) => { - if value == "true" { - args.push("--skip-jenkins"); - } + if let Some(value) = env::var_os("CI") { + if value == "true" { + args.push("--skip-jenkins"); } - None => (), } // execute the bundle script @@ -122,6 +119,6 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { common::execute_with_output(&mut cmd) .map_err(|_| crate::Error::ShellScriptError("error running bundle_dmg.sh".to_owned()))?; - fs::rename(bundle_dir.join(dmg_name.clone()), dmg_path.clone())?; + fs::rename(bundle_dir.join(dmg_name), dmg_path.clone())?; Ok(vec![bundle_path, dmg_path]) } diff --git a/cli/tauri-bundler/src/bundle/ios_bundle.rs b/cli/tauri-bundler/src/bundle/ios_bundle.rs index c2f3534a3..5a2fee2a5 100644 --- a/cli/tauri-bundler/src/bundle/ios_bundle.rs +++ b/cli/tauri-bundler/src/bundle/ios_bundle.rs @@ -133,62 +133,62 @@ fn generate_icon_files(bundle_dir: &Path, settings: &Settings) -> crate::Result< fn generate_info_plist( bundle_dir: &Path, settings: &Settings, - icon_filenames: &Vec, + icon_filenames: &[String], ) -> crate::Result<()> { let file = &mut common::create_file(&bundle_dir.join("Info.plist"))?; - write!( + writeln!( file, "\n\ \n\ \n\ - \n" + " )?; - write!( + writeln!( file, - " CFBundleIdentifier\n {}\n", + " CFBundleIdentifier\n {}", settings.bundle_identifier() )?; - write!( + writeln!( file, - " CFBundleDisplayName\n {}\n", + " CFBundleDisplayName\n {}", settings.bundle_name() )?; - write!( + writeln!( file, - " CFBundleName\n {}\n", + " CFBundleName\n {}", settings.bundle_name() )?; - write!( + writeln!( file, - " CFBundleExecutable\n {}\n", + " CFBundleExecutable\n {}", settings.main_binary_name() )?; - write!( + writeln!( file, - " CFBundleVersion\n {}\n", + " CFBundleVersion\n {}", settings.version_string() )?; - write!( + writeln!( file, - " CFBundleShortVersionString\n {}\n", + " CFBundleShortVersionString\n {}", settings.version_string() )?; - write!( + writeln!( file, - " CFBundleDevelopmentRegion\n en_US\n" + " CFBundleDevelopmentRegion\n en_US" )?; if !icon_filenames.is_empty() { - write!(file, " CFBundleIconFiles\n \n")?; + writeln!(file, " CFBundleIconFiles\n ")?; for filename in icon_filenames { - write!(file, " {}\n", filename)?; + writeln!(file, " {}", filename)?; } - write!(file, " \n")?; + writeln!(file, " ")?; } - write!(file, " LSRequiresIPhoneOS\n \n")?; - write!(file, "\n\n")?; + writeln!(file, " LSRequiresIPhoneOS\n ")?; + writeln!(file, "\n")?; file.flush()?; Ok(()) } diff --git a/cli/tauri-bundler/src/bundle/osx_bundle.rs b/cli/tauri-bundler/src/bundle/osx_bundle.rs index 30fb1d413..e2485b24b 100644 --- a/cli/tauri-bundler/src/bundle/osx_bundle.rs +++ b/cli/tauri-bundler/src/bundle/osx_bundle.rs @@ -310,7 +310,7 @@ fn copy_frameworks_to_bundle(bundle_directory: &Path, settings: &Settings) -> cr .expect("Couldn't get framework filename"); common::copy_dir(&src_path, &dest_dir.join(&src_name))?; continue; - } else if framework.contains("/") { + } else if framework.contains('/') { return Err(crate::Error::GenericError(format!( "Framework path should have .framework extension: {}", framework @@ -417,11 +417,11 @@ fn create_icns_file( dest_path.set_extension("icns"); let icns_file = BufWriter::new(File::create(&dest_path)?); family.write(icns_file)?; - return Ok(Some(dest_path)); + Ok(Some(dest_path)) } else { - return Err(crate::Error::GenericError( + Err(crate::Error::GenericError( "No usable Icon files found".to_owned(), - )); + )) } } diff --git a/cli/tauri-bundler/src/bundle/settings.rs b/cli/tauri-bundler/src/bundle/settings.rs index ba9ca24e9..d8c19386f 100644 --- a/cli/tauri-bundler/src/bundle/settings.rs +++ b/cli/tauri-bundler/src/bundle/settings.rs @@ -54,6 +54,7 @@ impl PackageType { } /// Gets the short name of this PackageType. + #[allow(clippy::trivially_copy_pass_by_ref)] pub fn short_name(&self) -> &'static str { match *self { PackageType::Deb => "deb", @@ -379,7 +380,10 @@ impl Settings { let mut binaries: Vec = vec![]; if let Some(bin) = cargo_settings.bin { - let default_run = package.default_run.clone().unwrap_or("".to_string()); + let default_run = package + .default_run + .clone() + .unwrap_or_else(|| "".to_string()); for binary in bin { binaries.push( BundleBinary::new( @@ -391,16 +395,17 @@ impl Settings { } } - let mut bins_path = PathBuf::from(current_dir); + let mut bins_path = current_dir; bins_path.push("src/bin"); if let Ok(fs_bins) = std::fs::read_dir(bins_path) { for entry in fs_bins { let path = entry?.path(); if let Some(name) = path.file_stem() { - if !binaries.iter().any(|bin| { + let bin_exists = binaries.iter().any(|bin| { bin.name.as_str() == name || path.ends_with(bin.src_path.as_ref().unwrap_or(&"".to_string())) - }) { + }); + if !bin_exists { binaries.push(BundleBinary::new(name.to_string_lossy().to_string(), false)) } } @@ -442,7 +447,7 @@ impl Settings { is_release: bool, ) -> PathBuf { let mut path = project_root_dir.join("target"); - if let &Some((ref triple, _)) = target { + if let Some((ref triple, _)) = *target { path.push(triple); } path.push(if is_release { "release" } else { "debug" }); @@ -459,22 +464,18 @@ impl Settings { let project_name = CargoSettings::load(&dir).unwrap().package.unwrap().name; while dir.pop() { - match CargoSettings::load(&dir) { - Ok(cargo_settings) => match cargo_settings.workspace { - Some(workspace_settings) => { - if workspace_settings.members.is_some() - && workspace_settings - .members - .expect("Couldn't get members") - .iter() - .any(|member| member.as_str() == project_name) - { - return dir; - } + if let Ok(cargo_settings) = CargoSettings::load(&dir) { + if let Some(workspace_settings) = cargo_settings.workspace { + if workspace_settings.members.is_some() + && workspace_settings + .members + .expect("Couldn't get members") + .iter() + .any(|member| member.as_str() == project_name) + { + return dir; } - None => {} - }, - Err(_) => {} + } } } @@ -796,7 +797,7 @@ fn parse_external_bin(bundle_settings: BundleSettings) -> crate::Result(first: Option, second: Option) -> Option { - if let Some(_) = first { + if first.is_some() { first } else { second @@ -905,14 +906,12 @@ impl<'a> Iterator for ResourcePaths<'a> { } self.current_pattern_is_valid = true; return Some(Ok(path)); - } else { - if let Some(current_path) = &self.current_pattern { - if !self.current_pattern_is_valid { - return Some(Err(crate::Error::GenericError(format!( - "Path matching '{}' not found", - current_path - )))); - } + } else if let Some(current_path) = &self.current_pattern { + if !self.current_pattern_is_valid { + return Some(Err(crate::Error::GenericError(format!( + "Path matching '{}' not found", + current_path + )))); } } } @@ -1035,17 +1034,17 @@ mod tests { let bins = bundle.bin.as_ref().expect("Failed to get bin ref"); assert!(bins.contains_key("foo")); - let foo: &BundleSettings = bins.get("foo").expect("Failed to get foo bundle settings"); - assert_eq!(foo.name, Some("Foo App".to_string())); + let foo_settings: &BundleSettings = bins.get("foo").expect("Failed to get foo bundle settings"); + assert_eq!(foo_settings.name, Some("Foo App".to_string())); assert!(bins.contains_key("bar")); - let bar: &BundleSettings = bins.get("bar").expect("Failed to get bar bundle settings"); - assert_eq!(bar.name, Some("Bar App".to_string())); + let bar_settings: &BundleSettings = bins.get("bar").expect("Failed to get bar bundle settings"); + assert_eq!(bar_settings.name, Some("Bar App".to_string())); let examples = bundle.example.as_ref().expect("Failed to get example ref"); assert!(examples.contains_key("baz")); - let baz: &BundleSettings = examples + let baz_settings: &BundleSettings = examples .get("baz") .expect("Failed to get baz bundle settings"); - assert_eq!(baz.name, Some("Baz Example".to_string())); + assert_eq!(baz_settings.name, Some("Baz Example".to_string())); } } diff --git a/cli/tauri-bundler/src/main.rs b/cli/tauri-bundler/src/main.rs index 94a378955..6e511cd33 100644 --- a/cli/tauri-bundler/src/main.rs +++ b/cli/tauri-bundler/src/main.rs @@ -23,11 +23,8 @@ fn build_project_if_unbuilt(settings: &Settings) -> crate::Result<()> { args.push("--release".to_string()); } - match settings.build_features() { - Some(features) => { - args.push(format!("--features={}", features.join(" "))); - } - None => {} + if let Some(features) = settings.build_features() { + args.push(format!("--features={}", features.join(" "))); } let status = process::Command::new("cargo").args(args).status()?;