Skip to content

Commit 91d7ede

Browse files
committed
Add wget wrapper workaround + Fix cmake auto configure for zephyr + fix git path inclusion
Signed-off-by: paulober <[email protected]>
1 parent 65fb372 commit 91d7ede

File tree

11 files changed

+457
-299
lines changed

11 files changed

+457
-299
lines changed

.vscodeignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ node_modules/**
3535
!scripts/pico-vscode.cmake
3636
!scripts/Pico.code-profile
3737
!scripts/raspberrypi-swd.cfg
38+
!scripts/wget.cmd
39+
!scripts/wget.sh
3840
!data/**
3941
scripts/*.ps1
4042
scripts/fix_windows_reg.py

scripts/wget.cmd

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@echo off
2+
REM --- Simple wget wrapper using curl ---
3+
4+
setlocal
5+
6+
set QUIET=
7+
set OUTPUT=
8+
set URL=
9+
10+
:parse
11+
if "%~1"=="" goto done
12+
if "%~1"=="-q" (
13+
set QUIET=-s
14+
) else if "%~1"=="--show-progress" (
15+
REM curl shows progress by default unless -s is set
16+
) else if "%~1"=="-N" (
17+
REM ignore, wget -N is about timestamping
18+
) else if "%~1"=="-O" (
19+
shift
20+
set OUTPUT=-o %~1
21+
) else (
22+
set URL=%~1
23+
)
24+
shift
25+
goto parse
26+
27+
:done
28+
if "%URL%"=="" (
29+
echo ERROR: No URL provided
30+
exit /b 1
31+
)
32+
33+
curl --retry 5 --retry-delay 5 --retry-connrefused %QUIET% -L %OUTPUT% %URL%
34+
35+
endlocal

scripts/wget.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
# Simple wget wrapper using curl
3+
4+
QUIET=""
5+
OUTPUT=""
6+
URL=""
7+
8+
while [ "$#" -gt 0 ]; do
9+
case "$1" in
10+
-q) QUIET="-s" ;;
11+
--show-progress) ;; # curl shows by default
12+
-N) ;; # ignore timestamping
13+
-O) shift; OUTPUT="-o $1" ;;
14+
*) URL="$1" ;;
15+
esac
16+
shift
17+
done
18+
19+
if [ -z "$URL" ]; then
20+
echo "ERROR: No URL provided" >&2
21+
exit 1
22+
fi
23+
24+
exec curl --retry 5 --retry-delay 5 --retry-connrefused $QUIET -L $OUTPUT "$URL"

src/commands/getPaths.mts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommandWithResult } from "./command.mjs";
2-
import { commands, FileType, Uri, window, workspace } from "vscode";
2+
import { commands, Uri, window, workspace } from "vscode";
33
import {
44
getPythonPath,
55
getPath,
@@ -44,14 +44,16 @@ import {
4444
GET_ZEPHYR_SDK_PATH,
4545
GET_ZEPHYR_WORKSPACE_PATH,
4646
} from "./cmdIds.mjs";
47-
import { getBoardFromZephyrProject } from "../utils/setupZephyr.mjs";
47+
import {
48+
getBoardFromZephyrProject,
49+
getZephyrSDKVersion,
50+
} from "../utils/setupZephyr.mjs";
4851
import {
4952
ZEPHYR_PICO,
5053
ZEPHYR_PICO2,
5154
ZEPHYR_PICO2_W,
5255
ZEPHYR_PICO_W,
5356
} from "../models/zephyrBoards.mjs";
54-
import { compare } from "../utils/semverUtil.mjs";
5557

5658
export class GetPythonPathCommand extends CommandWithResult<string> {
5759
constructor() {
@@ -85,9 +87,10 @@ export class GetEnvPathCommand extends CommandWithResult<string> {
8587
return "";
8688
}
8789

88-
const path = await getPath();
90+
const env = await getPath();
91+
const pathValue = process.platform === "win32" ? env.Path : env.PATH;
8992

90-
return path;
93+
return JSON.stringify(pathValue ?? "");
9194
}
9295
}
9396

@@ -603,13 +606,7 @@ export class GetZephyrWorkspacePathCommand extends CommandWithResult<
603606
}
604607

605608
execute(): string | undefined {
606-
const result = buildZephyrWorkspacePath();
607-
608-
if (result === null || !result) {
609-
return undefined;
610-
}
611-
612-
return result;
609+
return buildZephyrWorkspacePath();
613610
}
614611
}
615612

@@ -626,22 +623,12 @@ export class GetZephyrSDKPathCommand extends CommandWithResult<
626623
if (result === null || !result) {
627624
return undefined;
628625
}
629-
const workspaceUri = Uri.file(result);
630626

631627
try {
632-
await workspace.fs.stat(workspaceUri);
633-
const contents = await workspace.fs.readDirectory(workspaceUri);
634-
// TODO: get zephr version form west manifest and sdk_version from zephyr directory
635-
const sdksDirectories = contents
636-
.filter(
637-
entry =>
638-
entry[1] === FileType.Directory &&
639-
entry[0].startsWith("zephyr-sdk-")
640-
)
641-
.map(([name]) => name.replace(/^zephyr-sdk-/, ""))
642-
.sort((a, b) => compare(b, a)); // sort descending
643-
644-
return joinPosix(result, `zephyr-sdk-${sdksDirectories[0]}`);
628+
await workspace.fs.stat(Uri.file(result));
629+
const zephyrSdkVersion = await getZephyrSDKVersion();
630+
631+
return joinPosix(result, `zephyr-sdk-${zephyrSdkVersion}`);
645632
} catch {
646633
return undefined;
647634
}

src/extension.mts

Lines changed: 70 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ProgressLocation,
88
Uri,
99
FileSystemError,
10+
type WorkspaceFolder,
1011
} from "vscode";
1112
import {
1213
extensionName,
@@ -112,6 +113,7 @@ import {
112113
getZephyrVersion,
113114
setupZephyr,
114115
updateZephyrCompilerPath,
116+
zephyrVerifyCMakCache,
115117
} from "./utils/setupZephyr.mjs";
116118
import { IMPORT_PROJECT } from "./commands/cmdIds.mjs";
117119
import {
@@ -398,7 +400,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
398400
ninjaVersion = version;
399401
}
400402

401-
// TODO: read selected ninja and cmake versions from project
402403
const result = await setupZephyr({
403404
extUri: context.extensionUri,
404405
cmakeMode: cmakeVersion !== "" ? 2 : 3,
@@ -462,6 +463,8 @@ export async function activate(context: ExtensionContext): Promise<void> {
462463
// TODO: maybe cancel activation
463464
}
464465

466+
await zephyrVerifyCMakCache(workspaceFolder.uri);
467+
465468
// Update the board info if it can be found in tasks.json
466469
const tasksJsonFilePath = join(
467470
workspaceFolder.uri.fsPath,
@@ -486,37 +489,44 @@ export async function activate(context: ExtensionContext): Promise<void> {
486489
}
487490
}
488491

489-
// check if build dir is empty and recommend to run a build to
490-
// get the intellisense working
491-
// TODO: maybe run cmake configure automatically if build folder empty
492-
const buildUri = Uri.file(join(workspaceFolder.uri.fsPath, "build"));
493-
try {
494-
// workaround to stop verbose logging of readDirectory internals even if we catch the error
495-
await workspace.fs.stat(buildUri);
496-
const buildDirContents = await workspace.fs.readDirectory(buildUri);
497-
498-
if (buildDirContents.length === 0) {
499-
void window.showWarningMessage(
500-
"To get full intellisense support please build the project once."
501-
);
502-
}
503-
} catch (error) {
504-
if (error instanceof FileSystemError && error.code === "FileNotFound") {
505-
void window.showWarningMessage(
506-
"To get full intellisense support please build the project once."
507-
);
508-
509-
Logger.debug(
510-
LoggerSource.extension,
511-
'No "build" folder found. Intellisense might not work ' +
512-
"properly until a build has been done."
513-
);
514-
} else {
515-
Logger.error(
516-
LoggerSource.extension,
517-
"Error when reading build folder:",
518-
unknownErrorToString(error)
519-
);
492+
if (settings.getBoolean(SettingsKey.cmakeAutoConfigure)) {
493+
await cmakeSetupAutoConfigure(workspaceFolder, ui);
494+
} else {
495+
// check if build dir is empty and recommend to run a build to
496+
// get the intellisense working
497+
const buildUri = Uri.file(join(workspaceFolder.uri.fsPath, "build"));
498+
try {
499+
// workaround to stop verbose logging of readDirectory
500+
// internals even if we catch the error
501+
await workspace.fs.stat(buildUri);
502+
const buildDirContents = await workspace.fs.readDirectory(buildUri);
503+
504+
if (buildDirContents.length === 0) {
505+
void window.showWarningMessage(
506+
"To get full intellisense support please build the project once."
507+
);
508+
}
509+
} catch (error) {
510+
if (
511+
error instanceof FileSystemError &&
512+
error.code === "FileNotFound"
513+
) {
514+
void window.showWarningMessage(
515+
"To get full intellisense support please build the project once."
516+
);
517+
518+
Logger.debug(
519+
LoggerSource.extension,
520+
'No "build" folder found. Intellisense might not work ' +
521+
"properly until a build has been done."
522+
);
523+
} else {
524+
Logger.error(
525+
LoggerSource.extension,
526+
"Error when reading build folder:",
527+
unknownErrorToString(error)
528+
);
529+
}
520530
}
521531
}
522532

@@ -1098,27 +1108,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
10981108

10991109
// auto project configuration with cmake
11001110
if (settings.getBoolean(SettingsKey.cmakeAutoConfigure)) {
1101-
//run `cmake -G Ninja -B ./build ` in the root folder
1102-
await configureCmakeNinja(workspaceFolder.uri);
1103-
1104-
const ws = workspaceFolder.uri.fsPath;
1105-
const cMakeCachePath = join(ws, "build", "CMakeCache.txt");
1106-
const newBuildType = cmakeGetPicoVar(cMakeCachePath, "CMAKE_BUILD_TYPE");
1107-
ui.updateBuildType(newBuildType ?? "unknown");
1108-
1109-
workspace.onDidChangeTextDocument(event => {
1110-
// Check if the changed document is the file you are interested in
1111-
if (basename(event.document.fileName) === "CMakeLists.txt") {
1112-
// File has changed, do something here
1113-
// TODO: rerun configure project
1114-
// TODO: maybe conflicts with cmake extension which also does this
1115-
Logger.debug(
1116-
LoggerSource.extension,
1117-
"File changed:",
1118-
event.document.fileName
1119-
);
1120-
}
1121-
});
1111+
await cmakeSetupAutoConfigure(workspaceFolder, ui);
11221112
} else if (settings.getBoolean(SettingsKey.useCmakeTools)) {
11231113
// Ensure the Pico kit is selected
11241114
await cmakeToolsForcePicoKit();
@@ -1131,6 +1121,33 @@ export async function activate(context: ExtensionContext): Promise<void> {
11311121
}
11321122
}
11331123

1124+
async function cmakeSetupAutoConfigure(
1125+
workspaceFolder: WorkspaceFolder,
1126+
ui: UI
1127+
): Promise<void> {
1128+
//run `cmake -G Ninja -B ./build ` in the root folder
1129+
await configureCmakeNinja(workspaceFolder.uri);
1130+
1131+
const ws = workspaceFolder.uri.fsPath;
1132+
const cMakeCachePath = join(ws, "build", "CMakeCache.txt");
1133+
const newBuildType = cmakeGetPicoVar(cMakeCachePath, "CMAKE_BUILD_TYPE");
1134+
ui.updateBuildType(newBuildType ?? "unknown");
1135+
1136+
workspace.onDidChangeTextDocument(event => {
1137+
// Check if the changed document is the file you are interested in
1138+
if (basename(event.document.fileName) === "CMakeLists.txt") {
1139+
// File has changed, do something here
1140+
// TODO: rerun configure project
1141+
// TODO: maybe conflicts with cmake extension which also does this
1142+
Logger.debug(
1143+
LoggerSource.extension,
1144+
"File changed:",
1145+
event.document.fileName
1146+
);
1147+
}
1148+
});
1149+
}
1150+
11341151
/**
11351152
* Make sure the executable has the .exe extension on Windows.
11361153
*

0 commit comments

Comments
 (0)