@@ -7,6 +7,7 @@ import Logger from "../logger.mjs";
77import type { Progress as GotProgress } from "got" ;
88
99import {
10+ buildCMakePath ,
1011 buildZephyrWorkspacePath ,
1112 downloadAndInstallArchive ,
1213 downloadAndInstallCmake ,
@@ -19,6 +20,7 @@ import Settings, { HOME_VAR } from "../settings.mjs";
1920import { openOCDVersion } from "../webview/newProjectPanel.mjs" ;
2021import findPython , { showPythonNotFoundError } from "../utils/pythonHelper.mjs" ;
2122import { ensureGit } from "../utils/gitUtil.mjs" ;
23+ import { type VersionBundle } from "../utils/versionBundles.mjs" ;
2224
2325const _logger = new Logger ( "zephyrSetup" ) ;
2426
@@ -44,6 +46,17 @@ manifest:
4446 - hal_infineon # required for Wifi chip support
4547` ;
4648
49+ interface ZephyrSetupValue {
50+ versionBundle : VersionBundle | undefined ;
51+ cmakeMode : number ;
52+ cmakePath : string ;
53+ cmakeVersion : string ;
54+ }
55+
56+ interface ZephyrSetupOutputs {
57+ cmakeExecutable : string ;
58+ }
59+
4760function _runCommand (
4861 command : string ,
4962 options : ExecOptions
@@ -67,14 +80,18 @@ function _runCommand(
6780 } ) ;
6881}
6982
70- export async function setupZephyr ( ) : Promise < string | undefined > {
83+ export async function setupZephyr (
84+ data : ZephyrSetupValue
85+ ) : Promise < ZephyrSetupOutputs | string | undefined > {
7186 const settings = Settings . getInstance ( ) ;
7287 if ( settings === undefined ) {
7388 _logger . error ( "Settings not initialized." ) ;
7489
7590 return ;
7691 }
7792
93+ let output : ZephyrSetupOutputs = { cmakeExecutable : "" } ;
94+
7895 let python3Path = "" ;
7996 let isWindows = false ;
8097 await window . withProgress (
@@ -111,38 +128,96 @@ export async function setupZephyr(): Promise<string | undefined> {
111128 }
112129 ) ;
113130
114- await window . withProgress (
115- {
116- location : ProgressLocation . Notification ,
117- title : "Download and install CMake" ,
118- cancellable : false ,
119- } ,
120- async progress2 => {
121- if (
122- await downloadAndInstallCmake ( "v3.31.5" , ( prog : GotProgress ) => {
123- const per = prog . percent * 100 ;
124- progress2 . report ( {
125- increment : per - prog2LastState ,
126- } ) ;
127- prog2LastState = per ;
128- } )
129- ) {
130- progress2 . report ( {
131- message : "Successfully downloaded and installed CMake." ,
132- increment : 100 ,
133- } ) ;
131+ // Handle CMake install
132+ switch ( data . cmakeMode ) {
133+ case 0 :
134+ if ( data . versionBundle !== undefined ) {
135+ data . cmakeVersion = data . versionBundle . cmake ;
136+ }
137+ // eslint-disable-next-line no-fallthrough
138+ case 2 :
139+ installedSuccessfully = false ;
140+ prog2LastState = 0 ;
141+ await window . withProgress (
142+ {
143+ location : ProgressLocation . Notification ,
144+ title : "Download and install CMake" ,
145+ cancellable : false ,
146+ } ,
147+ async progress2 => {
148+ if (
149+ await downloadAndInstallCmake (
150+ data . cmakeVersion ,
151+ ( prog : GotProgress ) => {
152+ const per = prog . percent * 100 ;
153+ progress2 . report ( {
154+ increment : per - prog2LastState ,
155+ } ) ;
156+ prog2LastState = per ;
157+ }
158+ )
159+ ) {
160+ progress . report ( {
161+ // TODO: maybe just finished or something like that
162+ message : "Successfully downloaded and installed CMake." ,
163+ increment : 100 ,
164+ } ) ;
134165
135- installedSuccessfully = true ;
136- } else {
137- installedSuccessfully = false ;
138- progress2 . report ( {
166+ installedSuccessfully = true ;
167+ } else {
168+ installedSuccessfully = false ;
169+ progress2 . report ( {
170+ message : "Failed" ,
171+ increment : 100 ,
172+ } ) ;
173+ }
174+ }
175+ ) ;
176+
177+ if ( ! installedSuccessfully ) {
178+ progress . report ( {
139179 message : "Failed" ,
140180 increment : 100 ,
141181 } ) ;
182+ void window . showErrorMessage (
183+ // TODO: maybe remove all requirements met part
184+ "Failed to download and install CMake.\
185+ Make sure all requirements are met."
186+ ) ;
187+
188+ return ;
189+ } else {
190+ const cmakeVersionBasePath = buildCMakePath ( data . cmakeVersion ) ;
191+
192+ output . cmakeExecutable = joinPosix (
193+ cmakeVersionBasePath ,
194+ "bin" ,
195+ "cmake"
196+ ) ;
142197 }
143- }
144- ) ;
198+ break ;
199+ case 1 :
200+ // Don't need to add anything to path if already available via system
201+ output . cmakeExecutable = "" ;
202+ break ;
203+ case 3 :
204+ // normalize path returned by the os selector to posix path for the settings json
205+ // and cross platform compatibility
206+ output . cmakeExecutable =
207+ process . platform === "win32"
208+ ? // TODO: maybe use path.sep for split
209+ joinPosix ( ...data . cmakePath . split ( "\\" ) )
210+ : data . cmakePath ;
211+ break ;
212+ default :
213+ progress . report ( {
214+ message : "Failed" ,
215+ increment : 100 ,
216+ } ) ;
217+ void window . showErrorMessage ( "Unknown cmake selection." ) ;
145218
219+ return ;
220+ }
146221 await window . withProgress (
147222 {
148223 location : ProgressLocation . Notification ,
@@ -811,5 +886,5 @@ export async function setupZephyr(): Promise<string | undefined> {
811886
812887 _logger . info ( "Complete" ) ;
813888
814- return "" ;
889+ return output ;
815890}
0 commit comments