From b662dca93ff800767b60c682e55d65ec704cfbdc Mon Sep 17 00:00:00 2001 From: Nikolay Chashnikov Date: Thu, 3 Oct 2024 16:23:31 +0200 Subject: [PATCH] [launcher] use overriden envVarBaseName in product-info.json for custom commands (RDCT-1735) Since 7ce799261de4c6cd38 the launcher doesn't compute names of the environment variables using 'vmOptionsFilePath' and reads the explicit name instead. So we also need to load the custom env variable base name explicitly for the cases when the frontend process is started from the full IDE. GitOrigin-RevId: 5bf42471b75a6cde3b9bb40c667a840286988496 --- .../product_info_custom_command.json | 1 + native/XPlatLauncher/src/default.rs | 29 ++++++++++++++----- native/XPlatLauncher/src/lib.rs | 1 + .../XPlatLauncher/tests/product_info_tests.rs | 16 ++++++---- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/native/XPlatLauncher/resources/product-info/product_info_custom_command.json b/native/XPlatLauncher/resources/product-info/product_info_custom_command.json index f771d3c85b9b..873a3a631f87 100644 --- a/native/XPlatLauncher/resources/product-info/product_info_custom_command.json +++ b/native/XPlatLauncher/resources/product-info/product_info_custom_command.json @@ -33,6 +33,7 @@ "-Dproduct.property=product.value" ], "mainClass": "com.intellij.idea.CustomMain", + "envVarBaseName": "CUSTOM_XPLAT", "dataDirectoryName": "XPlatLauncherTestCustom" } ] diff --git a/native/XPlatLauncher/src/default.rs b/native/XPlatLauncher/src/default.rs index 8fdc7ed4f492..0c5209be4efd 100644 --- a/native/XPlatLauncher/src/default.rs +++ b/native/XPlatLauncher/src/default.rs @@ -104,14 +104,15 @@ impl DefaultLaunchConfiguration { let caches_home = get_caches_home()?; let product_info = read_product_info(&product_info_file)?; - let (launch_info, custom_data_directory_name) = compute_launch_info(&product_info, args.first())?; + let product_launch_info = compute_launch_info(&product_info, args.first())?; + let launch_info = product_launch_info.product_info_launch_field; let vm_options_rel_path = &launch_info.vmOptionsFilePath; let vm_options_path = product_info_file.parent().context("failed to get product_info_file parent()")?.join(vm_options_rel_path); - let data_directory_name = custom_data_directory_name.unwrap_or(product_info.dataDirectoryName.clone()); + let data_directory_name = product_launch_info.custom_data_directory_name.unwrap_or(product_info.dataDirectoryName.clone()); let user_config_dir = config_home.join(&product_info.productVendor).join(&data_directory_name); let user_caches_dir = caches_home.join(&product_info.productVendor).join(&data_directory_name); let launcher_base_name = Self::get_launcher_base_name(vm_options_rel_path); - let env_var_base_name = product_info.envVarBaseName.clone(); + let env_var_base_name = product_launch_info.custom_env_var_base_name.unwrap_or(product_info.envVarBaseName.clone()); let config = DefaultLaunchConfiguration { product_info, @@ -333,8 +334,14 @@ pub fn read_product_info(product_info_path: &Path) -> Result { Ok(product_info) } +pub struct ProductLaunchInfo { + pub product_info_launch_field: ProductInfoLaunchField, + pub custom_env_var_base_name: Option, + pub custom_data_directory_name: Option, +} + pub fn compute_launch_info(product_info: &ProductInfo, command_name: Option<&String>) - -> Result<(ProductInfoLaunchField, Option)> { + -> Result { if product_info.launch.len() != 1 { bail!("Malformed product descriptor (expecting 1 'launch' record, got {})", product_info.launch.len()) @@ -354,9 +361,13 @@ pub fn compute_launch_info(product_info: &ProductInfo, command_name: Option<&Str }; let result = match custom_command_data { - None => (launch_data.clone(), None), - Some(custom_command_data) => { - (ProductInfoLaunchField { + None => ProductLaunchInfo { + product_info_launch_field: launch_data.clone(), + custom_env_var_base_name: None, + custom_data_directory_name: None + }, + Some(custom_command_data) => ProductLaunchInfo { + product_info_launch_field: ProductInfoLaunchField { vmOptionsFilePath: custom_command_data.vmOptionsFilePath.clone().unwrap_or(launch_data.vmOptionsFilePath.clone()), bootClassPathJarNames: if !custom_command_data.bootClassPathJarNames.is_empty() { custom_command_data.bootClassPathJarNames.clone() @@ -372,7 +383,9 @@ pub fn compute_launch_info(product_info: &ProductInfo, command_name: Option<&Str }, mainClass: custom_command_data.mainClass.clone().unwrap_or(launch_data.mainClass.clone()), customCommands: None - }, custom_command_data.dataDirectoryName.clone()) + }, + custom_env_var_base_name: custom_command_data.envVarBaseName.clone(), + custom_data_directory_name: custom_command_data.dataDirectoryName.clone() } }; Ok(result) diff --git a/native/XPlatLauncher/src/lib.rs b/native/XPlatLauncher/src/lib.rs index 8696abe013a2..ac4a33816925 100644 --- a/native/XPlatLauncher/src/lib.rs +++ b/native/XPlatLauncher/src/lib.rs @@ -289,6 +289,7 @@ pub struct ProductInfoCustomCommandField { #[serde(default = "Vec::new")] pub additionalJvmArguments: Vec, pub mainClass: Option, + pub envVarBaseName: Option, pub dataDirectoryName: Option, } diff --git a/native/XPlatLauncher/tests/product_info_tests.rs b/native/XPlatLauncher/tests/product_info_tests.rs index db2b896f6061..4cf03d1c5b99 100644 --- a/native/XPlatLauncher/tests/product_info_tests.rs +++ b/native/XPlatLauncher/tests/product_info_tests.rs @@ -3,7 +3,7 @@ #[cfg(test)] mod tests { use std::env; - use xplat_launcher::default::{compute_launch_info, read_product_info}; + use xplat_launcher::default::{compute_launch_info, read_product_info, ProductLaunchInfo}; use xplat_launcher::ProductInfoLaunchField; #[test] @@ -32,24 +32,28 @@ mod tests { } fn assert_custom_values(file_name: &str, command: Option<&String>) { - let (launch_info, custom_data_directory_name) = load_launch_info(file_name, command); + let product_launch_info = load_launch_info(file_name, command); + let launch_info = product_launch_info.product_info_launch_field; assert_eq!(launch_info.vmOptionsFilePath, "bin/xplat64custom.vmoptions"); assert_eq!(launch_info.bootClassPathJarNames, [String::from("custom.jar")].to_vec()); assert_eq!(launch_info.additionalJvmArguments, [String::from("-Dproduct.property=product.value")].to_vec()); assert_eq!(launch_info.mainClass, "com.intellij.idea.CustomMain"); - assert_eq!(custom_data_directory_name, Some(String::from("XPlatLauncherTestCustom"))) + assert_eq!(product_launch_info.custom_env_var_base_name, Some(String::from("CUSTOM_XPLAT"))); + assert_eq!(product_launch_info.custom_data_directory_name, Some(String::from("XPlatLauncherTestCustom"))) } fn assert_default_values(file_name: &str, command: Option<&String>) { - let (launch_info, custom_data_directory_name) = load_launch_info(file_name, command); + let product_launch_info = load_launch_info(file_name, command); + let launch_info = product_launch_info.product_info_launch_field; assert_eq!(launch_info.vmOptionsFilePath, "bin/xplat64.vmoptions"); assert_eq!(launch_info.bootClassPathJarNames, [String::from("app.jar")].to_vec()); assert_eq!(launch_info.additionalJvmArguments, [String::from("-Didea.paths.selector=XPlatLauncherTest")].to_vec()); assert_eq!(launch_info.mainClass, "com.intellij.idea.TestMain"); - assert!(custom_data_directory_name.is_none(), "Custom data directory must not be set") + assert!(product_launch_info.custom_env_var_base_name.is_none(), "Custom env var base name must not be set"); + assert!(product_launch_info.custom_data_directory_name.is_none(), "Custom data directory must not be set") } - fn load_launch_info(file_name: &str, command: Option<&String>) -> (ProductInfoLaunchField, Option) { + fn load_launch_info(file_name: &str, command: Option<&String>) -> ProductLaunchInfo { let project_root = env::current_dir().expect("Failed to get project root"); let product_info_path = project_root.join(format!("resources/product-info/{file_name}")); let product_info = read_product_info(&product_info_path).expect("product-info must be loaded");