Skip to content

Commit

Permalink
feat(cli.rs): build tools info (#2618)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Sep 21, 2021
1 parent 84f6e3e commit d5f07d1
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changes/cli.rs-build-tools-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.rs": patch
---

Add `Visual Studio Build Tools` installed versions to the `info` command output.
14 changes: 1 addition & 13 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,14 @@ use crate::http::{

#[cfg(feature = "system-tray")]
#[non_exhaustive]
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct SystemTray {
pub icon: Option<Icon>,
pub menu: Option<menu::SystemTrayMenu>,
#[cfg(target_os = "macos")]
pub icon_as_template: bool,
}

#[cfg(feature = "system-tray")]
impl Default for SystemTray {
fn default() -> Self {
Self {
icon: None,
menu: None,
#[cfg(target_os = "macos")]
icon_as_template: false,
}
}
}

#[cfg(feature = "system-tray")]
impl SystemTray {
/// Creates a new system tray that only renders an icon.
Expand Down
16 changes: 2 additions & 14 deletions core/tauri-runtime/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub trait TrayHandle: fmt::Debug {
}

/// A window menu.
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct Menu {
pub items: Vec<MenuEntry>,
Expand All @@ -179,12 +179,6 @@ impl Submenu {
}
}

impl Default for Menu {
fn default() -> Self {
Self { items: Vec::new() }
}
}

impl Menu {
/// Creates a new window menu.
pub fn new() -> Self {
Expand Down Expand Up @@ -274,18 +268,12 @@ impl CustomMenuItem {
}

/// A system tray menu.
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct SystemTrayMenu {
pub items: Vec<SystemTrayMenuEntry>,
}

impl Default for SystemTrayMenu {
fn default() -> Self {
Self { items: Vec::new() }
}
}

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct SystemTraySubmenu {
Expand Down
6 changes: 2 additions & 4 deletions core/tauri/src/endpoints/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// SPDX-License-Identifier: MIT

use super::InvokeResponse;
#[cfg(any(windows, target_os = "macos"))]
use crate::api::dialog::window_parent;
#[cfg(any(dialog_open, dialog_save))]
use crate::api::dialog::FileDialogBuilder;
use crate::{
Expand Down Expand Up @@ -145,7 +143,7 @@ pub fn open<R: Runtime>(
let mut dialog_builder = FileDialogBuilder::new();
#[cfg(any(windows, target_os = "macos"))]
{
dialog_builder = dialog_builder.set_parent(&window_parent(window)?);
dialog_builder = dialog_builder.set_parent(&crate::api::dialog::window_parent(window)?);
}
if let Some(default_path) = options.default_path {
if !default_path.exists() {
Expand Down Expand Up @@ -181,7 +179,7 @@ pub fn save<R: Runtime>(
let mut dialog_builder = FileDialogBuilder::new();
#[cfg(any(windows, target_os = "macos"))]
{
dialog_builder = dialog_builder.set_parent(&window_parent(&window)?);
dialog_builder = dialog_builder.set_parent(&crate::api::dialog::window_parent(&window)?);
}
if let Some(default_path) = options.default_path {
dialog_builder = set_default_path(dialog_builder, default_path);
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/updater/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ pub struct Update {
/// Update publish date
pub date: String,
/// Target
#[allow(dead_code)]
target: String,
/// Extract path
extract_path: PathBuf,
Expand Down
2 changes: 2 additions & 0 deletions examples/commands/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use tauri::{command, State, Window};

#[derive(Debug)]
pub struct MyState {
#[allow(dead_code)]
value: u64,
#[allow(dead_code)]
label: String,
}

Expand Down
59 changes: 57 additions & 2 deletions tooling/cli.rs/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ struct VersionMetadata {
struct CargoManifestDependencyPackage {
version: Option<String>,
path: Option<PathBuf>,
#[serde(default)]
features: Vec<String>,
}

#[derive(Clone, Deserialize)]
Expand Down Expand Up @@ -291,6 +289,45 @@ fn webview2_version() -> crate::Result<Option<String>> {
Ok(version)
}

#[cfg(windows)]
fn run_vs_setup_instance() -> std::io::Result<std::process::Output> {
Command::new("powershell")
.args(&["-NoProfile", "-Command"])
.arg("Get-VSSetupInstance")
.output()
}

#[cfg(windows)]
fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
let mut output = run_vs_setup_instance();
if output.is_err() {
Command::new("powershell")
.args(&["-NoProfile", "-Command"])
.arg("Install-Module VSSetup -Scope CurrentUser")
.output()?;
output = run_vs_setup_instance();
}
let output = output?;
let versions = if output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
let mut versions = Vec::new();

let regex = regex::Regex::new(r"Visual Studio Build Tools (?P<version>\d+)").unwrap();
for caps in regex.captures_iter(&stdout) {
versions.push(caps["version"].to_string());
}

if versions.is_empty() {
None
} else {
Some(versions)
}
} else {
None
};
Ok(versions)
}

struct InfoBlock {
section: bool,
key: &'static str,
Expand Down Expand Up @@ -403,6 +440,24 @@ impl Info {

#[cfg(windows)]
VersionBlock::new("Webview2", webview2_version().unwrap_or_default()).display();
#[cfg(windows)]
VersionBlock::new(
"Visual Studio Build Tools",
build_tools_version()
.map(|r| {
let required_string = "(>= 2019 required)";
let multiple_string =
"(multiple versions might conflict; keep only 2019 if build errors occur)";
r.map(|v| match v.len() {
1 if v[0].as_str() < "2019" => format!("{} {}", v[0], required_string),
1 if v[0].as_str() >= "2019" => v[0].clone(),
_ if v.contains(&"2019".into()) => format!("{} {}", v.join(", "), multiple_string),
_ => format!("{} {} {}", v.join(", "), required_string, multiple_string),
})
})
.unwrap_or_default(),
)
.display();

let hook = panic::take_hook();
panic::set_hook(Box::new(|_info| {
Expand Down

0 comments on commit d5f07d1

Please sign in to comment.