дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
fix(cmake): discover targets when configuration case differs (#8248)
A CMake preset's build type (Debug) was compared case-sensitively with the codemodel's configuration names, so a codemodel reporting `debug` / `release` yielded no targets. The profile now picks the configuration with the exact name, else the only one that matches ignoring ASCII case; several case-insensitive matches stay unmatched rather than guessing. Co-authored-by: HyperWinX <[email protected]>
Цей коміт міститься в:
1 джерело
aa124276b2
коміт
251f3953fa
1 file changed
+62
-1
@@ -327,11 +327,19 @@ fn targets(
|
||||
return;
|
||||
}
|
||||
let canonical_root = dunce::canonicalize(&source_root).unwrap_or(source_root);
|
||||
let matched_name = profile.and_then(|profile| {
|
||||
let names = model.configurations.iter().map(|configuration| configuration.name.as_str());
|
||||
names.clone().find(|&name| name == profile.build_type).or_else(|| {
|
||||
let mut matching = names.filter(|name| name.eq_ignore_ascii_case(&profile.build_type));
|
||||
let name = matching.next()?;
|
||||
matching.next().is_none().then_some(name)
|
||||
})
|
||||
});
|
||||
for (index, configuration) in model.configurations.iter().enumerate() {
|
||||
let name = configuration.name.as_str();
|
||||
// The profile's configuration; with CLion's "Default" build type (empty), the first one.
|
||||
let wanted = |p: &CMakeProfile| {
|
||||
if p.build_type.is_empty() { index == 0 } else { name.is_empty() || name == p.build_type }
|
||||
if p.build_type.is_empty() { index == 0 } else { name.is_empty() || Some(name) == matched_name }
|
||||
};
|
||||
if profile.is_some_and(|p| !wanted(p)) {
|
||||
continue;
|
||||
@@ -731,6 +739,59 @@ mod tests {
|
||||
assert!(root.path().join("out/dev/.cmake/api/v1/query/client-openidea/codemodel-v2").is_file());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preset_targets_match_the_codemodel_configuration() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let root = root.path();
|
||||
fs::write(root.join("CMakeLists.txt"), "project(app)").unwrap();
|
||||
fs::write(
|
||||
root.join("CMakePresets.json"),
|
||||
r#"{"version":3,"configurePresets":[{"name":"dev","binaryDir":"out","cacheVariables":{"CMAKE_BUILD_TYPE":"Debug"}}]}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let settings = ide_core::settings::CMakeSettings { enabled_presets: vec!["dev".into()], ..Default::default() };
|
||||
let profiles = presets::profiles(root, &settings, &[]).unwrap();
|
||||
assert_eq!(profiles[0].build_type, "Debug");
|
||||
|
||||
for (names, expected) in [
|
||||
(&["Release", "debug"][..], Some("debug")),
|
||||
(&["debug", "DEBUG", "Debug"][..], Some("Debug")),
|
||||
(&["debug", "DEBUG"][..], None),
|
||||
(&["Release"][..], None),
|
||||
(&["Release", ""][..], Some("Debug")),
|
||||
] {
|
||||
let configurations: Vec<_> = names
|
||||
.iter()
|
||||
.map(|name| serde_json::json!({"name": name, "targets": [{"jsonFile": "app.json"}]}))
|
||||
.collect();
|
||||
file_api::tests::write_reply(
|
||||
&root.join("out"),
|
||||
&[(
|
||||
"codemodel",
|
||||
2,
|
||||
"model.json",
|
||||
serde_json::json!({"paths": {"source": root}, "configurations": configurations}),
|
||||
)],
|
||||
&[(
|
||||
"app.json",
|
||||
serde_json::json!({"name": "app", "type": "EXECUTABLE", "artifacts": [{"path": "app"}]}),
|
||||
)],
|
||||
);
|
||||
let mut configs = Vec::new();
|
||||
detect(root, Some(&profiles), &mut configs);
|
||||
let target_ids: Vec<_> =
|
||||
configs.iter().filter(|c| c.id.starts_with("cmake:profile:target:")).map(|c| c.id.as_str()).collect();
|
||||
if let Some(expected) = expected {
|
||||
let id = "cmake:profile:target:app:build";
|
||||
assert_eq!(target_ids, [id, "cmake:profile:target:app"], "{names:?}");
|
||||
let build = configs.iter().find(|c| c.id == id).unwrap();
|
||||
assert_eq!(build.args[..6], ["--build", "out", "--target", "app", "--config", expected]);
|
||||
} else {
|
||||
assert!(target_ids.is_empty(), "{names:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_default_build_type_passes_no_configuration() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Заблокувати користувача