1
1
import { FileUri } from '@theia/core/lib/node/file-uri' ;
2
2
import { inject , injectable } from 'inversify' ;
3
- import { dirname } from 'path' ;
3
+ import { relative } from 'path' ;
4
+ import * as jspb from 'google-protobuf' ;
4
5
import { CoreService } from '../common/protocol/core-service' ;
5
6
import { CompileReq , CompileResp } from './cli-protocol/commands/compile_pb' ;
6
7
import { CoreClientProvider } from './core-client-provider' ;
@@ -24,17 +25,15 @@ export class CoreServiceImpl implements CoreService {
24
25
protected readonly notificationService : NotificationServiceServer ;
25
26
26
27
async compile ( options : CoreService . Compile . Options & { exportBinaries : boolean } ) : Promise < void > {
27
- this . outputService . append ( { chunk : 'Compile...\n' + JSON . stringify ( options , null , 2 ) + '\n--------------------------\n' } ) ;
28
28
const { sketchUri, fqbn } = options ;
29
- const sketchFilePath = FileUri . fsPath ( sketchUri ) ;
30
- const sketchpath = dirname ( sketchFilePath ) ;
29
+ const sketchPath = FileUri . fsPath ( sketchUri ) ;
31
30
32
31
const coreClient = await this . coreClient ( ) ;
33
32
const { client, instance } = coreClient ;
34
33
35
34
const compilerReq = new CompileReq ( ) ;
36
35
compilerReq . setInstance ( instance ) ;
37
- compilerReq . setSketchpath ( sketchpath ) ;
36
+ compilerReq . setSketchpath ( sketchPath ) ;
38
37
if ( fqbn ) {
39
38
compilerReq . setFqbn ( fqbn ) ;
40
39
}
@@ -43,6 +42,7 @@ export class CoreServiceImpl implements CoreService {
43
42
compilerReq . setVerbose ( options . verbose ) ;
44
43
compilerReq . setQuiet ( false ) ;
45
44
compilerReq . setExportBinaries ( options . exportBinaries ) ;
45
+ this . mergeSourceOverrides ( compilerReq , options ) ;
46
46
47
47
const result = client . compile ( compilerReq ) ;
48
48
try {
@@ -76,18 +76,15 @@ export class CoreServiceImpl implements CoreService {
76
76
task : string = 'upload' ) : Promise < void > {
77
77
78
78
await this . compile ( Object . assign ( options , { exportBinaries : false } ) ) ;
79
- const chunk = firstToUpperCase ( task ) + '...\n' ;
80
- this . outputService . append ( { chunk : chunk + JSON . stringify ( options , null , 2 ) + '\n--------------------------\n' } ) ;
81
79
const { sketchUri, fqbn, port, programmer } = options ;
82
- const sketchFilePath = FileUri . fsPath ( sketchUri ) ;
83
- const sketchpath = dirname ( sketchFilePath ) ;
80
+ const sketchPath = FileUri . fsPath ( sketchUri ) ;
84
81
85
82
const coreClient = await this . coreClient ( ) ;
86
83
const { client, instance } = coreClient ;
87
84
88
85
const req = requestProvider ( ) ;
89
86
req . setInstance ( instance ) ;
90
- req . setSketchPath ( sketchpath ) ;
87
+ req . setSketchPath ( sketchPath ) ;
91
88
if ( fqbn ) {
92
89
req . setFqbn ( fqbn ) ;
93
90
}
@@ -169,4 +166,15 @@ export class CoreServiceImpl implements CoreService {
169
166
return coreClient ;
170
167
}
171
168
169
+ private mergeSourceOverrides ( req : { getSourceOverrideMap ( ) : jspb . Map < string , string > } , options : CoreService . Compile . Options ) : void {
170
+ const sketchPath = FileUri . fsPath ( options . sketchUri ) ;
171
+ for ( const uri of Object . keys ( options . sourceOverride ) ) {
172
+ const content = options . sourceOverride [ uri ] ;
173
+ if ( content ) {
174
+ const relativePath = relative ( sketchPath , FileUri . fsPath ( uri ) ) ;
175
+ req . getSourceOverrideMap ( ) . set ( relativePath , content ) ;
176
+ }
177
+ }
178
+ }
179
+
172
180
}
0 commit comments