Procházet zdrojové kódy

fix(cli) improve workspace detection #67 (#125)

Lucas Fernandes Nogueira před 5 roky
rodič
revize
85674d4fe6

+ 1 - 1
cli/tauri-cli/src/bundle.rs

@@ -6,9 +6,9 @@ mod dmg_bundle;
 mod ios_bundle;
 mod msi_bundle;
 mod osx_bundle;
+mod path_utils;
 mod rpm_bundle;
 mod settings;
-mod path_utils;
 mod wix;
 
 pub use self::common::{print_error, print_finished};

+ 4 - 3
cli/tauri-cli/src/bundle/appimage_bundle.rs

@@ -1,8 +1,8 @@
 use super::common;
 use super::deb_bundle;
+use super::path_utils;
 use crate::ResultExt;
 use crate::Settings;
-use super::path_utils;
 
 use handlebars::Handlebars;
 use lazy_static::lazy_static;
@@ -48,10 +48,11 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   // generate deb_folder structure
   deb_bundle::generate_folders(settings, &package_dir)?;
 
-  let app_dir_path = path_utils::create(
+  let _app_dir_path = path_utils::create(
     settings
       .project_out_directory()
-      .join(format!("{}.AppDir", settings.binary_name())), true
+      .join(format!("{}.AppDir", settings.binary_name())),
+    true,
   );
 
   let upcase = settings.binary_name().to_uppercase();

+ 4 - 4
cli/tauri-cli/src/bundle/deb_bundle.rs

@@ -27,11 +27,11 @@ use image::{self, GenericImageView, ImageDecoder};
 use libflate::gzip;
 use md5;
 use std::collections::BTreeSet;
+use std::convert::TryInto;
 use std::ffi::OsStr;
 use std::fs::{self, File};
 use std::io::{self, Write};
 use std::path::{Path, PathBuf};
-use std::convert::TryInto;
 use tar;
 use walkdir::WalkDir;
 
@@ -57,7 +57,8 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   }
   let package_path = base_dir.join(package_name);
 
-  let data_dir = generate_folders(settings, &package_dir).chain_err(|| "Failed to build folders")?;
+  let data_dir =
+    generate_folders(settings, &package_dir).chain_err(|| "Failed to build folders")?;
   // Generate control files.
   let control_dir = package_dir.join("control");
   generate_control_file(settings, arch, &control_dir, &data_dir)
@@ -84,7 +85,6 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
 }
 
 pub fn generate_folders(settings: &Settings, package_dir: &Path) -> crate::Result<PathBuf> {
-  
   // Generate data files.
   let data_dir = package_dir.join("data");
   let binary_dest = data_dir.join("usr/bin").join(settings.binary_name());
@@ -231,7 +231,7 @@ fn generate_icon_files(settings: &Settings, data_dir: &PathBuf) -> crate::Result
     if icon_path.extension() != Some(OsStr::new("png")) {
       continue;
     }
-    let mut decoder = PNGDecoder::new(File::open(&icon_path)?)?;
+    let decoder = PNGDecoder::new(File::open(&icon_path)?)?;
     let width = decoder.dimensions().0.try_into().unwrap();
     let height = decoder.dimensions().1.try_into().unwrap();
     let is_high_density = common::is_retina(&icon_path);

+ 1 - 1
cli/tauri-cli/src/bundle/dmg_bundle.rs

@@ -61,7 +61,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
     .spawn()
     .expect("Failed to chmod script");
 
-    // execute the bundle script
+  // execute the bundle script
   Command::new(&bundle_sh)
     .current_dir(output_path)
     .stdout(Stdio::piped())

+ 2 - 2
cli/tauri-cli/src/bundle/ios_bundle.rs

@@ -14,11 +14,11 @@ use icns;
 use image::png::{PNGDecoder, PNGEncoder};
 use image::{self, GenericImageView, ImageDecoder};
 use std::collections::BTreeSet;
+use std::convert::TryInto;
 use std::ffi::OsStr;
 use std::fs::{self, File};
 use std::io::Write;
 use std::path::{Path, PathBuf};
-use std::convert::TryInto;
 
 pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   common::print_warning("iOS bundle support is still experimental.")?;
@@ -75,7 +75,7 @@ fn generate_icon_files(bundle_dir: &Path, settings: &Settings) -> crate::Result<
       if icon_path.extension() != Some(OsStr::new("png")) {
         continue;
       }
-      let mut decoder = PNGDecoder::new(File::open(&icon_path)?)?;
+      let decoder = PNGDecoder::new(File::open(&icon_path)?)?;
       let width = decoder.dimensions().0.try_into().unwrap();
       let height = decoder.dimensions().1.try_into().unwrap();
       let is_retina = common::is_retina(&icon_path);

+ 1 - 1
cli/tauri-cli/src/bundle/osx_bundle.rs

@@ -265,7 +265,7 @@ fn create_icns_file(
     match icns::IconType::from_pixel_size_and_density(icon.width(), icon.height(), density) {
       Some(icon_type) => {
         if !family.has_icon_with_type(icon_type) {
-          let icon =make_icns_image(icon)?;
+          let icon = make_icns_image(icon)?;
           family.add_icon_with_type(&icon, icon_type)?;
         }
         Ok(())

+ 5 - 2
cli/tauri-cli/src/bundle/path_utils.rs

@@ -204,8 +204,11 @@ pub fn get_dir_info<P>(path: P, options: &DirOpts) -> crate::Result<DirInfo>
 where
   P: AsRef<Path>,
 {
-
-  let depth = if options.depth==0 { 0 } else { options.depth + 1 };
+  let depth = if options.depth == 0 {
+    0
+  } else {
+    options.depth + 1
+  };
 
   _get_dir_info(path, depth)
 }

+ 20 - 4
cli/tauri-cli/src/bundle/settings.rs

@@ -256,14 +256,30 @@ impl Settings {
       Determining if the current project folder is part of a workspace:
           - Walk up the file system, looking for a Cargo.toml file.
           - Stop at the first one found.
-          - If one is found before reaching "/" then this folder belongs to that parent workspace
+          - If one is found before reaching "/" then this folder belongs to that parent workspace,
+            if it contains a [workspace] entry and the project crate name is listed on the "members" array
   */
   pub fn get_workspace_dir(current_dir: &PathBuf) -> PathBuf {
     let mut dir = current_dir.clone();
+    let project_name = CargoSettings::load(&dir).unwrap().package.unwrap().name;
+
     while dir.pop() {
-      let set = CargoSettings::load(&dir);
-      if set.is_ok() {
-        return dir;
+      match CargoSettings::load(&dir) {
+        Ok(cargo_settings) => match cargo_settings.workspace {
+          Some(workspace_settings) => {
+            if workspace_settings.members.is_some()
+              && workspace_settings
+                .members
+                .unwrap()
+                .iter()
+                .any(|member| member.as_str() == project_name)
+            {
+              return dir;
+            }
+          }
+          None => {}
+        },
+        Err(_) => {}
       }
     }