1
1
import { inject , injectable } from 'inversify' ;
2
2
import { FileSystem } from '@theia/filesystem/lib/common/filesystem' ;
3
3
import { CoreService } from '../common/protocol/core-service' ;
4
- import { CompileReq } from './cli-protocol/compile_pb' ;
4
+ import { CompileReq , CompileResp } from './cli-protocol/compile_pb' ;
5
5
import { BoardsService } from '../common/protocol/boards-service' ;
6
6
import { CoreClientProvider } from './core-client-provider' ;
7
- import { PlatformInstallReq } from './cli-protocol/core_pb ' ;
8
- import { LibraryInstallReq } from './cli- protocol/lib_pb ' ;
7
+ import * as path from 'path ' ;
8
+ import { ToolOutputServiceServer } from '../common/ protocol/tool-output-service ' ;
9
9
10
10
@injectable ( )
11
11
export class CoreServiceImpl implements CoreService {
@@ -19,13 +19,17 @@ export class CoreServiceImpl implements CoreService {
19
19
@inject ( BoardsService )
20
20
protected readonly boardsService : BoardsService ;
21
21
22
- async compile ( options : CoreService . Compile . Options ) : Promise < string > {
22
+ @inject ( ToolOutputServiceServer )
23
+ protected readonly toolOutputService : ToolOutputServiceServer ;
24
+
25
+ async compile ( options : CoreService . Compile . Options ) : Promise < void > {
23
26
console . log ( 'compile' , options ) ;
24
27
const { uri } = options ;
25
- const sketchpath = await this . fileSystem . getFsPath ( options . uri ) ;
26
- if ( ! sketchpath ) {
28
+ const sketchFilePath = await this . fileSystem . getFsPath ( options . uri ) ;
29
+ if ( ! sketchFilePath ) {
27
30
throw new Error ( `Cannot resolve filesystem path for URI: ${ uri } .` ) ;
28
31
}
32
+ const sketchpath = path . dirname ( sketchFilePath ) ;
29
33
30
34
const { client, instance } = await this . coreClientProvider . getClient ( uri ) ;
31
35
// const boards = await this.boardsService.connectedBoards();
@@ -34,38 +38,30 @@ export class CoreServiceImpl implements CoreService {
34
38
// }
35
39
// https://github.com/cmaglie/arduino-cli/blob/bd5e78701e7546787649d3cca6b21c5d22d0e438/cli/compile/compile.go#L78-L88
36
40
37
- const installLibReq = new LibraryInstallReq ( ) ;
38
- installLibReq . setInstance ( instance ) ;
39
- installLibReq . setName ( 'arduino:samd' ) ;
40
- const installResp = client . libraryInstall ( installLibReq ) ;
41
- const xxx = await new Promise < string > ( ( resolve , reject ) => {
42
- const chunks : Buffer [ ] = [ ] ;
43
- installResp . on ( 'data' , ( chunk : Buffer ) => chunks . push ( chunk ) ) ;
44
- installResp . on ( 'error' , error => reject ( error ) ) ;
45
- installResp . on ( 'end' , ( ) => resolve ( Buffer . concat ( chunks ) . toString ( 'utf8' ) . trim ( ) ) )
46
- } ) ;
47
- console . log ( 'xxx' , xxx ) ;
48
-
49
41
const compilerReq = new CompileReq ( ) ;
50
42
compilerReq . setInstance ( instance ) ;
51
43
compilerReq . setSketchpath ( sketchpath ) ;
52
- compilerReq . setFqbn ( 'arduino:samd ' /*boards.current.name*/ ) ;
44
+ compilerReq . setFqbn ( 'arduino:avr:uno ' /*boards.current.name*/ ) ;
53
45
// request.setShowproperties(false);
54
- // request .setPreprocess(false);
46
+ compilerReq . setPreprocess ( false ) ;
55
47
// request.setBuildcachepath('');
56
- // request.setBuildpath('');
48
+ // compilerReq.setBuildpath('/tmp/build');
49
+ // compilerReq.setShowproperties(true);
57
50
// request.setBuildpropertiesList([]);
58
51
// request.setWarnings('none');
59
- // request .setVerbose(true);
60
- // request .setQuiet(false);
52
+ compilerReq . setVerbose ( true ) ;
53
+ compilerReq . setQuiet ( false ) ;
61
54
// request.setVidpid('');
62
55
// request.setExportfile('');
56
+
63
57
const result = client . compile ( compilerReq ) ;
64
- return new Promise < string > ( ( resolve , reject ) => {
65
- const chunks : Buffer [ ] = [ ] ;
66
- result . on ( 'data' , ( chunk : Buffer ) => chunks . push ( chunk ) ) ;
58
+ return new Promise < void > ( ( resolve , reject ) => {
59
+ result . on ( 'data' , ( cr : CompileResp ) => {
60
+ this . toolOutputService . publishNewOutput ( "compile" , new Buffer ( cr . getOutStream_asU8 ( ) ) . toString ( ) ) ;
61
+ console . error ( cr . getErrStream ( ) . toString ( ) ) ;
62
+ } ) ;
67
63
result . on ( 'error' , error => reject ( error ) ) ;
68
- result . on ( 'end' , ( ) => resolve ( Buffer . concat ( chunks ) . toString ( 'utf8' ) . trim ( ) ) )
64
+ result . on ( 'end' , ( ) => resolve ( ) ) ;
69
65
} ) ;
70
66
}
71
67
0 commit comments