@@ -2,7 +2,7 @@ const BaseBuildStrategy = require('./baseBuildStrategy');
22const { getDebuggerSession } = require ( '../managers/sessionManager' ) ;
33const vscode = require ( 'vscode' ) ;
44const fs = require ( 'fs' ) ;
5- const { exec } = require ( 'child_process' ) ;
5+ const { spawn } = require ( 'child_process' ) ;
66const BuildCommands = require ( './buildCommands' ) ;
77const gimletConfigManager = require ( '../config' ) ;
88const { safeReadDir } = require ( '../projectStructure' ) ;
@@ -32,59 +32,69 @@ class SbpfV1BuildStrategy extends BaseBuildStrategy {
3232
3333 async build ( progress ) {
3434 const buildCmd = this . getBuildCommand ( ) ;
35- console . log ( ` Running command: ${ buildCmd } ` ) ;
36- progress . report ( { increment : 1 , message : 'Building you program!' } ) ;
35+ progress . report ( { increment : 1 , message : 'Building your program!' } ) ;
3736
3837 return new Promise ( ( resolve ) => {
39- exec (
38+ const outputChannel = vscode . window . createOutputChannel ( 'Gimlet' ) ;
39+ outputChannel . show ( true ) ;
40+ outputChannel . appendLine ( `Running build command: ${ buildCmd } \n` ) ;
41+
42+ const buildProcess = spawn (
4043 buildCmd ,
41- { cwd : this . workspaceFolder } ,
42- async ( err , stdout , stderr ) => {
43- if ( err ) {
44- vscode . window . showErrorMessage (
45- `Build error: ${ stderr } `
46- ) ;
47- resolve ( ) ;
48- return ;
49- }
44+ {
45+ cwd : this . workspaceFolder ,
46+ shell : true
47+ }
48+ )
5049
51- progress . report ( { increment : 2 , message : 'Setting gimlet internals!' } ) ;
52- // Load the depsPath from gimlet config
53- const { depsPath } = await gimletConfigManager . resolveGimletConfig ( ) ;
54- this . depsPath = depsPath ;
50+ buildProcess . stdout . on ( 'data' , ( data ) => {
51+ outputChannel . append ( data . toString ( ) ) ;
52+ } ) ;
5553
56- // Holds all the compiled programs in target/deploy
57- let newFiles = await safeReadDir ( this . depsPath ) ;
58- if ( ! newFiles ) {
59- resolve ( ) ;
60- return ;
61- }
54+ buildProcess . stderr . on ( 'data' , ( data ) => {
55+ outputChannel . append ( data . toString ( ) ) ;
56+ } ) ;
57+
58+ buildProcess . on ( 'close' , async ( code ) => {
59+ if ( code !== 0 ) {
60+ throw new Error ( `Build failed with exit code ${ code } ` ) ;
61+ }
6262
63- // Hash all the compiled programs
64- for ( let programCompiledFile of newFiles ) {
65- if ( ! programCompiledFile . endsWith ( '.so' ) ) {
66- continue ;
67- }
68-
69- const debugBinaryPath = ` ${ this . depsPath } / ${ programCompiledFile . replace ( '.so' , '.debug' ) } ` ;
70- const bpfCompiledPath = ` ${ this . depsPath } / ${ programCompiledFile } ` ;
71-
72- this . hashProgram ( programCompiledFile ) ;
73-
74- this . debuggerSession . executablesPaths [ programCompiledFile ] = {
75- debugBinary : debugBinaryPath ,
76- bpfCompiledPath : bpfCompiledPath
77- } ;
63+ // Load the depsPath from gimlet config
64+ const { depsPath } = await gimletConfigManager . resolveGimletConfig ( ) ;
65+ this . depsPath = depsPath ;
66+
67+ // Holds all the compiled programs in target/deploy
68+ let newFiles = await safeReadDir ( this . depsPath ) ;
69+ if ( ! newFiles ) {
70+ resolve ( ) ;
71+ return ;
72+ }
73+
74+ // Hash all the compiled programs
75+ for ( let programCompiledFile of newFiles ) {
76+ if ( ! programCompiledFile . endsWith ( '.so' ) ) {
77+ continue ;
7878 }
7979
80- if ( progress )
81- progress . report ( {
82- increment : 3 ,
83- message : 'Setting up debugger...' ,
84- } ) ;
85- resolve ( true ) ;
80+ const debugBinaryPath = `${ this . depsPath } /${ programCompiledFile . replace ( '.so' , '.debug' ) } ` ;
81+ const bpfCompiledPath = `${ this . depsPath } /${ programCompiledFile } ` ;
82+
83+ this . hashProgram ( programCompiledFile ) ;
84+
85+ this . debuggerSession . executablesPaths [ programCompiledFile ] = {
86+ debugBinary : debugBinaryPath ,
87+ bpfCompiledPath : bpfCompiledPath
88+ } ;
8689 }
87- ) ;
90+
91+ if ( progress )
92+ progress . report ( {
93+ increment : 3 ,
94+ message : 'Setting up debugger...' ,
95+ } ) ;
96+ resolve ( true ) ;
97+ } ) ;
8898 } ) ;
8999 }
90100
0 commit comments