@@ -139,16 +139,8 @@ export class ArduinoApp {
139
139
UsbDetector . getInstance ( ) . pauseListening ( ) ;
140
140
await vscode . workspace . saveAll ( false ) ;
141
141
142
- if ( dc . prebuild ) {
143
- arduinoChannel . info ( `Run prebuild command: ${ dc . prebuild } ` ) ;
144
- const prebuildargs = dc . prebuild . split ( " " ) ;
145
- const prebuildCommand = prebuildargs . shift ( ) ;
146
- try {
147
- await util . spawn ( prebuildCommand , arduinoChannel . channel , prebuildargs , { shell : true , cwd : ArduinoWorkspace . rootPath } ) ;
148
- } catch ( ex ) {
149
- arduinoChannel . error ( `Run prebuild failed: \n${ ex . error } ` ) ;
150
- return ;
151
- }
142
+ if ( ! await this . runPreBuildCommand ( dc ) ) {
143
+ return ;
152
144
}
153
145
154
146
if ( ! compile && ! this . useArduinoCli ( ) ) {
@@ -174,6 +166,10 @@ export class ArduinoApp {
174
166
args . push ( "--port" , dc . port ) ;
175
167
}
176
168
args . push ( appPath ) ;
169
+ if ( ! await this . runPreBuildCommand ( dc ) ) {
170
+ return ;
171
+ }
172
+
177
173
if ( VscodeSettings . getInstance ( ) . logLevel === "verbose" ) {
178
174
args . push ( "--verbose" ) ;
179
175
}
@@ -228,16 +224,8 @@ export class ArduinoApp {
228
224
229
225
arduinoChannel . start ( `Verify sketch - ${ dc . sketch } ` ) ;
230
226
231
- if ( dc . prebuild ) {
232
- arduinoChannel . info ( `Run prebuild command: ${ dc . prebuild } ` ) ;
233
- const prebuildargs = dc . prebuild . split ( " " ) ;
234
- const prebuildCommand = prebuildargs . shift ( ) ;
235
- try {
236
- await util . spawn ( prebuildCommand , arduinoChannel . channel , prebuildargs , { shell : true , cwd : ArduinoWorkspace . rootPath } ) ;
237
- } catch ( ex ) {
238
- arduinoChannel . error ( `Run prebuild failed: \n${ ex . error } ` ) ;
239
- return ;
240
- }
227
+ if ( ! await this . runPreBuildCommand ( dc ) ) {
228
+ return false ;
241
229
}
242
230
243
231
const appPath = path . join ( ArduinoWorkspace . rootPath , dc . sketch ) ;
@@ -779,6 +767,33 @@ export class ArduinoApp {
779
767
this . _programmerManager = value ;
780
768
}
781
769
770
+ /**
771
+ * Runs the pre build command.
772
+ * Usually before one of
773
+ * * verify
774
+ * * upload
775
+ * * upload using programmer
776
+ * @param dc Device context prepared during one of the above actions
777
+ * @returns True if successful, false on error.
778
+ */
779
+ protected async runPreBuildCommand ( dc : DeviceContext ) : Promise < boolean > {
780
+ if ( dc . prebuild ) {
781
+ arduinoChannel . info ( `Running pre-build command: ${ dc . prebuild } ` ) ;
782
+ const prebuildargs = dc . prebuild . split ( " " ) ;
783
+ const prebuildCommand = prebuildargs . shift ( ) ;
784
+ try {
785
+ await util . spawn ( prebuildCommand ,
786
+ arduinoChannel . channel ,
787
+ prebuildargs ,
788
+ { shell : true , cwd : ArduinoWorkspace . rootPath } ) ;
789
+ } catch ( ex ) {
790
+ arduinoChannel . error ( `Running pre-build command failed: ${ os . EOL } ${ ex . error } ` ) ;
791
+ return false ;
792
+ }
793
+ }
794
+ return true ;
795
+ }
796
+
782
797
/**
783
798
* Checks if the arduino cli is being used
784
799
* @returns {bool } - true if arduino cli is being use
0 commit comments