2017-03-29 17:18:00 +00:00
|
|
|
let async = require('../utils/async_extend.js');
|
2017-02-17 12:14:44 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
class Compiler {
|
|
|
|
constructor(options) {
|
|
|
|
this.plugins = options.plugins;
|
|
|
|
this.logger = options.logger;
|
|
|
|
}
|
2017-01-29 02:31:09 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
compile_contracts(contractFiles, cb) {
|
2018-04-11 13:47:55 +00:00
|
|
|
const self = this;
|
2017-12-16 20:39:30 +00:00
|
|
|
let available_compilers = {};
|
2017-01-29 02:31:09 +00:00
|
|
|
|
2018-04-26 18:15:43 +00:00
|
|
|
if (contractFiles.length === 0) {
|
|
|
|
return cb(null, {});
|
|
|
|
}
|
|
|
|
|
2018-04-11 13:47:55 +00:00
|
|
|
let pluginCompilers = self.plugins.getPluginsProperty('compilers', 'compilers');
|
2017-12-29 13:26:31 +00:00
|
|
|
pluginCompilers.forEach(function (compilerObject) {
|
|
|
|
available_compilers[compilerObject.extension] = compilerObject.cb;
|
|
|
|
});
|
2017-01-29 02:31:09 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
let compiledObject = {};
|
2017-01-29 02:31:09 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
async.eachObject(available_compilers,
|
|
|
|
function (extension, compiler, callback) {
|
|
|
|
let matchingFiles = contractFiles.filter(function (file) {
|
2017-06-29 11:39:12 +00:00
|
|
|
let fileMatch = file.filename.match(/\.[0-9a-z]+$/);
|
2018-04-11 13:47:55 +00:00
|
|
|
if (fileMatch && (fileMatch[0] === extension)) {
|
|
|
|
file.compiled = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
2016-08-14 12:04:34 +00:00
|
|
|
|
2018-05-17 14:02:53 +00:00
|
|
|
if (!matchingFiles || !matchingFiles.length) {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
compiler.call(compiler, matchingFiles, function (err, compileResult) {
|
2017-03-30 11:12:39 +00:00
|
|
|
Object.assign(compiledObject, compileResult);
|
|
|
|
callback(err, compileResult);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function (err) {
|
2018-04-11 13:47:55 +00:00
|
|
|
contractFiles.forEach(file => {
|
|
|
|
if (!file.compiled) {
|
|
|
|
self.logger.warn(`${file.filename} doesn't have a compatible contract compiler. Maybe a plugin exists for it.`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
cb(err, compiledObject);
|
2017-02-25 20:47:35 +00:00
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-08-14 12:04:34 +00:00
|
|
|
|
|
|
|
module.exports = Compiler;
|