@@ -85,6 +85,24 @@ export class CompilerFinder {
8585 return this . awsPoller . getInstances ( ) ;
8686 }
8787
88+ static prepareRemoteUrlParts ( host : string , port : number , uriBase : string , langId : string | null ) {
89+ const uriSchema = port === 443 ? 'https' : 'http' ;
90+ return {
91+ uriSchema : uriSchema ,
92+ uri : urljoin ( `${ uriSchema } ://${ host } :${ port } ` , uriBase ) ,
93+ apiPath : urljoin ( '/' , uriBase || '' , 'api/compilers' , langId || '' , '?fields=all' ) ,
94+ } ;
95+ }
96+
97+ static getRemoteInfo ( uriSchema : string , host : string , port : number , uriBase : string , compilerId : string ) {
98+ return {
99+ target : `${ uriSchema } ://${ host } :${ port } ` ,
100+ path : urljoin ( '/' , uriBase , 'api/compiler' , compilerId , 'compile' ) ,
101+ cmakePath : urljoin ( '/' , uriBase , 'api/compiler' , compilerId , 'cmake' ) ,
102+ basePath : urljoin ( '/' , uriBase ) ,
103+ } ;
104+ }
105+
88106 async fetchRemote (
89107 host : string ,
90108 port : number ,
@@ -93,9 +111,7 @@ export class CompilerFinder {
93111 langId : string | null ,
94112 ) : Promise < CompilerInfo [ ] | null > {
95113 const requestLib = port === 443 ? https : http ;
96- const uriSchema = port === 443 ? 'https' : 'http' ;
97- const uri = urljoin ( `${ uriSchema } ://${ host } :${ port } ` , uriBase ) ;
98- const apiPath = urljoin ( '/' , uriBase || '' , 'api/compilers' , langId || '' , '?fields=all' ) ;
114+ const { uriSchema, uri, apiPath} = CompilerFinder . prepareRemoteUrlParts ( host , port , uriBase , langId ) ;
99115 logger . info ( `Fetching compilers from remote source ${ uri } ` ) ;
100116 return this . retryPromise (
101117 ( ) => {
@@ -150,11 +166,13 @@ export class CompilerFinder {
150166 if ( typeof compiler . alias == 'string' ) compiler . alias = [ compiler . alias ] ;
151167 // End fixup
152168 compiler . exe = '/dev/null' ;
153- compiler . remote = {
154- target : `${ uriSchema } ://${ host } :${ port } ` ,
155- path : urljoin ( '/' , uriBase , 'api/compiler' , compiler . id , 'compile' ) ,
156- cmakePath : urljoin ( '/' , uriBase , 'api/compiler' , compiler . id , 'cmake' ) ,
157- } ;
169+ compiler . remote = CompilerFinder . getRemoteInfo (
170+ uriSchema ,
171+ host ,
172+ port ,
173+ uriBase ,
174+ compiler . id ,
175+ ) ;
158176 return compiler ;
159177 } ) ;
160178 resolve ( compilers ) ;
@@ -369,19 +387,25 @@ export class CompilerFinder {
369387 . filter ( a => a !== '' ) ;
370388 }
371389
390+ static getRemotePartsFromCompilerName ( remoteCompilerName : string ) {
391+ const bits = remoteCompilerName . split ( '@' ) ;
392+ const pathParts = bits [ 1 ] . split ( '/' ) ;
393+ return {
394+ host : bits [ 0 ] ,
395+ port : parseInt ( unwrap ( pathParts . shift ( ) ) ) ,
396+ uriBase : pathParts . join ( '/' ) ,
397+ } ;
398+ }
399+
372400 async recurseGetCompilers (
373401 langId : string ,
374402 compilerName : string ,
375403 parentProps : CompilerProps [ 'get' ] ,
376404 ) : Promise < PreliminaryCompilerInfo [ ] > {
377405 // Don't treat @ in paths as remote addresses if requested
378406 if ( this . args . fetchCompilersFromRemote && compilerName . includes ( '@' ) ) {
379- const bits = compilerName . split ( '@' ) ;
380- const host = bits [ 0 ] ;
381- const pathParts = bits [ 1 ] . split ( '/' ) ;
382- const port = parseInt ( unwrap ( pathParts . shift ( ) ) ) ;
383- const path = pathParts . join ( '/' ) ;
384- return ( await this . fetchRemote ( host , port , path , this . ceProps , langId ) ) || [ ] ;
407+ const { host, port, uriBase} = CompilerFinder . getRemotePartsFromCompilerName ( compilerName ) ;
408+ return ( await this . fetchRemote ( host , port , uriBase , this . ceProps , langId ) ) || [ ] ;
385409 }
386410 if ( compilerName . indexOf ( '&' ) === 0 ) {
387411 const groupName = compilerName . substring ( 1 ) ;
0 commit comments