1 import { window } from "vscode";
2 import which from "which";
3 import type Settings from "../settings.mjs";
4 import { SettingsKey } from "../settings.mjs";
5 import { downloadGit } from "./download.mjs";
6 import Logger from "../logger.mjs";
8 export async function showRequirementsNotMetErrorMessage(
11 await window.showErrorMessage(
12 "Development for the Pico (W) requires " +
14 " to be installed and available in the PATH. " +
15 "Please install and restart VS Code."
20 * Checks if all requirements for installing a Pico-SDK are met
21 * TODO: add support for custom compiler and git paths in settings
23 * @returns true if all requirements are met, false otherwise
25 export async function checkForInstallationRequirements(
29 const gitExe: string = gitPath || "git";
30 const compilerExe: string[] = ["clang", "gcc", "cl"];
32 const git: string | null = await which(gitExe, { nothrow: true });
33 //check if any of the compilers is available
34 const compiler: string | null = await Promise.any(
36 .map(compiler => which(compiler, { nothrow: true }))
37 .map(p => p.catch(() => null))
39 // set availability of tools on windows
40 const allToolsAvailable: boolean = process.platform === "win32";
42 let requirementsMet: boolean = true;
44 if (process.platform === "linux") {
45 requirementsMet = false;
46 } else if (process.platform === "darwin") {
47 void window.showErrorMessage(
48 "Installation of the Pico-SDK requires Git to be installed " +
49 "and in PATH. You can install it by running " +
50 "`xcode-select --install` in the terminal and restart your computer."
52 requirementsMet = false;
54 // install if not available
55 const gitDownloaded: string | undefined = await downloadGit();
57 if (gitDownloaded === undefined) {
58 Logger.log("Error: Git is not installed and could not be downloaded.");
59 requirementsMet = false;
61 // if git is downloaded set custom git path
62 await settings.updateGlobal(SettingsKey.gitPath, gitDownloaded);
66 if (!allToolsAvailable) {
67 // only check for compilers if pioasm
68 if (compiler === null) {
69 requirementsMet = false;
73 if (!requirementsMet) {
74 void showInstallationRequirementsNotMetErrorMessage(
76 allToolsAvailable || compiler !== null
80 return requirementsMet;
83 export async function showInstallationRequirementsNotMetErrorMessage(
84 isGitInstalled: boolean,
85 allToolsAvailableOrCompilerInstalled: boolean
87 if (!isGitInstalled && process.platform !== "darwin") {
88 await window.showErrorMessage(
89 "Installation of the Pico-SDK requires Git " +
90 "to be installed and available in the PATH."
93 if (!allToolsAvailableOrCompilerInstalled) {
94 await window.showErrorMessage(
95 "A native C/C++ compiler (clang or gcc) needs to be installed and in " +
96 "PATH for manual compilation of the tools." +
97 "Please install and restart VS Code."