[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
This commit is contained in:
Nikolay Chashnikov
2024-10-03 16:23:31 +02:00
committed by intellij-monorepo-bot
parent 1a16d06b5e
commit b662dca93f
4 changed files with 33 additions and 14 deletions

View File

@@ -33,6 +33,7 @@
"-Dproduct.property=product.value"
],
"mainClass": "com.intellij.idea.CustomMain",
"envVarBaseName": "CUSTOM_XPLAT",
"dataDirectoryName": "XPlatLauncherTestCustom"
}
]

View File

@@ -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<ProductInfo> {
Ok(product_info)
}
pub struct ProductLaunchInfo {
pub product_info_launch_field: ProductInfoLaunchField,
pub custom_env_var_base_name: Option<String>,
pub custom_data_directory_name: Option<String>,
}
pub fn compute_launch_info(product_info: &ProductInfo, command_name: Option<&String>)
-> Result<(ProductInfoLaunchField, Option<String>)> {
-> Result<ProductLaunchInfo> {
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)

View File

@@ -289,6 +289,7 @@ pub struct ProductInfoCustomCommandField {
#[serde(default = "Vec::new")]
pub additionalJvmArguments: Vec<String>,
pub mainClass: Option<String>,
pub envVarBaseName: Option<String>,
pub dataDirectoryName: Option<String>,
}

View File

@@ -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<String>) {
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");