Skip to content

Commit cec99da

Browse files
authored
Merge pull request #220 from raspberrypi/fix-zephyr-setup
Fix zephyr project files and setup
2 parents 5e9658b + 60709c9 commit cec99da

File tree

10 files changed

+214
-94
lines changed

10 files changed

+214
-94
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ For further context, see this discussion in the Zephyr project: https://github.c
112112

113113
## Additonal Zephyr Prerequisites
114114

115-
> On Raspberry Pi OS Trixie these come pre-installed.
115+
> On Raspberry Pi OS Trixie all of those come pre-installed.
116116
117-
* **wget** - Required for sdk-ng to download toolchains. Install via your package manager (e.g., `brew install wget` on macOS or `sudo apt install wget` on Debian based Linux distributions).
117+
* **wget** - Required for sdk-ng to download toolchains.
118118

119119
### Linux and macOS only
120120

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@
279279
"command": "raspberry-pi-pico.openUninstaller",
280280
"title": "Open Uninstaller",
281281
"category": "Raspberry Pi Pico"
282+
},
283+
{
284+
"command": "raspberry-pi-pico.getGitPath",
285+
"title": "Get git path",
286+
"category": "Raspberry Pi Pico",
287+
"enablement": "false"
282288
}
283289
],
284290
"configuration": {

src/commands/cmdIds.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const GET_SVD_PATH = "getSVDPath";
2121
export const GET_WEST_PATH = "getWestPath";
2222
export const GET_ZEPHYR_WORKSPACE_PATH = "getZephyrWorkspacePath";
2323
export const GET_ZEPHYR_SDK_PATH = "getZephyrSDKPath";
24+
export const GET_GIT_PATH = "getGitPath";
2425

2526
export const IMPORT_PROJECT = "importProject";
2627

src/commands/getPaths.mts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
GET_CXX_COMPILER_PATH,
3636
GET_ENV_PATH,
3737
GET_GDB_PATH,
38+
GET_GIT_PATH,
3839
GET_OPENOCD_ROOT,
3940
GET_PICOTOOL_PATH,
4041
GET_PYTHON_PATH,
@@ -54,6 +55,7 @@ import {
5455
ZEPHYR_PICO2_W,
5556
ZEPHYR_PICO_W,
5657
} from "../models/zephyrBoards.mjs";
58+
import { ensureGit } from "../utils/gitUtil.mjs";
5759

5860
export class GetPythonPathCommand extends CommandWithResult<string> {
5961
constructor() {
@@ -628,9 +630,28 @@ export class GetZephyrSDKPathCommand extends CommandWithResult<
628630
await workspace.fs.stat(Uri.file(result));
629631
const zephyrSdkVersion = await getZephyrSDKVersion();
630632

631-
return joinPosix(result, `zephyr-sdk-${zephyrSdkVersion}`);
633+
return joinPosix(result, `zephyr-sdk-${zephyrSdkVersion ?? "unknown"}`);
632634
} catch {
633635
return undefined;
634636
}
635637
}
636638
}
639+
640+
export class GetGitPathCommand extends CommandWithResult<string> {
641+
constructor(private readonly _settings: Settings) {
642+
super(GET_GIT_PATH);
643+
}
644+
645+
async execute(): Promise<string> {
646+
const gitPath = await ensureGit(this._settings, { returnPath: true });
647+
if (
648+
typeof gitPath !== "string" ||
649+
gitPath.length === 0 ||
650+
!gitPath.includes("/")
651+
) {
652+
return "";
653+
}
654+
655+
return gitPath;
656+
}
657+
}

src/extension.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
GetWestPathCommand,
5757
GetZephyrWorkspacePathCommand,
5858
GetZephyrSDKPathCommand,
59+
GetGitPathCommand,
5960
} from "./commands/getPaths.mjs";
6061
import {
6162
downloadAndInstallCmake,
@@ -184,6 +185,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
184185
new SbomTargetPathDebugCommand(),
185186
new SbomTargetPathReleaseCommand(),
186187
new OpenUninstallerCommand(context.extensionUri),
188+
new GetGitPathCommand(settings),
187189
];
188190

189191
// register all command handlers

src/utils/download.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ export async function downloadAndInstallSDK(
520520
return false;
521521
}
522522

523+
// TODO: option to parse already resolved path into this function
523524
// TODO: this does take about 2s - may be reduced
524525
const gitPath = await ensureGit(settings, { returnPath: true });
525526
if (typeof gitPath !== "string" || gitPath.length === 0) {

src/utils/projectGeneration/projectZephyr.mts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-len */
22
/* eslint-disable @typescript-eslint/naming-convention */
3-
import { dirname, join } from "path";
3+
import { join } from "path";
44
import { dirname as dirnamePosix } from "path/posix";
55
import Logger, { LoggerSource } from "../../logger.mjs";
66
import { unknownErrorToString } from "../errorHelper.mjs";
@@ -27,10 +27,12 @@ import {
2727
import { homedir } from "os";
2828
import {
2929
GET_CHIP_UPPERCASE,
30+
GET_GIT_PATH,
3031
GET_OPENOCD_ROOT,
3132
GET_PICOTOOL_PATH,
3233
GET_TARGET,
3334
GET_WEST_PATH,
35+
GET_ZEPHYR_SDK_PATH,
3436
GET_ZEPHYR_WORKSPACE_PATH,
3537
} from "../../commands/cmdIds.mjs";
3638
import { getZephyrSDKVersion, getZephyrVersion } from "../setupZephyr.mjs";
@@ -69,8 +71,7 @@ async function generateVSCodeConfig(
6971
ninjaPath: string,
7072
cmakePath: string,
7173
te: TextEncoder = new TextEncoder(),
72-
data: ZephyrSubmitMessageValue,
73-
gitPath: string
74+
data: ZephyrSubmitMessageValue
7475
): Promise<boolean> {
7576
const vsc = join(projectRoot, ".vscode");
7677

@@ -164,7 +165,7 @@ async function generateVSCodeConfig(
164165
toolchainPrefix: "arm-zephyr-eabi",
165166
armToolchainPath:
166167
// TODO: maybe just full get zephyr compiler path command
167-
`\${command:${extensionName}.${GET_ZEPHYR_WORKSPACE_PATH}}/zephyr-sdk/arm-zephyr-eabi/bin`,
168+
`\${command:${extensionName}.${GET_ZEPHYR_SDK_PATH}}/arm-zephyr-eabi/bin`,
168169
// TODO: get chip dynamically maybe: chip: `\${command:${extensionName}.${GetChipCommand.id}}`,
169170
// meaning only one cfg required
170171
device: `\${command:${extensionName}.${GET_CHIP_UPPERCASE}}`,
@@ -179,6 +180,8 @@ async function generateVSCodeConfig(
179180
openOCDLaunchCommands: ["adapter speed 5000"],
180181
// TODO: add zephyr build support to support this.
181182
rtos: "Zephyr",
183+
// TODO: maybe get into launch target path command like in c/c++ projects
184+
preLaunchTask: "Compile Project",
182185
},
183186
],
184187
};
@@ -205,15 +208,13 @@ async function generateVSCodeConfig(
205208
"terminal.integrated.env.windows": {
206209
// remove gperf and dtc for now
207210
// \${env:USERPROFILE}/.pico-sdk/dtc/${CURRENT_DTC_VERSION}/bin;\${env:USERPROFILE}/.pico-sdk/gperf/${CURRENT_GPERF_VERSION}
208-
Path: `${dirname(
209-
gitPath
210-
)};\${env:USERPROFILE}/.pico-sdk/7zip;\${env:Path};`,
211+
Path: "${env:USERPROFILE}/.pico-sdk/7zip;${env:Path};",
211212
},
212213
"terminal.integrated.env.osx": {
213-
PATH: `${dirname(gitPath)}:\${env:PATH}:`,
214+
PATH: "${env:PATH}:",
214215
},
215216
"terminal.integrated.env.linux": {
216-
PATH: `${dirname(gitPath)}:\${env:PATH}:`,
217+
PATH: "${env:PATH}:",
217218
},
218219
"raspberry-pi-pico.cmakeAutoConfigure": true,
219220
"raspberry-pi-pico.useCmakeTools": false,
@@ -331,9 +332,15 @@ async function generateVSCodeConfig(
331332
problemMatcher: "$gcc",
332333
options: {
333334
cwd: `\${command:${extensionName}.${GET_ZEPHYR_WORKSPACE_PATH}}`,
335+
env: {
336+
PATH: `\${command:${extensionName}.${GET_GIT_PATH}}:\${env:PATH}:`,
337+
},
334338
},
335339
windows: {
336340
options: {
341+
env: {
342+
Path: `\${command:${extensionName}.${GET_GIT_PATH}};\${env:Path};`,
343+
},
337344
shell: {
338345
executable: "cmd.exe",
339346
args: ["/d", "/c"],
@@ -365,6 +372,8 @@ async function generateVSCodeConfig(
365372
panel: "dedicated",
366373
},
367374
problemMatcher: [],
375+
dependsOrder: "sequence",
376+
dependsOn: "Compile Project",
368377
},
369378
],
370379
};
@@ -1170,8 +1179,7 @@ export async function generateZephyrProject(
11701179
latestVb: [string, VersionBundle],
11711180
ninjaPath: string,
11721181
cmakePath: string,
1173-
data: ZephyrSubmitMessageValue,
1174-
gitPath: string
1182+
data: ZephyrSubmitMessageValue
11751183
): Promise<boolean> {
11761184
const projectRoot = join(projectFolder, projectName);
11771185

@@ -1245,8 +1253,7 @@ export async function generateZephyrProject(
12451253
ninjaPath,
12461254
cmakePath,
12471255
te,
1248-
data,
1249-
gitPath
1256+
data
12501257
);
12511258
if (!result) {
12521259
Logger.debug(

0 commit comments

Comments
 (0)