@@ -24,6 +24,13 @@ import {
2424 getWAMRExtensionVersion ,
2525} from './utilities/lldbUtilities' ;
2626
27+ import {
28+ checkIfDockerStarted ,
29+ checkIfDockerImagesExist ,
30+ promptSetupDockerImages ,
31+ } from './utilities/dockerUtilities' ;
32+ import { SelectionOfPrompt } from './constants' ;
33+
2734let wasmTaskProvider : WasmTaskProvider ;
2835let wasmDebugConfigProvider : WasmDebugConfigurationProvider ;
2936let currentPrjDir = '' ;
@@ -304,7 +311,7 @@ export async function activate(context: vscode.ExtensionContext) {
304311
305312 const disposableBuild = vscode . commands . registerCommand (
306313 'wamride.build' ,
307- ( ) => {
314+ async ( ) => {
308315 if ( ! isWasmProject ) {
309316 vscode . window . showErrorMessage ( 'Build failed' , {
310317 modal : true ,
@@ -313,6 +320,28 @@ export async function activate(context: vscode.ExtensionContext) {
313320 return ;
314321 }
315322
323+ try {
324+ /* check if docker images are ready before building */
325+ if (
326+ ( await checkIfDockerStarted ( ) ) &&
327+ ! ( await checkIfDockerImagesExist ( context ) )
328+ ) {
329+ /**NOTE - if users select to skip install,
330+ * we should return rather than continue
331+ * the execution
332+ */
333+ if (
334+ ( await promptSetupDockerImages ( context ) ) ===
335+ SelectionOfPrompt . skip
336+ ) {
337+ return ;
338+ }
339+ }
340+ } catch ( e ) {
341+ vscode . window . showWarningMessage ( ( e as Error ) . message ) ;
342+ return ;
343+ }
344+
316345 generateCMakeFile ( includePathArr , excludeFileArr ) ;
317346 /* destroy the wasm-toolchain-ctr if it exists */
318347 vscode . commands
@@ -382,10 +411,35 @@ export async function activate(context: vscode.ExtensionContext) {
382411 /* we should check again whether the user installed lldb, as this can be skipped during activation */
383412 try {
384413 if ( ! isLLDBInstalled ( context ) ) {
385- await promptInstallLLDB ( context ) ;
414+ /**NOTE - if users select to skip install,
415+ * we should return rather than continue
416+ * the execution
417+ */
418+ if (
419+ ( await promptInstallLLDB ( context ) ) ===
420+ SelectionOfPrompt . skip
421+ ) {
422+ return ;
423+ }
424+ }
425+
426+ if (
427+ ( await checkIfDockerStarted ( ) ) &&
428+ ! ( await checkIfDockerImagesExist ( context ) )
429+ ) {
430+ /**NOTE - save as above lldb, should return if
431+ * users select to skip set up
432+ */
433+ if (
434+ ( await promptSetupDockerImages ( context ) ) ===
435+ SelectionOfPrompt . skip
436+ ) {
437+ return ;
438+ }
386439 }
387440 } catch ( e ) {
388441 vscode . window . showWarningMessage ( ( e as Error ) . message ) ;
442+ return ;
389443 }
390444
391445 /* refuse to debug if build process failed */
@@ -461,48 +515,70 @@ export async function activate(context: vscode.ExtensionContext) {
461515 }
462516 ) ;
463517
464- const disposableRun = vscode . commands . registerCommand ( 'wamride.run' , ( ) => {
465- if ( ! isWasmProject ) {
466- vscode . window . showErrorMessage ( 'run failed' , {
467- modal : true ,
468- detail : 'Current project is not wasm project, please open wasm project and try again.' ,
469- } ) ;
470- return ;
471- }
518+ const disposableRun = vscode . commands . registerCommand (
519+ 'wamride.run' ,
520+ async ( ) => {
521+ if ( ! isWasmProject ) {
522+ vscode . window . showErrorMessage ( 'run failed' , {
523+ modal : true ,
524+ detail : 'Current project is not wasm project, please open wasm project and try again.' ,
525+ } ) ;
526+ return ;
527+ }
472528
473- /* refuse to debug if build process failed */
474- if ( ! checkIfBuildSuccess ( ) ) {
475- vscode . window . showErrorMessage ( 'Debug failed' , {
476- modal : true ,
477- detail : 'Can not find WASM binary, please build WASM firstly.' ,
478- } ) ;
479- return ;
480- }
481- vscode . commands
482- . executeCommand (
483- 'workbench.action.tasks.runTask' ,
484- 'Destroy: Wasm-Container-Before-Run'
485- )
486- . then ( ( ) => {
487- const disposableAft = vscode . tasks . onDidEndTaskProcess ( e => {
488- if ( e . execution . task . name === 'Wasm-Container-Before-Run' ) {
489- /* make sure that run wasm task will be executed after destroy task finish */
490- vscode . commands
491- . executeCommand (
492- 'workbench.action.tasks.runTask' ,
493- 'Run: Wasm'
494- )
495- . then ( ( ) => {
496- if ( e . exitCode !== 0 ) {
497- disposableAft . dispose ( ) ;
498- return ;
499- }
500- } ) ;
501- disposableAft . dispose ( ) ;
502- }
529+ try {
530+ /* check if docker images are set up before building */
531+ if (
532+ ( await checkIfDockerStarted ( ) ) &&
533+ ! ( await checkIfDockerImagesExist ( context ) )
534+ ) {
535+ await promptSetupDockerImages ( context ) ;
536+ }
537+ } catch ( e ) {
538+ vscode . window . showWarningMessage ( ( e as Error ) . message ) ;
539+ return ;
540+ }
541+
542+ /* refuse to debug if build process failed */
543+ if ( ! checkIfBuildSuccess ( ) ) {
544+ vscode . window . showErrorMessage ( 'Debug failed' , {
545+ modal : true ,
546+ detail : 'Can not find WASM binary, please build WASM firstly.' ,
503547 } ) ;
504- } ) ;
505- } ) ;
548+ return ;
549+ }
550+
551+ vscode . commands
552+ . executeCommand (
553+ 'workbench.action.tasks.runTask' ,
554+ 'Destroy: Wasm-Container-Before-Run'
555+ )
556+ . then ( ( ) => {
557+ const disposableAft = vscode . tasks . onDidEndTaskProcess (
558+ e => {
559+ if (
560+ e . execution . task . name ===
561+ 'Wasm-Container-Before-Run'
562+ ) {
563+ /* make sure that run wasm task will be executed when destroy task finish */
564+ vscode . commands
565+ . executeCommand (
566+ 'workbench.action.tasks.runTask' ,
567+ 'Run: Wasm'
568+ )
569+ . then ( ( ) => {
570+ if ( e . exitCode !== 0 ) {
571+ disposableAft . dispose ( ) ;
572+ return ;
573+ }
574+ } ) ;
575+ disposableAft . dispose ( ) ;
576+ }
577+ }
578+ ) ;
579+ } ) ;
580+ }
581+ ) ;
506582
507583 const disposableToggleIncludePath = vscode . commands . registerCommand (
508584 'wamride.build.toggleStateIncludePath' ,
@@ -700,6 +776,13 @@ export async function activate(context: vscode.ExtensionContext) {
700776 if ( ! isLLDBInstalled ( context ) ) {
701777 await promptInstallLLDB ( context ) ;
702778 }
779+
780+ if (
781+ ( await checkIfDockerStarted ( ) ) &&
782+ ! ( await checkIfDockerImagesExist ( context ) )
783+ ) {
784+ await promptSetupDockerImages ( context ) ;
785+ }
703786 } catch ( e ) {
704787 vscode . window . showWarningMessage ( ( e as Error ) . message ) ;
705788 }
0 commit comments