pub fn build(self) -> crate::Result<Settings> {
    let current_dir = std::env::current_dir()?;
    let cargo_settings = CargoSettings::load(&current_dir)?;
    let tauri_config = super::tauri_config::get();

    let package = match cargo_settings.package {
      Some(package_info) => package_info,
      None => {
        return Err(crate::Error::GenericError(
          "No package info in the config file".to_owned(),
        ))
      }
    };
    let workspace_dir = Settings::get_workspace_dir(&current_dir);
    let target = if let Some(target_triple) = self.target_triple {
      Some((target_triple.clone(), TargetInfo::from_str(&target_triple)?))
    } else {
      None
    };
    let target_dir = Settings::get_target_dir(&workspace_dir, &target, self.release)?;
    let bundle_settings = match tauri_config {
      Ok(config) => merge_settings(BundleSettings::default(), config.tauri.bundle),
      Err(e) => {
        let error_message = e.to_string();
        if !error_message.contains("No such file or directory") {
          return Err(crate::Error::GenericError(format!(
            "Failed to read tauri config: {}",
            error_message
          )));
        }
        if let Some(bundle_settings) = package
          .metadata
          .as_ref()
          .and_then(|metadata| metadata.bundle.as_ref())
        {
          bundle_settings.clone()
        } else {
          return Err(crate::Error::GenericError(
            "No 'bundle' key in the tauri.conf.json".to_owned(),
          ));
        }
      }
    };

    let mut binaries: Vec<BundleBinary> = vec![];
    if let Some(bin) = cargo_settings.bin {
      let default_run = package
        .default_run
        .clone()
        .unwrap_or_else(|| "".to_string());
      for binary in bin {
        binaries.push(
          BundleBinary::new(
            binary.name.clone(),
            binary.name.as_str() == package.name || binary.name.as_str() == default_run,
          )
          .set_src_path(binary.path),
        )
      }
    }

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

    if let Some(default_run) = package.default_run.as_ref() {
      if !binaries.iter().any(|bin| bin.name.as_str() == default_run) {
        binaries.push(BundleBinary::new(default_run.to_string(), true));
      }
    }

    if binaries.len() == 1 {
      if let Some(bin) = binaries.get_mut(0) {
        bin.main = true;
      }
    }

    let bundle_settings = parse_external_bin(bundle_settings)?;

    Ok(Settings {
      package,
      package_types: self.package_types,
      target,
      features: self.features,
      is_release: self.release,
      is_verbose: self.verbose,
      project_out_directory: target_dir,
      binaries,
      bundle_settings,
    })
  }
/// Builds a Settings from the CLI args.
///
/// Package settings will be read from Cargo.toml.
///
/// Bundle settings will be read from from $TAURI_DIR/tauri.conf.json if it exists and fallback to Cargo.toml's [package.metadata.bundle].
Builds a Settings from the CLI args.
Package settings will be read from Cargo.toml.

Bundle settings will be read from from $TAURI_DIR/tauri.conf.json if it exists and fallback to Cargo.toml's [package.metadata.bundle].
Builds a Settings from the CLI args . Package settings will be read from Cargo . toml . Bundle settings will be read from from $TAURI_DIR / tauri . conf . json if it exists and fallback to Cargo . toml ' s [ package . metadata . bundle ] .
pub fn build(self) -> crate::Result<Settings> {
    let current_dir = std::env::current_dir()?;
    let cargo_settings = CargoSettings::load(&current_dir)?;
    let tauri_config = super::tauri_config::get();
    let package = match cargo_settings.package {
      Some(package_info) => package_info,
      None => {
        return Err(crate::Error::GenericError(
          "No package info in the config file".to_owned(),
        ))
      }
    };
    let workspace_dir = Settings::get_workspace_dir(&current_dir);
    let target = if let Some(target_triple) = self.target_triple {
      Some((target_triple.clone(), TargetInfo::from_str(&target_triple)?))
    } else {
      None
    };
    let target_dir = Settings::get_target_dir(&workspace_dir, &target, self.release)?;
    let bundle_settings = match tauri_config {
      Ok(config) => merge_settings(BundleSettings::default(), config.tauri.bundle),
      Err(e) => {
        let error_message = e.to_string();
        if !error_message.contains("No such file or directory") {
          return Err(crate::Error::GenericError(format!(
            "Failed to read tauri config: {}",
            error_message
          )));
        }
        if let Some(bundle_settings) = package
          .metadata
          .as_ref()
          .and_then(|metadata| metadata.bundle.as_ref())
        {
          bundle_settings.clone()
        } else {
          return Err(crate::Error::GenericError(
            "No 'bundle' key in the tauri.conf.json".to_owned(),
          ));
        }
      }
    };
    let mut binaries: Vec<BundleBinary> = vec![];
    if let Some(bin) = cargo_settings.bin {
      let default_run = package
        .default_run
        .clone()
        .unwrap_or_else(|| "".to_string());
      for binary in bin {
        binaries.push(
          BundleBinary::new(
            binary.name.clone(),
            binary.name.as_str() == package.name || binary.name.as_str() == default_run,
          )
          .set_src_path(binary.path),
        )
      }
    }
    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() {
          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))
          }
        }
      }
    }
    if let Some(default_run) = package.default_run.as_ref() {
      if !binaries.iter().any(|bin| bin.name.as_str() == default_run) {
        binaries.push(BundleBinary::new(default_run.to_string(), true));
      }
    }
    if binaries.len() == 1 {
      if let Some(bin) = binaries.get_mut(0) {
        bin.main = true;
      }
    }
    let bundle_settings = parse_external_bin(bundle_settings)?;
    Ok(Settings {
      package,
      package_types: self.package_types,
      target,
      features: self.features,
      is_release: self.release,
      is_verbose: self.verbose,
      project_out_directory: target_dir,
      binaries,
      bundle_settings,
    })
  }
pub fn build ( self ) -> crate :: Result < Settings > { let current_dir = std :: env :: current_dir ( ) ? ; let cargo_settings = CargoSettings :: load ( & current_dir ) ? ; let tauri_config = super :: tauri_config :: get ( ) ; let package = match cargo_settings . package { Some ( package_info ) => package_info , None => { return Err ( crate :: Error :: GenericError ( " " . to_owned ( ) , ) ) } } ; let workspace_dir = Settings :: get_workspace_dir ( & current_dir ) ; let target = if let Some ( target_triple ) = self . target_triple { Some ( ( target_triple . clone ( ) , TargetInfo :: from_str ( & target_triple ) ? ) ) } else { None } ; let target_dir = Settings :: get_target_dir ( & workspace_dir , & target , self . release ) ? ; let bundle_settings = match tauri_config { Ok ( config ) => merge_settings ( BundleSettings :: default ( ) , config . tauri . bundle ) , Err ( e ) => { let error_message = e . to_string ( ) ; if ! error_message . contains ( " " ) { return Err ( crate :: Error :: GenericError ( format ! ( " " error_message ) ) ) ; } if let Some ( bundle_settings ) = package . metadata . as_ref ( ) . and_then ( | metadata | metadata . bundle . as_ref ( ) ) { bundle_settings . clone ( ) } else { return Err ( crate :: Error :: GenericError ( " " . to_owned ( ) , ) ) ; } } } ; let mut binaries : Vec < BundleBinary > = vec ! [ ] ; if let Some ( bin ) = cargo_settings . bin { let default_run = package . default_run . clone ( ) . unwrap_or_else ( | | " " . to_string ( ) ) ; for binary in bin { binaries . push ( BundleBinary :: new ( binary . name . clone ( ) , binary . name . as_str ( ) == package . name || binary . name . as_str ( ) == default_run , ) . set_src_path ( binary . path ) , ) } } let mut bins_path = current_dir ; bins_path . push ( " " ) ; 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 ( ) { 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 ) ) } } } } if let Some ( default_run ) = package . default_run . as_ref ( ) { if ! binaries . iter ( ) . any ( | bin | bin . name . as_str ( ) == default_run ) { binaries . push ( BundleBinary :: new ( default_run . to_string ( ) , true ) ) ; } } if binaries . len ( ) == 1 { if let Some ( bin ) = binaries . get_mut ( 0 ) { bin . main = true ; } } let bundle_settings = parse_external_bin ( bundle_settings ) ? ; Ok ( Settings { package , package_types : self . package_types , target , features : self . features , is_release : self . release , is_verbose : self . verbose , project_out_directory : target_dir , binaries , bundle_settings , } ) }
Builds a Settings from the CLI args.
Builds a Settings from the CLI args .
self
self