]> Git Repo - pico-vscode.git/blob - src/utils/cmakeUtil.mts
Version check and settings check improvements
[pico-vscode.git] / src / utils / cmakeUtil.mts
1 import { exec } from "child_process";
2 import { workspace, type Uri, window, ProgressLocation } from "vscode";
3 import {
4   checkForRequirements,
5   showRquirementsNotMetErrorMessage,
6 } from "./requirementsUtil.mjs";
7 import { join } from "path";
8 import { getSDKAndToolchainPath } from "./picoSDKUtil.mjs";
9 import type Settings from "../settings.mjs";
10 import { SettingsKey } from "../settings.mjs";
11
12 export async function configureCmakeNinja(
13   folder: Uri,
14   settings: Settings
15 ): Promise<boolean> {
16   try {
17     // check if CMakeLists.txt exists in the root folder
18     await workspace.fs.stat(
19       folder.with({ path: join(folder.path, "CMakeLists.txt") })
20     );
21
22     const rquirementsAvailable = await checkForRequirements(settings);
23
24     if (!rquirementsAvailable) {
25       void showRquirementsNotMetErrorMessage();
26
27       return false;
28     }
29
30     void window.withProgress(
31       {
32         location: ProgressLocation.Notification,
33         cancellable: true,
34         title: "Configuring CMake...",
35       },
36       // eslint-disable-next-line @typescript-eslint/require-await
37       async (progress, token) => {
38         const sdkPaths = await getSDKAndToolchainPath(settings);
39         const cmake = settings.getString(SettingsKey.cmakePath) || "cmake";
40
41         // TODO: analyze command result
42         // TODO: option for the user to choose the generator
43         const child = exec(`${cmake} -G Ninja -S . -B ./build`, {
44           cwd: folder.fsPath,
45           env: {
46             ...process.env,
47             // TODO: set PICO_SDK_PATH
48             // eslint-disable-next-line @typescript-eslint/naming-convention
49             PICO_SDK_PATH: sdkPaths?.[0],
50             // eslint-disable-next-line @typescript-eslint/naming-convention
51             PICO_TOOLCHAIN_PATH: sdkPaths?.[1],
52           },
53         });
54
55         //child.stdout?.on("data", data => {});
56         child.on("close", () => {
57           progress.report({ increment: 100 });
58         });
59         child.on("exit", () => {
60           progress.report({ increment: 100 });
61         });
62
63         token.onCancellationRequested(() => {
64           child.kill();
65         });
66       }
67     );
68
69     return true;
70   } catch (e) {
71     return false;
72   }
73 }
This page took 0.027175 seconds and 4 git commands to generate.