Файли
openidea/src/features/run/cmake.ts
T
l0ng-ai 192b59801a fix(build): build selected CMake targets in the Build window (#2061)
Fixes #2039

CMake configurations bypassed the Build executor and Build Project ignored the selected target, so CMake projects had no hammer, configure/build output went to Run tabs, and generated names carried a "(build)" suffix (the build directory) that read like an action. Now the toolbar hammer and Cmd+F9 build the selected CMake target and profile without running it; configure/build prerequisites of Run, Debug and CTest run in the Build window and a failed build prevents the launch; generated executables are "CMake Application" configurations; generated names add profile/build directory only when needed to tell them apart ("hello", or "hello [Debug · build-debug/]"). Saved names and configuration ids are kept. Verified on macOS.
2026-11-08 04:48:14 +08:00

30 рядки
1.3 KiB
TypeScript

import { executeAction, getAction } from "@/platform/actions";
import { getContext } from "@/platform/context";
import type { RunConfig } from "@/platform/ipc";
export function isCMakeBuild(config: RunConfig): boolean {
return config.kind === "cmake" && ["-S", "--build"].includes(config.args[0] ?? "");
}
/** The selected target's build, including saved configurations and CTest. */
export function cmakeBuildId(config: RunConfig | undefined, configs: readonly RunConfig[]): string | null {
if (!config) return null;
if (isCMakeBuild(config)) {
if (config.args[0] === "--build") return config.id;
const build = configs.find((c) => c.id !== config.id && c.id === config.id.replace(/:configure$/, ":build"));
return build && isCMakeBuild(build) ? build.id : null;
}
return (
config.beforeLaunch
?.filter((task) => task.kind === "run" || task.kind === "build")
.map((task) => configs.find((c) => c.id === task.target))
.find((c) => c && isCMakeBuild(c))?.id ?? null
);
}
export async function buildCMake(id: string, activate = false): Promise<string | null> {
if (!getAction("build.buildProject")) return "Building is not available";
if (!(await executeAction("build.buildProject", { cmake: id, activate }))) return "A build is already running";
return getContext()["build.lastStatus"] === "success" ? null : "Build failed";
}