2017-03-29 17:50:05 +00:00
|
|
|
let utils = require('../utils/utils.js');
|
|
|
|
let solcProcess;
|
|
|
|
let compilerLoaded = false;
|
2017-07-05 12:35:51 +00:00
|
|
|
var npm = require('../pipeline/npm.js');
|
|
|
|
let path = require('path');
|
2017-02-25 00:27:27 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
class SolcW {
|
2017-02-25 00:27:27 +00:00
|
|
|
|
2017-07-05 12:35:51 +00:00
|
|
|
constructor(version) {
|
|
|
|
this.solcVersion = version;
|
|
|
|
}
|
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
load_compiler(done) {
|
|
|
|
if (compilerLoaded) {
|
|
|
|
done();
|
2017-02-25 03:49:34 +00:00
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
solcProcess = require('child_process').fork(utils.joinPath(__dirname, '/solcP.js'));
|
|
|
|
solcProcess.once('message', function (msg) {
|
|
|
|
if (msg.result !== 'loadedCompiler') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
compilerLoaded = true;
|
|
|
|
done();
|
|
|
|
});
|
2017-07-05 12:35:51 +00:00
|
|
|
npm.getPackageVersion('solc', '0.4.10', false, function(location) {
|
|
|
|
console.log("new compiler installed at " + location);
|
|
|
|
//let requirePath = path.join(process.env.PWD, location.substr(2));
|
|
|
|
let requirePath = path.join(process.env.PWD, location);
|
|
|
|
console.log(requirePath);
|
|
|
|
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
|
|
|
|
});
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2017-02-25 03:49:34 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
isCompilerLoaded() {
|
|
|
|
return (compilerLoaded === true);
|
|
|
|
}
|
2017-02-25 20:47:35 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
compile(obj, optimize, done) {
|
|
|
|
solcProcess.once('message', function (msg) {
|
|
|
|
if (msg.result !== 'compilation') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
done(msg.output);
|
|
|
|
});
|
|
|
|
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
|
|
|
|
}
|
|
|
|
}
|
2017-02-25 00:27:27 +00:00
|
|
|
|
|
|
|
module.exports = SolcW;
|
|
|
|
|