fix: fix race condition by using the new compiler api
This commit is contained in:
parent
1be928a525
commit
0fdea9d20c
20
index.js
20
index.js
|
@ -1,30 +1,38 @@
|
||||||
/*global require, module*/
|
/*global require, module*/
|
||||||
const Compiler = require("./lib/Compiler");
|
const Compiler = require("./lib/Compiler");
|
||||||
|
const semver = require('semver');
|
||||||
|
|
||||||
module.exports = (embark) => {
|
module.exports = (embark) => {
|
||||||
if (embark.config.embarkConfig.versions.solc) {
|
if (embark.config.embarkConfig.versions.solc) {
|
||||||
|
const versionPromise = new Promise(function(resolve, reject) {
|
||||||
// Check solc version
|
// Check solc version
|
||||||
Compiler.getSolcVersion(embark.logger, (err, version) => {
|
Compiler.getSolcVersion(embark.logger, (err, version) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
embark.logger.error(err);
|
embark.logger.error(err);
|
||||||
embark.logger.error("Error getting solc's version. Will default back to Embark's commpiler");
|
embark.logger.error("Error getting solc's version. Will default back to Embark's compiler");
|
||||||
return;
|
return reject(err);
|
||||||
}
|
}
|
||||||
const wantedVer = embark.config.embarkConfig.versions.solc.split('.').map(ver => parseInt(ver, 10));
|
if (semver.lt(version, embark.config.embarkConfig.versions.solc)) {
|
||||||
const currentVer = version.split('.').map(ver => parseInt(ver, 10));
|
|
||||||
if (wantedVer[0] > currentVer[0] || wantedVer[1] > currentVer[1] || wantedVer[2] > currentVer[2]) {
|
|
||||||
embark.logger.warn(`Current version of solc lower than version in embark.json`);
|
embark.logger.warn(`Current version of solc lower than version in embark.json`);
|
||||||
embark.logger.warn(`Current: ${version} | Wanted: ${embark.config.embarkConfig.versions.solc}`);
|
embark.logger.warn(`Current: ${version} | Wanted: ${embark.config.embarkConfig.versions.solc}`);
|
||||||
embark.logger.warn('Will default back to Embark\'s compiler');
|
embark.logger.warn('Will default back to Embark\'s compiler');
|
||||||
return;
|
return reject(new Error('Bad version'));
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
embark.registerCompiler('.sol', (contractFiles, options, cb) => {
|
embark.registerCompiler('.sol', (contractFiles, options, cb) => {
|
||||||
if (!contractFiles || !contractFiles.length) {
|
if (!contractFiles || !contractFiles.length) {
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
versionPromise.then(() => {
|
||||||
Compiler.compileSolc(embark, contractFiles, embark.config.contractDirectories, cb);
|
Compiler.compileSolc(embark, contractFiles, embark.config.contractDirectories, cb);
|
||||||
|
}).catch(_e => {
|
||||||
|
// Need to default to Embark's compiler
|
||||||
|
cb(null, false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -997,10 +997,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "5.5.1",
|
"version": "5.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
||||||
"integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==",
|
"integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"shebang-command": {
|
"shebang-command": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.6.0",
|
"async": "^2.6.0",
|
||||||
|
"semver": "^5.6.0",
|
||||||
"shelljs": "^0.8.1"
|
"shelljs": "^0.8.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue