Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions crates/tauri-cli/src/acl/capability/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ use std::{collections::HashSet, path::PathBuf};
use clap::Parser;
use tauri_utils::acl::capability::{Capability, PermissionEntry};

use crate::{
acl::FileFormat,
error::ErrorExt,
helpers::{app_paths::tauri_dir, prompts},
Result,
};
use crate::{acl::FileFormat, error::ErrorExt, helpers::prompts, Result};

#[derive(Debug, Parser)]
#[clap(about = "Create a new permission file")]
Expand All @@ -37,7 +32,7 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let identifier = match options.identifier {
Some(i) => i,
Expand Down Expand Up @@ -111,8 +106,7 @@ pub fn command(options: Options) -> Result<()> {
.canonicalize()
.fs_context("failed to canonicalize capability file path", o.clone())?,
None => {
let dir = tauri_dir();
let capabilities_dir = dir.join("capabilities");
let capabilities_dir = dirs.tauri.join("capabilities");
capabilities_dir.join(format!(
"{}.{}",
capability.identifier,
Expand Down
6 changes: 3 additions & 3 deletions crates/tauri-cli/src/acl/permission/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use clap::Parser;

use crate::{
error::{Context, ErrorExt},
helpers::app_paths::tauri_dir,
Result,
};
use colored::Colorize;
Expand All @@ -25,9 +24,10 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let acl_manifests_path = tauri_dir()
let acl_manifests_path = dirs
.tauri
.join("gen")
.join("schemas")
.join("acl-manifests.json");
Expand Down
20 changes: 11 additions & 9 deletions crates/tauri-cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
acl,
error::ErrorExt,
helpers::{
app_paths::{resolve_frontend_dir, tauri_dir},
app_paths::{resolve_frontend_dir, Dirs},
cargo,
npm::PackageManager,
},
Expand Down Expand Up @@ -39,11 +39,11 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
run(options)
let dirs = crate::helpers::app_paths::resolve_dirs();
run(options, &dirs)
}

pub fn run(options: Options) -> Result<()> {
pub fn run(options: Options, dirs: &Dirs) -> Result<()> {
let (plugin, version) = options
.plugin
.split_once('@')
Expand Down Expand Up @@ -71,7 +71,6 @@ pub fn run(options: Options) -> Result<()> {
}

let frontend_dir = resolve_frontend_dir();
let tauri_dir = tauri_dir();

let target_str = metadata
.desktop_only
Expand All @@ -90,7 +89,7 @@ pub fn run(options: Options) -> Result<()> {
branch: options.branch.as_deref(),
rev: options.rev.as_deref(),
tag: options.tag.as_deref(),
cwd: Some(tauri_dir),
cwd: Some(dirs.tauri),
target: target_str,
})?;

Expand All @@ -117,7 +116,7 @@ pub fn run(options: Options) -> Result<()> {
(None, None, None, None) => npm_name,
_ => crate::error::bail!("Only one of --tag, --rev and --branch can be specified"),
};
manager.install(&[npm_spec], tauri_dir)?;
manager.install(&[npm_spec], dirs.tauri)?;
}

let _ = acl::permission::add::command(acl::permission::add::Options {
Expand All @@ -143,7 +142,10 @@ pub fn run(options: Options) -> Result<()> {
let plugin_init = format!(".plugin(tauri_plugin_{plugin_snake_case}::{plugin_init_fn})");

let re = Regex::new(r"(tauri\s*::\s*Builder\s*::\s*default\(\))(\s*)").unwrap();
for file in [tauri_dir.join("src/main.rs"), tauri_dir.join("src/lib.rs")] {
for file in [
dirs.tauri.join("src/main.rs"),
dirs.tauri.join("src/lib.rs"),
] {
let contents =
std::fs::read_to_string(&file).fs_context("failed to read Rust entry point", file.clone())?;

Expand All @@ -166,7 +168,7 @@ pub fn run(options: Options) -> Result<()> {
log::info!("Running `cargo fmt`...");
let _ = Command::new("cargo")
.arg("fmt")
.current_dir(tauri_dir)
.current_dir(dirs.tauri)
.status();
}

Expand Down
47 changes: 23 additions & 24 deletions crates/tauri-cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
error::{Context, ErrorExt},
helpers::{
self,
app_paths::{frontend_dir, tauri_dir},
config::{get as get_config, ConfigMetadata, FrontendDist},
app_paths::Dirs,
config::{get_config, ConfigMetadata, FrontendDist},
},
info::plugins::check_mismatched_packages,
interface::{rust::get_cargo_target_dir, AppInterface, Interface},
Expand Down Expand Up @@ -81,9 +81,7 @@ pub struct Options {
pub no_sign: bool,
}

pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
crate::helpers::app_paths::resolve();

pub fn command(mut options: Options, verbosity: u8, dirs: &Dirs) -> Result<()> {
if options.no_sign {
log::warn!("--no-sign flag detected: Signing will be skipped.");
}
Expand All @@ -99,42 +97,38 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
let config = get_config(
target,
&options.config.iter().map(|c| &c.0).collect::<Vec<_>>(),
dirs.tauri,
)?;

let mut interface = AppInterface::new(
config.lock().unwrap().as_ref().unwrap(),
options.target.clone(),
)?;

let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
let mut interface = AppInterface::new(&config, options.target.clone(), dirs.tauri)?;

setup(&interface, &mut options, config_, false)?;
setup(&interface, &mut options, &config, false, dirs)?;

if let Some(minimum_system_version) = &config_.bundle.macos.minimum_system_version {
if let Some(minimum_system_version) = &config.bundle.macos.minimum_system_version {
std::env::set_var("MACOSX_DEPLOYMENT_TARGET", minimum_system_version);
}

let app_settings = interface.app_settings();
let interface_options = options.clone().into();

let out_dir = app_settings.out_dir(&interface_options)?;
let out_dir = app_settings.out_dir(&interface_options, dirs.tauri)?;

let bin_path = interface.build(interface_options)?;
let bin_path = interface.build(interface_options, dirs)?;

log::info!(action ="Built"; "application at: {}", tauri_utils::display_path(bin_path));

let app_settings = interface.app_settings();

if !options.no_bundle && (config_.bundle.active || options.bundles.is_some()) {
if !options.no_bundle && (config.bundle.active || options.bundles.is_some()) {
crate::bundle::bundle(
&options.into(),
verbosity,
ci,
&interface,
&*app_settings,
config_,
&config,
&out_dir,
dirs,
)?;
}

Expand All @@ -146,21 +140,20 @@ pub fn setup(
options: &mut Options,
config: &ConfigMetadata,
mobile: bool,
dirs: &Dirs,
) -> Result<()> {
let tauri_path = tauri_dir();

// TODO: Maybe optimize this to run in parallel in the future
// see https://github.com/tauri-apps/tauri/pull/13993#discussion_r2280697117
log::info!("Looking up installed tauri packages to check mismatched versions...");
if let Err(error) = check_mismatched_packages(frontend_dir(), tauri_path) {
if let Err(error) = check_mismatched_packages(dirs.frontend, dirs.tauri) {
if options.ignore_version_mismatches {
log::error!("{error}");
} else {
return Err(error);
}
}

set_current_dir(tauri_path).context("failed to set current directory")?;
set_current_dir(dirs.tauri).context("failed to set current directory")?;

let bundle_identifier_source = config
.find_bundle_identifier_overwriter()
Expand Down Expand Up @@ -191,7 +184,13 @@ pub fn setup(
}

if let Some(before_build) = config.build.before_build_command.clone() {
helpers::run_hook("beforeBuildCommand", before_build, interface, options.debug)?;
helpers::run_hook(
"beforeBuildCommand",
before_build,
interface,
options.debug,
dirs.frontend,
)?;
}

if let Some(FrontendDist::Directory(web_asset_path)) = &config.build.frontend_dist {
Expand Down Expand Up @@ -219,7 +218,7 @@ pub fn setup(

// Issue #13287 - Allow the use of target dir inside frontendDist/distDir
// https://github.com/tauri-apps/tauri/issues/13287
let target_path = get_cargo_target_dir(&options.args)?;
let target_path = get_cargo_target_dir(&options.args, dirs.tauri)?;
let mut out_folders = Vec::new();
if let Ok(web_asset_canonical) = dunce::canonicalize(web_asset_path) {
if let Ok(relative_path) = target_path.strip_prefix(&web_asset_canonical) {
Expand Down
35 changes: 19 additions & 16 deletions crates/tauri-cli/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
error::{Context, ErrorExt},
helpers::{
self,
app_paths::tauri_dir,
config::{get as get_config, ConfigMetadata},
app_paths::Dirs,
config::{get_config, ConfigMetadata},
updater_signature,
},
interface::{AppInterface, AppSettings, Interface},
Expand Down Expand Up @@ -118,7 +118,7 @@ impl From<crate::build::Options> for Options {
}

pub fn command(options: Options, verbosity: u8) -> crate::Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let ci = options.ci;

Expand All @@ -131,36 +131,31 @@ pub fn command(options: Options, verbosity: u8) -> crate::Result<()> {
let config = get_config(
target,
&options.config.iter().map(|c| &c.0).collect::<Vec<_>>(),
dirs.tauri,
)?;

let interface = AppInterface::new(
config.lock().unwrap().as_ref().unwrap(),
options.target.clone(),
)?;

let tauri_path = tauri_dir();
std::env::set_current_dir(tauri_path).context("failed to set current directory")?;
let interface = AppInterface::new(&config, options.target.clone(), dirs.tauri)?;

let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
std::env::set_current_dir(dirs.tauri).context("failed to set current directory")?;

if let Some(minimum_system_version) = &config_.bundle.macos.minimum_system_version {
if let Some(minimum_system_version) = &config.bundle.macos.minimum_system_version {
std::env::set_var("MACOSX_DEPLOYMENT_TARGET", minimum_system_version);
}

let app_settings = interface.app_settings();
let interface_options = options.clone().into();

let out_dir = app_settings.out_dir(&interface_options)?;
let out_dir = app_settings.out_dir(&interface_options, dirs.tauri)?;

bundle(
&options,
verbosity,
ci,
&interface,
&*app_settings,
config_,
&config,
&out_dir,
&dirs,
)
}

Expand All @@ -173,6 +168,7 @@ pub fn bundle<A: AppSettings>(
app_settings: &A,
config: &ConfigMetadata,
out_dir: &Path,
dirs: &Dirs,
) -> crate::Result<()> {
let package_types: Vec<PackageType> = if let Some(bundles) = &options.bundles {
bundles.iter().map(|bundle| bundle.0).collect::<Vec<_>>()
Expand All @@ -198,12 +194,19 @@ pub fn bundle<A: AppSettings>(
before_bundle,
interface,
options.debug,
dirs.frontend,
)?;
}
}

let mut settings = app_settings
.get_bundler_settings(options.clone().into(), config, out_dir, package_types)
.get_bundler_settings(
options.clone().into(),
config,
out_dir,
package_types,
dirs.tauri,
)
.with_context(|| "failed to build bundler settings")?;
settings.set_no_sign(options.no_sign);

Expand Down
Loading