1
1
import { join } from 'path' ;
2
2
3
- // import { EOL } from 'os';
4
-
5
3
import { OutputtingProcess } from '../../OutputtingProcess' ;
6
4
7
5
import { FileSystem } from '../file_system/FileSystem' ;
8
6
9
7
import ChildLogger from '../logging/child_logger' ;
10
8
9
+ import * as OutputChannelProcess from '../../OutputChannelProcess' ;
10
+
11
11
namespace Constants {
12
12
export const DEFAULT_TOOLCHAIN_SUFFIX = '(default)' ;
13
13
}
@@ -112,14 +112,15 @@ export class Rustup {
112
112
* @return true if no error occurred and the toolchain has been installed otherwise false
113
113
*/
114
114
public async installToolchain ( toolchain : string ) : Promise < boolean > {
115
- const logger = this . logger . createChildLogger ( `installToolchain: toolchain=${ toolchain } ` ) ;
116
- const output = await Rustup . invoke ( [ 'toolchain' , 'install' , toolchain ] , logger ) ;
117
- if ( output ) {
118
- logger . debug ( `output= ${ output } ` ) ;
119
- } else {
115
+ const logger = this . logger . createChildLogger ( `installToolchain( toolchain=${ toolchain } ): ` ) ;
116
+ const args = [ 'toolchain' , 'install' , toolchain ] ;
117
+ const outputChannelName = `Rustup: Installing ${ toolchain } toolchain` ;
118
+ const output = await Rustup . invokeWithOutputChannel ( args , logger , outputChannelName ) ;
119
+ if ( output === undefined ) {
120
120
logger . error ( `output=${ output } ` ) ;
121
121
return false ;
122
122
}
123
+ logger . debug ( `output=${ output } ` ) ;
123
124
await this . updateToolchains ( ) ;
124
125
if ( this . toolchains . length === 0 ) {
125
126
logger . error ( 'this.toolchains.length === 0' ) ;
@@ -320,7 +321,8 @@ export class Rustup {
320
321
* @return The output of the invocation if the invocation exited successfully otherwise undefined
321
322
*/
322
323
private static async invokeGettingSysrootPath ( toolchain : string , logger : ChildLogger ) : Promise < string | undefined > {
323
- const output : string | undefined = await this . invokeRun ( toolchain , [ 'rustc' , '--print' , 'sysroot' ] , logger ) ;
324
+ const args = [ 'run' , toolchain , 'rustc' , '--print' , 'sysroot' ] ;
325
+ const output : string | undefined = await this . invoke ( args , logger ) ;
324
326
if ( ! output ) {
325
327
return undefined ;
326
328
}
@@ -337,16 +339,6 @@ export class Rustup {
337
339
return output . trim ( ) . split ( '\n' ) ;
338
340
}
339
341
340
- /**
341
- * Invokes `rustup run...` with the specified toolchain and arguments, checks if it exited successfully and returns its output
342
- * @param toolchain The toolchain to invoke rustup with
343
- * @param args The arguments to invoke rustup with
344
- * @param logger The logger to log messages
345
- */
346
- private static async invokeRun ( toolchain : string , args : string [ ] , logger : ChildLogger ) : Promise < string | undefined > {
347
- return await this . invoke ( [ 'run' , toolchain , ...args ] , logger ) ;
348
- }
349
-
350
342
/**
351
343
* Invokes Rustup with specified arguments, checks if it exited successfully and returns its output
352
344
* @param args Arguments to invoke Rustup with
@@ -368,6 +360,34 @@ export class Rustup {
368
360
return result . stdoutData ;
369
361
}
370
362
363
+ /**
364
+ * Invokes rustup with the specified arguments, creates an output channel with the specified
365
+ * name, writes output of the invocation and returns the output
366
+ * @param args The arguments which to invoke rustup with
367
+ * @param logger The logger to log messages
368
+ * @param outputChannelName The name which to create an output channel with
369
+ */
370
+ private static async invokeWithOutputChannel ( args : string [ ] , logger : ChildLogger ,
371
+ outputChannelName : string ) : Promise < string | undefined > {
372
+ const functionLogger = logger . createChildLogger ( `invokeWithOutputChannel(args=${ JSON . stringify ( args ) } , outputChannelName=${ outputChannelName } ): ` ) ;
373
+ const result = await OutputChannelProcess . create ( this . getRustupExecutable ( ) , args , undefined , outputChannelName ) ;
374
+ if ( ! result . success ) {
375
+ functionLogger . error ( 'failed to start' ) ;
376
+ return undefined ;
377
+ }
378
+ if ( result . code !== 0 ) {
379
+ functionLogger . error ( `exited with not zero; code=${ result . code } ` ) ;
380
+ functionLogger . error ( 'Beginning of stdout' ) ;
381
+ functionLogger . error ( result . stdout ) ;
382
+ functionLogger . error ( 'Ending of stdout' ) ;
383
+ functionLogger . error ( 'Beginning of stderr' ) ;
384
+ functionLogger . error ( result . stderr ) ;
385
+ functionLogger . error ( 'Ending of stderr' ) ;
386
+ return undefined ;
387
+ }
388
+ return result . stdout ;
389
+ }
390
+
371
391
/**
372
392
* Constructs a new instance of the class.
373
393
* The constructor is private because creating a new instance should be done via the method `create`
@@ -415,10 +435,10 @@ export class Rustup {
415
435
return true ;
416
436
}
417
437
const args = [ 'component' , 'add' , componentName , '--toolchain' , 'nightly' ] ;
418
- const stdoutData : string | undefined = await Rustup . invoke ( args , logger ) ;
419
- // Some error occurred. It is already logged in the method invokeRustup.
420
- // So we just need to notify a caller that the installation failed
438
+ const stdoutData = await Rustup . invokeWithOutputChannel ( args , logger , `Rustup: Installing ${ componentName } ` ) ;
421
439
if ( stdoutData === undefined ) {
440
+ // Some error occurred. It is already logged
441
+ // So we just need to notify a caller that the installation failed
422
442
return false ;
423
443
}
424
444
await this . updateComponents ( ) ;
0 commit comments