feat(workflow) run clippy on the bundler (#826)

This commit is contained in:
Lucas Fernandes Nogueira
2020-07-14 12:46:13 -03:00
committed by GitHub
parent bd0118f160
commit 490b3a3323
10 changed files with 109 additions and 108 deletions

View File

@@ -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

View File

@@ -59,7 +59,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
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();

View File

@@ -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",

View File

@@ -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<PathBuf>) -> 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<PathBuf>) -> 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<T: term::Terminal + ?Sized>(
output: &mut Box<T>,
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"),

View File

@@ -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(())
}

View File

@@ -70,7 +70,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
.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<Vec<PathBuf>> {
// 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<Vec<PathBuf>> {
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])
}

View File

@@ -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<String>,
icon_filenames: &[String],
) -> crate::Result<()> {
let file = &mut common::create_file(&bundle_dir.join("Info.plist"))?;
write!(
writeln!(
file,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \
\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n\
<plist version=\"1.0\">\n\
<dict>\n"
<dict>"
)?;
write!(
writeln!(
file,
" <key>CFBundleIdentifier</key>\n <string>{}</string>\n",
" <key>CFBundleIdentifier</key>\n <string>{}</string>",
settings.bundle_identifier()
)?;
write!(
writeln!(
file,
" <key>CFBundleDisplayName</key>\n <string>{}</string>\n",
" <key>CFBundleDisplayName</key>\n <string>{}</string>",
settings.bundle_name()
)?;
write!(
writeln!(
file,
" <key>CFBundleName</key>\n <string>{}</string>\n",
" <key>CFBundleName</key>\n <string>{}</string>",
settings.bundle_name()
)?;
write!(
writeln!(
file,
" <key>CFBundleExecutable</key>\n <string>{}</string>\n",
" <key>CFBundleExecutable</key>\n <string>{}</string>",
settings.main_binary_name()
)?;
write!(
writeln!(
file,
" <key>CFBundleVersion</key>\n <string>{}</string>\n",
" <key>CFBundleVersion</key>\n <string>{}</string>",
settings.version_string()
)?;
write!(
writeln!(
file,
" <key>CFBundleShortVersionString</key>\n <string>{}</string>\n",
" <key>CFBundleShortVersionString</key>\n <string>{}</string>",
settings.version_string()
)?;
write!(
writeln!(
file,
" <key>CFBundleDevelopmentRegion</key>\n <string>en_US</string>\n"
" <key>CFBundleDevelopmentRegion</key>\n <string>en_US</string>"
)?;
if !icon_filenames.is_empty() {
write!(file, " <key>CFBundleIconFiles</key>\n <array>\n")?;
writeln!(file, " <key>CFBundleIconFiles</key>\n <array>")?;
for filename in icon_filenames {
write!(file, " <string>{}</string>\n", filename)?;
writeln!(file, " <string>{}</string>", filename)?;
}
write!(file, " </array>\n")?;
writeln!(file, " </array>")?;
}
write!(file, " <key>LSRequiresIPhoneOS</key>\n <true/>\n")?;
write!(file, "</dict>\n</plist>\n")?;
writeln!(file, " <key>LSRequiresIPhoneOS</key>\n <true/>")?;
writeln!(file, "</dict>\n</plist>")?;
file.flush()?;
Ok(())
}

View File

@@ -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(),
));
))
}
}

View File

@@ -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<BundleBinary> = 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<BundleSe
/// Returns the first Option with a value, or None if both are None.
fn options_value<T>(first: Option<T>, second: Option<T>) -> Option<T> {
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()));
}
}

View File

@@ -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()?;