Skip to content

Commit 55b849f

Browse files
committed
LastUsedDepsStore basic implementation
Signed-off-by: paulober <[email protected]>
1 parent fb9437f commit 55b849f

File tree

6 files changed

+428
-12
lines changed

6 files changed

+428
-12
lines changed

src/extension.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import {
124124
ZEPHYR_PICO_W,
125125
} from "./models/zephyrBoards.mjs";
126126
import { NewZephyrProjectPanel } from "./webview/newZephyrProjectPanel.mjs";
127+
import LastUsedDepsStore from "./utils/lastUsedDeps.mjs";
127128

128129
export async function activate(context: ExtensionContext): Promise<void> {
129130
Logger.info(LoggerSource.extension, "Extension activation triggered");
@@ -134,6 +135,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
134135
context.extension.packageJSON as PackageJSON
135136
);
136137
GithubApiCache.createInstance(context);
138+
LastUsedDepsStore.instance.setup(context.globalState);
137139

138140
const picoProjectActivityBarProvider = new PicoProjectActivityBar();
139141
const ui = new UI(picoProjectActivityBarProvider);

src/models/dependency.mts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export type DepId =
2+
| "pico-sdk"
3+
| "arm-toolchain"
4+
| "riscv-toolchain"
5+
| "ninja"
6+
| "cmake"
7+
| "embedded-python" // windows-only
8+
| "git" // windows-only
9+
| "openocd"
10+
| "7zip" // windows-only
11+
| "pico-sdk-tools"
12+
| "picotool"
13+
| "zephyr";
14+
15+
export interface DependencyMeta {
16+
id: DepId;
17+
label: string;
18+
platforms?: NodeJS.Platform[]; // omit = all
19+
versioned?: boolean; // default true
20+
}
21+
22+
export const ALL_DEPS: DependencyMeta[] = [
23+
{ id: "pico-sdk", label: "Pico SDK" },
24+
{ id: "arm-toolchain", label: "Arm GNU Toolchain" },
25+
{ id: "riscv-toolchain", label: "RISC-V GNU Toolchain" },
26+
{ id: "ninja", label: "Ninja" },
27+
{ id: "cmake", label: "CMake" },
28+
{ id: "embedded-python", label: "Embedded Python", platforms: ["win32"] },
29+
{ id: "git", label: "Git", platforms: ["win32"] },
30+
{ id: "openocd", label: "OpenOCD" },
31+
{ id: "7zip", label: "7-Zip", platforms: ["win32"], versioned: false },
32+
{ id: "pico-sdk-tools", label: "Pico SDK Tools" },
33+
{ id: "picotool", label: "Picotool" },
34+
];

src/utils/download.mts

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
WINDOWS_X86_PYTHON_DOWNLOAD_URL,
4848
} from "./sharedConstants.mjs";
4949
import { compareGe } from "./semverUtil.mjs";
50+
import LastUsedDepsStore from "./lastUsedDeps.mjs";
5051

5152
/// Translate nodejs platform names to ninja platform names
5253
const NINJA_PLATFORMS: { [key: string]: string } = {
@@ -573,8 +574,15 @@ export async function downloadAndInstallSDK(
573574
`SDK ${version} is missing submodules - installing them now.`
574575
);
575576

576-
return initSubmodules(targetDirectory, gitPath);
577+
const result = await initSubmodules(targetDirectory, gitPath);
578+
if (result) {
579+
await LastUsedDepsStore.instance.record("pico-sdk", version);
580+
}
581+
582+
return result;
577583
} else {
584+
await LastUsedDepsStore.instance.record("pico-sdk", version);
585+
578586
return true;
579587
}
580588
}
@@ -610,7 +618,12 @@ export async function downloadAndInstallSDK(
610618
return false;
611619
}
612620

613-
return initSubmodules(targetDirectory, gitPath);
621+
const result = await initSubmodules(targetDirectory, gitPath);
622+
if (result) {
623+
await LastUsedDepsStore.instance.record("pico-sdk", version);
624+
}
625+
626+
return result;
614627
}
615628

616629
return false;
@@ -745,7 +758,6 @@ export async function downloadAndInstallGithubAsset(
745758
// eslint-disable-next-line @typescript-eslint/naming-convention
746759
"User-Agent": EXT_USER_AGENT,
747760
},
748-
maxRedirections: 0, // don't automatically follow redirects
749761
};
750762
} else {
751763
const urlObj = new URL(url);
@@ -757,7 +769,6 @@ export async function downloadAndInstallGithubAsset(
757769
// eslint-disable-next-line @typescript-eslint/naming-convention
758770
"User-Agent": EXT_USER_AGENT,
759771
},
760-
maxRedirections: 0, // don't automatically follow redirects
761772
};
762773
}
763774

@@ -934,7 +945,7 @@ export async function downloadAndInstallTools(
934945
}-${TOOLS_PLATFORMS[process.platform]}.${assetExt}`;
935946
const releaseVersion = TOOLS_RELEASES[version] ?? "v" + version + "-0";
936947

937-
return downloadAndInstallGithubAsset(
948+
const result = await downloadAndInstallGithubAsset(
938949
version,
939950
releaseVersion,
940951
GithubRepository.tools,
@@ -946,6 +957,11 @@ export async function downloadAndInstallTools(
946957
undefined,
947958
progressCallback
948959
);
960+
if (result) {
961+
await LastUsedDepsStore.instance.record("pico-sdk-tools", version);
962+
}
963+
964+
return result;
949965
}
950966

951967
export async function downloadAndInstallPicotool(
@@ -964,7 +980,7 @@ export async function downloadAndInstallPicotool(
964980
}-${TOOLS_PLATFORMS[process.platform]}.${assetExt}`;
965981
const releaseVersion = PICOTOOL_RELEASES[version] ?? "v" + version + "-0";
966982

967-
return downloadAndInstallGithubAsset(
983+
const result = await downloadAndInstallGithubAsset(
968984
version,
969985
releaseVersion,
970986
GithubRepository.tools,
@@ -976,6 +992,12 @@ export async function downloadAndInstallPicotool(
976992
undefined,
977993
progressCallback
978994
);
995+
996+
if (result) {
997+
await LastUsedDepsStore.instance.record("picotool", version);
998+
}
999+
1000+
return result;
9791001
}
9801002

9811003
export async function downloadAndInstallToolchain(
@@ -999,7 +1021,7 @@ export async function downloadAndInstallToolchain(
9991021

10001022
const archiveFileName = `${toolchain.version}.${artifactExt}`;
10011023

1002-
return downloadAndInstallArchive(
1024+
const result = await downloadAndInstallArchive(
10031025
downloadUrl,
10041026
targetDirectory,
10051027
archiveFileName,
@@ -1009,6 +1031,16 @@ export async function downloadAndInstallToolchain(
10091031
undefined,
10101032
progressCallback
10111033
);
1034+
if (result) {
1035+
await LastUsedDepsStore.instance.record(
1036+
toolchain.version.toLowerCase().includes("risc")
1037+
? "riscv-toolchain"
1038+
: "arm-toolchain",
1039+
toolchain.version
1040+
);
1041+
}
1042+
1043+
return result;
10121044
}
10131045

10141046
/**
@@ -1032,7 +1064,7 @@ export async function downloadAndInstallNinja(
10321064
: ""
10331065
}.zip`;
10341066

1035-
return downloadAndInstallGithubAsset(
1067+
const result = await downloadAndInstallGithubAsset(
10361068
version,
10371069
version,
10381070
GithubRepository.ninja,
@@ -1044,6 +1076,11 @@ export async function downloadAndInstallNinja(
10441076
undefined,
10451077
progressCallback
10461078
);
1079+
if (result) {
1080+
await LastUsedDepsStore.instance.record("ninja", version);
1081+
}
1082+
1083+
return result;
10471084
}
10481085

10491086
/// Detects if the current system is a Raspberry Pi with Debian
@@ -1102,7 +1139,7 @@ export async function downloadAndInstallOpenOCD(
11021139
}
11031140
};
11041141

1105-
return downloadAndInstallGithubAsset(
1142+
const result = await downloadAndInstallGithubAsset(
11061143
version,
11071144
OPENOCD_RELEASES[version],
11081145
GithubRepository.tools,
@@ -1114,6 +1151,11 @@ export async function downloadAndInstallOpenOCD(
11141151
undefined,
11151152
progressCallback
11161153
);
1154+
if (result) {
1155+
await LastUsedDepsStore.instance.record("openocd", version);
1156+
}
1157+
1158+
return result;
11171159
}
11181160

11191161
/**
@@ -1155,7 +1197,7 @@ export async function downloadAndInstallCmake(
11551197
//chmodSync(join(targetDirectory, "CMake.app", "Contents", "bin", "cmake"), 0o755);
11561198
};
11571199

1158-
return downloadAndInstallGithubAsset(
1200+
const result = await downloadAndInstallGithubAsset(
11591201
version,
11601202
version,
11611203
GithubRepository.cmake,
@@ -1167,6 +1209,11 @@ export async function downloadAndInstallCmake(
11671209
undefined,
11681210
progressCallback
11691211
);
1212+
if (result) {
1213+
await LastUsedDepsStore.instance.record("cmake", version);
1214+
}
1215+
1216+
return result;
11701217
}
11711218

11721219
function _runCommand(
@@ -1363,8 +1410,9 @@ export async function downloadEmbedPython(
13631410
await workspace.fs.createDirectory(Uri.file(dllDir));
13641411

13651412
// Write to *._pth to allow use of installed packages
1366-
const versionAppend =
1367-
CURRENT_PYTHON_VERSION.split(".").slice(0, 2).join("");
1413+
const versionAppend = CURRENT_PYTHON_VERSION.split(".")
1414+
.slice(0, 2)
1415+
.join("");
13681416
const pthFile = `${targetDirectory}/python${versionAppend}._pth`;
13691417
let pthContents = (
13701418
await workspace.fs.readFile(Uri.file(pthFile))
@@ -1405,5 +1453,10 @@ export async function downloadEmbedPython(
14051453
}
14061454
}
14071455

1456+
await LastUsedDepsStore.instance.record(
1457+
"embedded-python",
1458+
CURRENT_PYTHON_VERSION
1459+
);
1460+
14081461
return pythonExe;
14091462
}

src/utils/gitUtil.mts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import which from "which";
99
import { ProgressLocation, window } from "vscode";
1010
import { compareGe } from "./semverUtil.mjs";
1111
import { downloadGit } from "./downloadGit.mjs";
12+
import LastUsedDepsStore from "./lastUsedDeps.mjs";
1213

1314
export const execAsync = promisify(exec);
1415

@@ -134,6 +135,10 @@ export async function ensureGit(
134135
}
135136
}
136137

138+
if (gitPath?.includes(".pico-sdk")) {
139+
await LastUsedDepsStore.instance.record("git", "latest");
140+
}
141+
137142
return returnPath ? gitPath || undefined : isGitInstalled;
138143
}
139144

0 commit comments

Comments
 (0)