diff options
author | Matt Godbolt <matt@godbolt.org> | 2020-01-14 22:05:34 -0600 |
---|---|---|
committer | Matt Godbolt <matt@godbolt.org> | 2020-01-14 22:06:05 -0600 |
commit | 7e789a80b4cd858da175a53237b57cdcca65b58c (patch) | |
tree | 14ecb2533dea8516e4f10adf5ef64046819dac45 /lib | |
parent | b28d2cf8f982df6017fc2da02552286f22fab4b7 (diff) | |
download | compiler-explorer-7e789a80b4cd858da175a53237b57cdcca65b58c.tar.gz compiler-explorer-7e789a80b4cd858da175a53237b57cdcca65b58c.zip |
Compiler finder async and fixups
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compiler-finder.js | 77 | ||||
-rw-r--r-- | lib/handlers/compile.js | 2 |
2 files changed, 34 insertions, 45 deletions
diff --git a/lib/compiler-finder.js b/lib/compiler-finder.js index 3baea8bcd..35e464096 100644 --- a/lib/compiler-finder.js +++ b/lib/compiler-finder.js @@ -61,7 +61,7 @@ class CompilerFinder { const requestLib = port === 443 ? https : http; const uriSchema = port === 443 ? "https" : "http"; const uri = urljoin(`${uriSchema}://${host}:${port}`, uriBase); - let apiPath = urljoin('/', uriBase || '', 'api/compilers', langId || ''); + const apiPath = urljoin('/', uriBase || '', 'api/compilers', langId || ''); logger.info(`Fetching compilers from remote source ${uri}`); return this.retryPromise( () => { @@ -134,29 +134,23 @@ class CompilerFinder { }); } - fetchAws() { + async fetchAws() { logger.info("Fetching instances from AWS"); - return this.awsInstances().then(instances => { - return Promise.all(instances.map(instance => { - logger.info("Checking instance " + instance.InstanceId); - let address = instance.PrivateDnsName; - if (this.awsProps("externalTestMode", false)) { - address = instance.PublicDnsName; - } - return this.fetchRemote(address, this.args.port, '', this.awsProps, null); - })); - }); + const instances = await this.awsInstances(); + return Promise.all(instances.map(instance => { + logger.info("Checking instance " + instance.InstanceId); + const address = this.awsProps("externalTestMode", false) ? instance.PublicDnsName : instance.PrivateDnsName; + return this.fetchRemote(address, this.args.port, '', this.awsProps, null); + })); } - compilerConfigFor(langId, compilerName, parentProps) { + async compilerConfigFor(langId, compilerName, parentProps) { const base = `compiler.${compilerName}.`; function props(propName, def) { - let propsForCompiler = parentProps(langId, base + propName, undefined); - if (propsForCompiler === undefined) { - propsForCompiler = parentProps(langId, propName, def); - } - return propsForCompiler; + const propsForCompiler = parentProps(langId, base + propName, undefined); + if (propsForCompiler !== undefined) return propsForCompiler; + return parentProps(langId, propName, def); } const ceToolsPath = props("ceToolsPath", "./"); @@ -172,11 +166,11 @@ class CompilerFinder { const semverVer = props("semver", ""); const name = props("name", compilerName); const envVars = (() => { - let envVarsString = props("envVars", ""); + const envVarsString = props("envVars", ""); if (envVarsString === "") { return []; } else { - let arr = []; + const arr = []; for (const el of envVarsString.split(':')) { const [env, setting] = el.split('='); arr.push([env, setting]); @@ -226,10 +220,10 @@ class CompilerFinder { unwiseOptions: props("unwiseOptions", "").split("|") }; logger.debug("Found compiler", compilerInfo); - return Promise.resolve(compilerInfo); + return compilerInfo; } - recurseGetCompilers(langId, compilerName, parentProps) { + async recurseGetCompilers(langId, compilerName, parentProps) { // Don't treat @ in paths as remote addresses if requested if (this.args.fetchCompilersFromRemote && compilerName.indexOf("@") !== -1) { const bits = compilerName.split("@"); @@ -256,17 +250,16 @@ class CompilerFinder { return this.compilerConfigFor(langId, compilerName, parentProps); } - getCompilers() { - this.getExes(); - let compilers = []; - _.each(this.exes, (exs, langId) => { + async getCompilers() { + const compilers = []; + _.each(this.getExes(), (exs, langId) => { _.each(exs, exe => compilers.push(this.recurseGetCompilers(langId, exe, this.compilerProps))); }); - return compilers; + return Promise.all(compilers); } ensureDistinct(compilers) { - let ids = {}; + const ids = {}; let foundClash = false; _.each(compilers, compiler => { if (!ids[compiler.id]) ids[compiler.id] = []; @@ -307,16 +300,17 @@ class CompilerFinder { } getExes() { - this.exes = this.compilerProps(this.languages, "compilers", "", exs => _.compact(exs.split(":"))); - logger.info('Exes found:', this.exes); - this.getNdkExes(); + const langToCompilers = this.compilerProps(this.languages, "compilers", "", exs => _.compact(exs.split(":"))); + this.addNdkExes(langToCompilers); + logger.info('Exes found:', langToCompilers); + return langToCompilers; } - getNdkExes() { + addNdkExes(langToCompilers) { const ndkPaths = this.compilerProps(this.languages, 'androidNdk'); _.each(ndkPaths, (ndkPath, langId) => { if (ndkPath) { - let toolchains = fs.readdirSync(`${ndkPath}/toolchains`); + const toolchains = fs.readdirSync(`${ndkPath}/toolchains`); toolchains.forEach((version, index, a) => { const path = `${ndkPath}/toolchains/${version}/prebuilt/linux-x86_64/bin/`; if (fs.existsSync(path)) { @@ -326,21 +320,16 @@ class CompilerFinder { a[index] = null; } }); - toolchains = toolchains.filter(x => x !== null); - this.exes[langId].push(toolchains); + langToCompilers[langId].push(toolchains.filter(x => x !== null)); } }); } - find() { - return Promise.all(this.getCompilers()) - .then(_.flatten) - .then(compilers => this.compileHandler.setCompilers(compilers)) - .then(compilers => _.compact(compilers)) - .then(this.ensureDistinct) - .then(result => { - return {foundClash: result.foundClash, compilers: _.sortBy(result.compilers, "name")}; - }); + async find() { + const compilers = (await this.getCompilers()).flat(Infinity); + await this.compileHandler.setCompilers(compilers); + const result = this.ensureDistinct(_.compact(compilers)); + return {foundClash: result.foundClash, compilers: _.sortBy(result.compilers, "name")}; } } diff --git a/lib/handlers/compile.js b/lib/handlers/compile.js index ffc9179d4..5e37b1dd7 100644 --- a/lib/handlers/compile.js +++ b/lib/handlers/compile.js @@ -131,7 +131,7 @@ class CompileHandler { } } - setCompilers(compilers) { + async setCompilers(compilers) { // Be careful not to update this.compilersById until we can replace it entirely. const compilersById = {}; return Promise.all(_.map(compilers, this.create, this)) |