Merge pull request #437 from embark-framework/no_solc_reload

don't unnecessary reload solc
This commit is contained in:
Iuri Matias 2018-05-18 13:55:39 -04:00 committed by GitHub
commit 566bcc71ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -7,6 +7,8 @@ class Solidity {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.contractDirectories = options.contractDirectories; this.contractDirectories = options.contractDirectories;
this.solcAlreadyLoaded = false;
this.solcW = null;
embark.registerCompiler(".sol", this.compile_solidity.bind(this)); embark.registerCompiler(".sol", this.compile_solidity.bind(this));
} }
@ -17,7 +19,6 @@ class Solidity {
} }
let self = this; let self = this;
let input = {}; let input = {};
let solcW;
async.waterfall([ async.waterfall([
function prepareInput(callback) { function prepareInput(callback) {
async.each(contractFiles, async.each(contractFiles,
@ -44,14 +45,14 @@ class Solidity {
); );
}, },
function loadCompiler(callback) { function loadCompiler(callback) {
// TODO: there ino need to load this twice if (self.solcAlreadyLoaded) {
solcW = new SolcW({logger: self.logger, events: self.events});
if (solcW.isCompilerLoaded()) {
return callback(); return callback();
} }
self.solcW = new SolcW({logger: self.logger, events: self.events});
self.logger.info(__("loading solc compiler") + ".."); self.logger.info(__("loading solc compiler") + "..");
solcW.load_compiler(function (err) { self.solcW.load_compiler(function (err) {
self.solcAlreadyLoaded = true;
callback(err); callback(err);
}); });
}, },
@ -73,7 +74,7 @@ class Solidity {
} }
}; };
solcW.compile(jsonObj, function (output) { self.solcW.compile(jsonObj, function (output) {
if (output.errors) { if (output.errors) {
for (let i=0; i<output.errors.length; i++) { for (let i=0; i<output.errors.length; i++) {
if (output.errors[i].type === 'Warning') { if (output.errors[i].type === 'Warning') {

View File

@ -49,7 +49,9 @@ class SolcW {
} }
compile(jsonObj, done) { compile(jsonObj, done) {
const self = this;
this.solcProcess.subscribeTo('result', 'compilation', (msg) => { this.solcProcess.subscribeTo('result', 'compilation', (msg) => {
self.solcProcess.unsubscribeTo('result', 'compilation');
done(JSON.parse(msg.output)); done(JSON.parse(msg.output));
}); });