fix(cli.rs): copy resources and binaries on dev, closes #1298 (#1946)

This commit is contained in:
Lucas Fernandes Nogueira 2021-06-04 01:58:15 -03:00 committed by GitHub
parent 8be35ced78
commit 8f29a260e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 91 additions and 26 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---
The process of copying binaries and resources to `project_out_directory` was moved to the Tauri CLI.

View File

@ -0,0 +1,5 @@
---
"cli.rs": patch
---
Copy resources and binaries to `OUT_DIR` on `tauri dev` command.

View File

@ -73,9 +73,6 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
});
}
settings.copy_resources(settings.project_out_directory())?;
settings.copy_binaries(settings.project_out_directory())?;
print_finished(&bundles)?;
Ok(bundles)

View File

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
use anyhow::Context;
use tauri_bundler::bundle::{bundle_project, PackageType, SettingsBuilder};
use tauri_bundler::bundle::{bundle_project, PackageType};
use crate::helpers::{
app_paths::{app_dir, tauri_dir},
@ -16,8 +16,6 @@ use crate::helpers::{
use std::{env::set_current_dir, fs::rename, path::PathBuf, process::Command};
mod rust;
#[derive(Default)]
pub struct Build {
runner: Option<String>,
@ -124,10 +122,10 @@ impl Build {
cargo_features.extend(features);
}
rust::build_project(runner, &self.target, cargo_features, self.debug)
crate::interface::rust::build_project(runner, &self.target, cargo_features, self.debug)
.with_context(|| "failed to build app")?;
let app_settings = rust::AppSettings::new(&config_)?;
let app_settings = crate::interface::rust::AppSettings::new(&config_)?;
let out_dir = app_settings
.get_out_dir(self.debug)
@ -162,17 +160,8 @@ impl Build {
};
std::fs::write(out_dir.join(filename), vcruntime_msm)?;
}
let mut settings_builder = SettingsBuilder::new()
.package_settings(app_settings.get_package_settings())
.bundle_settings(app_settings.get_bundle_settings(&config_, &manifest)?)
.binaries(app_settings.get_binaries(&config_)?)
.project_out_directory(out_dir);
if self.verbose {
settings_builder = settings_builder.verbose();
}
if let Some(names) = self.bundles {
let package_types = if let Some(names) = self.bundles {
let mut types = vec![];
for name in names {
if name == "none" {
@ -190,8 +179,7 @@ impl Build {
}
}
}
settings_builder = settings_builder.package_types(types);
Some(types)
} else if let Some(targets) = &config_.tauri.bundle.targets {
let mut types = vec![];
let targets = targets.to_vec();
@ -209,14 +197,26 @@ impl Build {
}
}
}
settings_builder = settings_builder.package_types(types);
Some(types)
} else {
None
}
}
} else {
None
};
// Bundle the project
let settings = settings_builder
.build()
.with_context(|| "failed to build bundler settings")?;
let settings = crate::interface::get_bundler_settings(
app_settings,
&manifest,
&config_,
&out_dir,
self.verbose,
package_types,
)
.with_context(|| "failed to build bundler settings")?;
settings.copy_resources(&out_dir)?;
settings.copy_binaries(&out_dir)?;
let bundles = bundle_project(settings).with_context(|| "failed to bundle project")?;

View File

@ -97,6 +97,27 @@ impl Dev {
let config = get_config(merge_config.as_deref())?;
let mut process: Arc<SharedChild>;
let (settings, out_dir) = {
let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
let app_settings = crate::interface::rust::AppSettings::new(&config_)?;
let out_dir = app_settings
.get_out_dir(true)
.with_context(|| "failed to get project out directory")?;
let settings = crate::interface::get_bundler_settings(
app_settings,
&Default::default(),
&config_,
&out_dir,
false,
None,
)
.with_context(|| "failed to build bundler settings")?;
(settings, out_dir)
};
settings.copy_resources(&out_dir)?;
settings.copy_binaries(&out_dir)?;
if let Some(before_dev) = &config
.lock()
.unwrap()

View File

@ -17,6 +17,7 @@ use std::{
path::Path,
};
#[derive(Default)]
pub struct Manifest {
pub features: HashSet<String>,
}

View File

@ -0,0 +1,35 @@
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
pub mod rust;
use std::path::Path;
use crate::helpers::{config::Config, manifest::Manifest};
use tauri_bundler::bundle::{PackageType, Settings, SettingsBuilder};
pub fn get_bundler_settings(
app_settings: rust::AppSettings,
manifest: &Manifest,
config: &Config,
out_dir: &Path,
verbose: bool,
package_types: Option<Vec<PackageType>>,
) -> crate::Result<Settings> {
let mut settings_builder = SettingsBuilder::new()
.package_settings(app_settings.get_package_settings())
.bundle_settings(app_settings.get_bundle_settings(config, manifest)?)
.binaries(app_settings.get_binaries(&config)?)
.project_out_directory(out_dir);
if verbose {
settings_builder = settings_builder.verbose();
}
if let Some(types) = package_types {
settings_builder = settings_builder.package_types(types);
}
settings_builder.build().map_err(Into::into)
}

View File

@ -12,6 +12,7 @@ mod dev;
mod helpers;
mod info;
mod init;
mod interface;
mod sign;
// temporary fork from https://github.com/mitsuhiko/console until 0.14.1+ release