From d350ec1c1ad40e3545ce08719d035d29c421bf89 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Sun, 30 Jul 2017 09:46:29 -0500 Subject: [PATCH] Only stat compilers if absolute. Fixes #487 --- lib/compile-handler.js | 43 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/compile-handler.js b/lib/compile-handler.js index 4e342d6b2..48d84b4cc 100644 --- a/lib/compile-handler.js +++ b/lib/compile-handler.js @@ -25,6 +25,7 @@ var child_process = require('child_process'), temp = require('temp'), fs = require('fs'), + path = require('path'), httpProxy = require('http-proxy'), Promise = require('promise'), // jshint ignore:line quote = require('shell-quote'), @@ -63,26 +64,32 @@ function CompileHandler(gccProps, compilerProps) { this.create = function (compiler) { var type = compiler.compilerType || "default"; if (this.factories[type] === undefined) { - var path = './compilers/' + type; - logger.info("Loading compiler from", path); - this.factories[type] = require(path); + var compilerPath = './compilers/' + type; + logger.info("Loading compiler from", compilerPath); + this.factories[type] = require(compilerPath); } - return this.stat(compiler.exe) - .then(_.bind(function (res) { - var cached = this.compilersById[compiler.id]; - if (cached && cached.mtime.getTime() === res.mtime.getTime()) { - logger.debug(compiler.id + " is unchanged"); - return cached; - } - return this.factories[type](compiler, this.compilerEnv).then(function (compiler) { - compiler.mtime = res.mtime; - return compiler; + if (path.isAbsolute(compiler.exe)) { + // Try stat'ing the compiler to cache its mtime and only re-run it if it + // has changed since the last time. + return this.stat(compiler.exe) + .then(_.bind(function (res) { + var cached = this.compilersById[compiler.id]; + if (cached && cached.mtime.getTime() === res.mtime.getTime()) { + logger.debug(compiler.id + " is unchanged"); + return cached; + } + return this.factories[type](compiler, this.compilerEnv).then(function (compiler) { + compiler.mtime = res.mtime; + return compiler; + }); + }, this)) + .catch(function (err) { + logger.warn("Unable to stat compiler binary", err); + return null; }); - }, this)) - .catch(function(err) { - logger.warn("Unable to stat compiler binary", err); - return null; - }); + } else { + return this.factories[type](compiler, this.compilerEnv); + } }; this.setCompilers = function (compilers) {