1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT license.
3
3
4
+ import * as ccp from "cocopa" ;
4
5
import * as fs from "fs" ;
5
6
import * as glob from "glob" ;
6
7
import * as os from "os" ;
7
8
import * as path from "path" ;
8
9
import * as vscode from "vscode" ;
9
- import * as ccp from "cocopa" ;
10
10
11
11
import * as constants from "../common/constants" ;
12
12
import * as util from "../common/util" ;
@@ -94,33 +94,6 @@ export class ArduinoApp {
94
94
}
95
95
}
96
96
97
- /** Runs the pre build command.
98
- * Usually before one of
99
- * * verify
100
- * * upload
101
- * * upload using programmer
102
- * @param dc Device context prepared during one of the above actions
103
- * @returns True if successful, false on error.
104
- */
105
- protected async runPreBuildCommand ( dc :DeviceContext ) : Promise < boolean >
106
- {
107
- if ( dc . prebuild ) {
108
- arduinoChannel . info ( `Running pre-build command: ${ dc . prebuild } ` ) ;
109
- const prebuildargs = dc . prebuild . split ( " " ) ;
110
- const prebuildCommand = prebuildargs . shift ( ) ;
111
- try {
112
- await util . spawn ( prebuildCommand ,
113
- arduinoChannel . channel ,
114
- prebuildargs ,
115
- { shell : true , cwd : ArduinoWorkspace . rootPath } ) ;
116
- } catch ( ex ) {
117
- arduinoChannel . error ( `Running pre-build command failed: ${ os . EOL } ${ ex . error } ` ) ;
118
- return false ;
119
- }
120
- }
121
- return true ;
122
- }
123
-
124
97
public async upload ( ) {
125
98
const dc = DeviceContext . getInstance ( ) ;
126
99
const boardDescriptor = this . getBoardBuildString ( ) ;
@@ -315,16 +288,17 @@ export class ArduinoApp {
315
288
arduinoChannel . show ( ) ;
316
289
317
290
try {
318
- let compilerParserContext = this . makeCompilerParserContext ( dc ) ;
291
+ const compilerParserContext = this . makeCompilerParserContext ( dc ) ;
319
292
320
293
await util . spawn ( this . _settings . commandPath ,
321
294
arduinoChannel . channel ,
322
295
args ,
323
296
{ } ,
324
297
compilerParserContext . callback ) ;
325
298
326
- compilerParserContext . conclude ( ) ;
327
-
299
+ if ( compilerParserContext . conclude ) {
300
+ compilerParserContext . conclude ( ) ;
301
+ }
328
302
arduinoChannel . end ( `Finished verify sketch - ${ dc . sketch } ${ os . EOL } ` ) ;
329
303
return true ;
330
304
} catch ( reason ) {
@@ -338,44 +312,6 @@ export class ArduinoApp {
338
312
}
339
313
}
340
314
341
- /** Creates a context which is used for compiler command parsing
342
- * during building (verify, upload, ...).
343
- *
344
- * This context makes sure that it can be used in those sections
345
- * without having to check whether this feature is en- or disabled
346
- * and keeps the calling context more readable.
347
- *
348
- * @param dc The device context of the caller.
349
- */
350
- private makeCompilerParserContext ( dc : DeviceContext )
351
- : { callback : ( s :string ) => void ; conclude : ( ) => void ; }
352
- {
353
- if ( ! VscodeSettings . getInstance ( ) . disableIntelliSenseAutoGen ) {
354
-
355
- // setup the parser with its engines
356
- let gccParserEngine = new ccp . ParserGcc ( dc . sketch ) ;
357
- let compilerParser = new ccp . Runner ( [ gccParserEngine ] ) ;
358
-
359
- // set up the function to be called after parsing
360
- let _conclude = ( ) => {
361
- let cppPropsPath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
362
- if ( compilerParser . processResult ( cppPropsPath ) ) {
363
- arduinoChannel . info ( "IntelliSense configuration generated successfully." ) ;
364
- } else {
365
- arduinoChannel . warning ( "Failed to generate IntelliSense configuration." ) ;
366
- }
367
- } ;
368
- return {
369
- callback : compilerParser . callback ( ) ,
370
- conclude : _conclude ,
371
- } ;
372
- }
373
- return {
374
- callback : undefined ,
375
- conclude : ( ) => void { } ,
376
- } ;
377
- } ;
378
-
379
315
public tryToUpdateIncludePaths ( ) {
380
316
const configFilePath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
381
317
if ( ! fs . existsSync ( configFilePath ) ) {
@@ -797,6 +733,72 @@ Please make sure the folder is not occupied by other procedures .`);
797
733
this . _programmerManager = value ;
798
734
}
799
735
736
+ /**
737
+ * Runs the pre build command.
738
+ * Usually before one of
739
+ * * verify
740
+ * * upload
741
+ * * upload using programmer
742
+ * @param dc Device context prepared during one of the above actions
743
+ * @returns True if successful, false on error.
744
+ */
745
+ protected async runPreBuildCommand ( dc : DeviceContext ) : Promise < boolean > {
746
+ if ( dc . prebuild ) {
747
+ arduinoChannel . info ( `Running pre-build command: ${ dc . prebuild } ` ) ;
748
+ const prebuildargs = dc . prebuild . split ( " " ) ;
749
+ const prebuildCommand = prebuildargs . shift ( ) ;
750
+ try {
751
+ await util . spawn ( prebuildCommand ,
752
+ arduinoChannel . channel ,
753
+ prebuildargs ,
754
+ { shell : true , cwd : ArduinoWorkspace . rootPath } ) ;
755
+ } catch ( ex ) {
756
+ arduinoChannel . error ( `Running pre-build command failed: ${ os . EOL } ${ ex . error } ` ) ;
757
+ return false ;
758
+ }
759
+ }
760
+ return true ;
761
+ }
762
+
763
+ /**
764
+ * Creates a context which is used for compiler command parsing
765
+ * during building (verify, upload, ...).
766
+ *
767
+ * This context makes sure that it can be used in those sections
768
+ * without having to check whether this feature is en- or disabled
769
+ * and keeps the calling context more readable.
770
+ *
771
+ * @param dc The device context of the caller.
772
+ */
773
+ private makeCompilerParserContext ( dc : DeviceContext )
774
+ : { callback : ( s : string ) => void ; conclude : ( ) => void ; } {
775
+ if ( ! VscodeSettings . getInstance ( ) . disableIntelliSenseAutoGen ) {
776
+
777
+ // setup the parser with its engines
778
+ const gccParserEngine = new ccp . ParserGcc ( dc . sketch ) ;
779
+ const compilerParser = new ccp . Runner ( [ gccParserEngine ] ) ;
780
+
781
+ // set up the function to be called after parsing
782
+ const _conclude = ( ) => {
783
+ const cppPropsPath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
784
+ if ( compilerParser . processResult ( cppPropsPath ) ) {
785
+ arduinoChannel . info ( "IntelliSense configuration generated successfully." ) ;
786
+ } else {
787
+ arduinoChannel . warning ( "Failed to generate IntelliSense configuration." ) ;
788
+ }
789
+ } ;
790
+ return {
791
+ callback : compilerParser . callback ( ) ,
792
+ conclude : _conclude ,
793
+ }
794
+ }
795
+ // const donothing = () => void {};
796
+ return {
797
+ callback : undefined ,
798
+ conclude : undefined ,
799
+ }
800
+ } ;
801
+
800
802
private getProgrammerString ( ) : string {
801
803
const selectProgrammer = this . programmerManager . currentProgrammer ;
802
804
if ( ! selectProgrammer ) {
0 commit comments