Skip to content

Commit 9d98097

Browse files
committed
Update picotool shell version when switching SDK
Also fix line endings when switching SDK
1 parent b2e2a4e commit 9d98097

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

scripts/pico_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,8 @@ def generateProjectFiles(
10581058
"{codeSdkPath(sdkVersion)}/**"
10591059
],
10601060
"forcedInclude": [
1061-
"{codeSdkPath(sdkVersion)}/src/common/{base_headers_folder_name}/include/pico.h",
1062-
"${{workspaceFolder}}/build/generated/pico_base/pico/config_autogen.h"
1061+
"${{workspaceFolder}}/build/generated/pico_base/pico/config_autogen.h",
1062+
"{codeSdkPath(sdkVersion)}/src/common/{base_headers_folder_name}/include/pico.h"
10631063
],
10641064
"defines": [],
10651065
"compilerPath": "{cPath}",

src/utils/cmakeUtil.mts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { homedir } from "os";
1212
import which from "which";
1313
import { compareLt } from "./semverUtil.mjs";
1414
import { buildCMakeIncPath } from "./download.mjs";
15+
import {EOL} from "os";
1516

1617
export const CMAKE_DO_NOT_EDIT_HEADER_PREFIX =
1718
// eslint-disable-next-line max-len
@@ -350,19 +351,19 @@ export async function cmakeUpdateSDK(
350351

351352
let modifiedContent = content.replace(
352353
updateSectionRegex,
353-
`# ${CMAKE_DO_NOT_EDIT_HEADER_PREFIX}\n` +
354-
"if(WIN32)\n" +
355-
" set(USERHOME $ENV{USERPROFILE})\n" +
356-
"else()\n" +
357-
" set(USERHOME $ENV{HOME})\n" +
358-
"endif()\n" +
359-
`set(sdkVersion ${newSDKVersion})\n` +
360-
`set(toolchainVersion ${newToolchainVersion})\n` +
361-
`set(picotoolVersion ${newPicotoolVersion})\n` +
362-
`set(picoVscode ${buildCMakeIncPath(false)}/pico-vscode.cmake)\n` +
363-
"if (EXISTS ${picoVscode})\n" +
364-
" include(${picoVscode})\n" +
365-
"endif()\n" +
354+
`# ${CMAKE_DO_NOT_EDIT_HEADER_PREFIX}` + EOL +
355+
"if(WIN32)" + EOL +
356+
" set(USERHOME $ENV{USERPROFILE})" + EOL +
357+
"else()" + EOL +
358+
" set(USERHOME $ENV{HOME})" + EOL +
359+
"endif()" + EOL +
360+
`set(sdkVersion ${newSDKVersion})` + EOL +
361+
`set(toolchainVersion ${newToolchainVersion})` + EOL +
362+
`set(picotoolVersion ${newPicotoolVersion})` + EOL +
363+
`set(picoVscode ${buildCMakeIncPath(false)}/pico-vscode.cmake)` + EOL +
364+
"if (EXISTS ${picoVscode})" + EOL +
365+
" include(${picoVscode})" + EOL +
366+
"endif()" + EOL +
366367
// eslint-disable-next-line max-len
367368
"# ===================================================================================="
368369
);

src/utils/vscodeConfigUtil.mts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { type WorkspaceConfiguration, workspace } from "vscode";
66
import { dirname } from "path/posix";
77
import { compareGe } from "./semverUtil.mjs";
88
import { extensionName } from "../commands/command.mjs";
9+
import {EOL} from "os";
910

1011
interface Configuration {
1112
includePath: string[];
@@ -58,11 +59,12 @@ async function updateCppPropertiesFile(
5859
? "riscv32-corev-elf-gcc"
5960
: "riscv32-unknown-elf-gcc"
6061
: "arm-none-eabi-gcc"
61-
}`;
62+
}${config.compilerPath.endsWith(".exe") ? ".exe" : ""}`;
6263
});
6364

6465
// Write the updated JSON back to the file
65-
const updatedJsonData = JSON.stringify(cppProperties, null, 4);
66+
const updatedJsonData =
67+
(JSON.stringify(cppProperties, null, 4) + EOL).replace(/\r?\n/g, EOL);
6668
await writeFile(file, updatedJsonData, "utf8");
6769

6870
console.log("cpp_properties.json file updated successfully.");
@@ -148,6 +150,7 @@ async function updateSettingsFile(
148150
Logger.debug(LoggerSource.vscodeConfigUtil, `Oldpath: ${oldPath}`);
149151
const pathList = oldPath.split(key.includes("windows") ? ";" : ":");
150152
let toolchainIdx = -1;
153+
let picotoolIdx = -1;
151154
let cmakeIdx = -1;
152155
let ninjaIdx = -1;
153156

@@ -158,6 +161,9 @@ async function updateSettingsFile(
158161
if (item.includes(".pico-sdk/toolchain")) {
159162
toolchainIdx = i;
160163
}
164+
if (item.includes(".pico-sdk/picotool")) {
165+
picotoolIdx = i;
166+
}
161167
if (item.includes(".pico-sdk/cmake")) {
162168
cmakeIdx = i;
163169
}
@@ -173,6 +179,17 @@ async function updateSettingsFile(
173179

174180
pathList[toolchainIdx] = currentValue["PICO_TOOLCHAIN_PATH"] + "/bin";
175181

182+
if (newSDKVersion) {
183+
const newPicotoolPath = `\${${
184+
key.includes("windows") ? "env:USERPROFILE" : "env:HOME"
185+
}}/.pico-sdk/picotool/${newSDKVersion}/picotool`;
186+
if (picotoolIdx > 0) {
187+
pathList[picotoolIdx] = newPicotoolPath;
188+
} else {
189+
pathList.splice(pathList.length - 1, 0, newPicotoolPath);
190+
}
191+
}
192+
176193
if (newCMakeVersion && newCMakeVersion !== "cmake") {
177194
let newCmakePath = "";
178195
if (!newCMakeVersion.includes("/")) {

0 commit comments

Comments
 (0)