Skip to content

Commit 929a8d2

Browse files
committed
Fix python and sdk installation for new rust projects
Signed-off-by: paulober <[email protected]>
1 parent 38adbdc commit 929a8d2

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

src/utils/download.mts

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
githubApiUnauthorized,
3939
HTTP_STATUS_FORBIDDEN,
4040
HTTP_STATUS_OK,
41+
SDK_REPOSITORY_URL,
4142
} from "./githubREST.mjs";
4243
import { unxzFile, unzipFile } from "./downloadHelpers.mjs";
4344
import type { Writable } from "stream";
@@ -52,6 +53,7 @@ import {
5253
} from "./sharedConstants.mjs";
5354
import { compareGe } from "./semverUtil.mjs";
5455
import VersionBundlesLoader from "./versionBundles.mjs";
56+
import findPython, { showPythonNotFoundError } from "./pythonHelper.mjs";
5557

5658
/// Translate nodejs platform names to ninja platform names
5759
const NINJA_PLATFORMS: { [key: string]: string } = {
@@ -574,6 +576,8 @@ export async function downloadAndInstallSDK(
574576
(await cloneRepository(repositoryUrl, version, targetDirectory, gitPath))
575577
) {
576578
settings.reload();
579+
580+
// TODO: should already be done by rust project panel
577581
// check python requirements
578582
const python3Exe: string =
579583
python3Path ||
@@ -589,7 +593,10 @@ export async function downloadAndInstallSDK(
589593
"Python3 is not installed and could not be downloaded."
590594
);
591595

592-
void window.showErrorMessage("Python3 is not installed and in PATH.");
596+
void window.showErrorMessage(
597+
"Python 3 was not found. " +
598+
"Please install Python 3 to complete Pico SDK setup."
599+
);
593600

594601
return false;
595602
}
@@ -1068,10 +1075,10 @@ export async function downloadAndInstallOpenOCD(
10681075
? "-aarch64"
10691076
: "-x86_64"
10701077
: process.platform === "darwin"
1071-
? process.arch === "arm64"
1072-
? "-arm64"
1073-
: "-x86_64"
1074-
: ""
1078+
? process.arch === "arm64"
1079+
? "-arm64"
1080+
: "-x86_64"
1081+
: ""
10751082
}-${TOOLS_PLATFORMS[process.platform]}.${assetExt}`;
10761083

10771084
const extraCallback = (): void => {
@@ -1327,16 +1334,66 @@ export async function installLatestRustRequirements(
13271334
return false;
13281335
}
13291336

1330-
const supportedToolchains = await getSupportedToolchains();
1337+
// install python (if necessary)
1338+
const python3Path = await findPython();
1339+
if (!python3Path) {
1340+
Logger.error(LoggerSource.downloader, "Failed to find Python3 executable.");
1341+
showPythonNotFoundError();
1342+
1343+
return false;
1344+
}
13311345

13321346
let result = await window.withProgress(
1347+
{
1348+
location: ProgressLocation.Notification,
1349+
title: "Downloading and installing SDK",
1350+
cancellable: false,
1351+
},
1352+
async progress2 => {
1353+
const result = await downloadAndInstallSDK(
1354+
latest[0],
1355+
SDK_REPOSITORY_URL,
1356+
// python3Path is only possible undefined if downloaded and
1357+
// there is already checked and returned if this happened
1358+
python3Path.replace(HOME_VAR, homedir().replaceAll("\\", "/"))
1359+
);
1360+
1361+
if (!result) {
1362+
Logger.error(
1363+
LoggerSource.downloader,
1364+
"Failed to download and install SDK."
1365+
);
1366+
progress2.report({
1367+
message: "Failed - Make sure all requirements are met.",
1368+
increment: 100,
1369+
});
1370+
1371+
void window.showErrorMessage(
1372+
"Failed to download and install SDK. " +
1373+
"Make sure all requirements are met."
1374+
);
1375+
1376+
return false;
1377+
}
1378+
1379+
return true;
1380+
}
1381+
);
1382+
1383+
if (!result) {
1384+
return false;
1385+
}
1386+
1387+
const supportedToolchains = await getSupportedToolchains();
1388+
1389+
result = await window.withProgress(
13331390
{
13341391
location: ProgressLocation.Notification,
13351392
title: `Downloading ARM Toolchain for debugging...`,
13361393
},
13371394
async progress => {
13381395
const toolchain = supportedToolchains.find(
1339-
t => t.version === latest.toolchain
1396+
t => t.version === latest[1].toolchain
13401397
);
13411398

13421399
if (toolchain === undefined) {
@@ -1374,7 +1431,7 @@ export async function installLatestRustRequirements(
13741431
},
13751432
async progress => {
13761433
const toolchain = supportedToolchains.find(
1377-
t => t.version === latest.riscvToolchain
1434+
t => t.version === latest[1].riscvToolchain
13781435
);
13791436

13801437
if (toolchain === undefined) {
@@ -1437,11 +1494,14 @@ export async function installLatestRustRequirements(
14371494
async progress => {
14381495
let progressState = 0;
14391496

1440-
return downloadAndInstallPicotool(latest.picotool, (prog: Progress) => {
1441-
const percent = prog.percent * 100;
1442-
progress.report({ increment: percent - progressState });
1443-
progressState = percent;
1444-
});
1497+
return downloadAndInstallPicotool(
1498+
latest[1].picotool,
1499+
(prog: Progress) => {
1500+
const percent = prog.percent * 100;
1501+
progress.report({ increment: percent - progressState });
1502+
progressState = percent;
1503+
}
1504+
);
14451505
}
14461506
);
14471507
if (!result) {

src/utils/rustUtil.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ export async function checkRustInstallation(): Promise<boolean> {
262262
if (!rustupOk) {
263263
void window
264264
.showErrorMessage(
265-
"Rustup is not installed. Please install it manually and restart VS Code.",
265+
"Rustup is not installed. Please install it " +
266+
"manually and restart VS Code.",
266267
"Install"
267268
)
268269
.then(result => {

src/utils/versionBundles.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ export default class VersionBundlesLoader {
129129
return chosenBundle;
130130
}
131131

132-
public async getLatest(): Promise<VersionBundle | undefined> {
132+
public async getLatest(): Promise<[string, VersionBundle] | undefined> {
133133
if (this.bundles === undefined) {
134134
await this.loadBundles();
135135
}
136136

137137
return Object.entries(this.bundles ?? {}).sort(
138138
(a, b) => compare(a[0], b[0]) * -1
139-
)[0][1];
139+
)[0];
140140
}
141141

142142
public async getLatestSDK(): Promise<string | undefined> {

0 commit comments

Comments
 (0)