RDCT-1171: restore console for remote dev scenario

GitOrigin-RevId: fff34b60f31aa68ff2179e4c82fd00988a1709ff
This commit is contained in:
Ivan Pashchenko
2024-03-15 02:03:17 +00:00
committed by intellij-monorepo-bot
parent f281bac3bb
commit c1dcfea6f6
3 changed files with 24 additions and 3 deletions
+2 -2
View File
@@ -25,7 +25,7 @@ va_list = "0.1.4"
[target.'cfg(target_os = "windows")'.dependencies.windows]
version = "0.51.1"
features = ["Win32_Foundation", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_System_Environment", "Win32_System_Services", "Win32_Security"]
features = ["Win32_Foundation", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_System_Environment", "Win32_System_Services", "Win32_Security", "Win32_System_Console"]
[target.'cfg(target_family = "unix")'.dependencies]
libc = "0.2.142"
@@ -48,7 +48,7 @@ cargo-about = "0.5.7" # generates license report
winresource = "0.1.17"
[dev-dependencies]
tempfile = "3"
tempfile = "3.8.0"
junction = "1.0.0"
[features]
+19 -1
View File
@@ -41,7 +41,8 @@ use serde::{Deserialize, Serialize};
use {
windows::core::{GUID, PWSTR},
windows::Win32::Foundation,
windows::Win32::UI::Shell
windows::Win32::UI::Shell,
windows::Win32::System::Console::{AllocConsole, ATTACH_PARENT_PROCESS, AttachConsole},
};
#[cfg(target_family = "unix")]
@@ -67,6 +68,10 @@ const CLASS_PATH_SEPARATOR: &str = ":";
pub fn main_lib() {
let exe_path = env::current_exe().unwrap_or_else(|_| PathBuf::from(env::args().next().unwrap()));
let remote_dev = exe_path.file_name().unwrap().to_string_lossy().starts_with("remote-dev-server");
if remote_dev {
attach_console();
}
let debug_mode = remote_dev || env::var(DEBUG_MODE_ENV_VAR).is_ok();
if let Err(e) = main_impl(exe_path, remote_dev, debug_mode) {
@@ -75,6 +80,19 @@ pub fn main_lib() {
}
}
#[cfg(target_os = "windows")]
fn attach_console() {
unsafe {
match AttachConsole(ATTACH_PARENT_PROCESS) {
Ok(_) => {}
Err(_) => AllocConsole().expect("Failed to attach to existing console or allocate a new one")
}
}
}
#[cfg(not(target_os = "windows"))]
fn attach_console() { }
fn main_impl(exe_path: PathBuf, remote_dev: bool, debug_mode: bool) -> Result<()> {
let level = if debug_mode { LevelFilter::Debug } else { LevelFilter::Error };
mini_logger::init(level).expect("Cannot initialize the logger");
+3
View File
@@ -1,5 +1,8 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// this attribute doesn't do anything on macos/linux
// same as /SUBSYSTEM:WINDOWS, doesn't allocate/attach to a console by default
#![windows_subsystem = "windows"]
use xplat_launcher::main_lib;
fn main() {