2023-02-19 14:21:50 +00:00
|
|
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
2023-05-26 16:45:20 +00:00
|
|
|
use super::{detect_target_ok, ensure_init, env, get_app, get_config, read_options, MobileTarget};
|
|
|
|
|
use crate::{helpers::config::get as get_tauri_config, Result};
|
2022-10-31 12:49:22 +00:00
|
|
|
use clap::{ArgAction, Parser};
|
2022-08-23 00:59:17 +00:00
|
|
|
|
2022-12-06 12:19:04 +00:00
|
|
|
use tauri_mobile::{
|
2022-08-24 19:06:14 +00:00
|
|
|
android::target::Target,
|
2022-08-26 12:24:23 +00:00
|
|
|
opts::Profile,
|
2022-08-23 00:59:17 +00:00
|
|
|
target::{call_for_targets_with_fallback, TargetTrait},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Parser)]
|
|
|
|
|
pub struct Options {
|
|
|
|
|
/// Targets to build.
|
|
|
|
|
#[clap(
|
|
|
|
|
short,
|
|
|
|
|
long = "target",
|
2022-10-31 12:49:22 +00:00
|
|
|
action = ArgAction::Append,
|
|
|
|
|
num_args(0..),
|
2022-08-23 00:59:17 +00:00
|
|
|
default_value = Target::DEFAULT_KEY,
|
|
|
|
|
value_parser(clap::builder::PossibleValuesParser::new(Target::name_list()))
|
|
|
|
|
)]
|
|
|
|
|
targets: Option<Vec<String>>,
|
|
|
|
|
/// Builds with the release flag
|
|
|
|
|
#[clap(short, long)]
|
|
|
|
|
release: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn command(options: Options) -> Result<()> {
|
|
|
|
|
let profile = if options.release {
|
|
|
|
|
Profile::Release
|
|
|
|
|
} else {
|
|
|
|
|
Profile::Debug
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-12 16:18:23 +00:00
|
|
|
let tauri_config = get_tauri_config(tauri_utils::platform::Target::Android, None)?;
|
2023-05-26 16:45:20 +00:00
|
|
|
|
|
|
|
|
let (config, metadata, cli_options) = {
|
|
|
|
|
let tauri_config_guard = tauri_config.lock().unwrap();
|
|
|
|
|
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
|
|
|
|
let cli_options = read_options(&tauri_config_.tauri.bundle.identifier);
|
|
|
|
|
let (config, metadata) = get_config(&get_app(tauri_config_), tauri_config_, &cli_options);
|
|
|
|
|
(config, metadata, cli_options)
|
|
|
|
|
};
|
|
|
|
|
ensure_init(config.project_dir(), MobileTarget::Android)?;
|
|
|
|
|
|
|
|
|
|
let env = env()?;
|
|
|
|
|
|
|
|
|
|
call_for_targets_with_fallback(
|
|
|
|
|
options.targets.unwrap_or_default().iter(),
|
|
|
|
|
&detect_target_ok,
|
|
|
|
|
&env,
|
|
|
|
|
|target: &Target| {
|
|
|
|
|
target
|
|
|
|
|
.build(
|
|
|
|
|
&config,
|
|
|
|
|
&metadata,
|
|
|
|
|
&env,
|
|
|
|
|
cli_options.noise_level,
|
|
|
|
|
true,
|
|
|
|
|
profile,
|
|
|
|
|
)
|
|
|
|
|
.map_err(Into::into)
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| anyhow::anyhow!(e.to_string()))?
|
2022-08-23 00:59:17 +00:00
|
|
|
}
|