mirror of https://github.com/embarklabs/embark.git
update old solc process to new process wrapper
This commit is contained in:
parent
f2e52d1dbc
commit
c94d8e9f91
|
@ -1,11 +1,13 @@
|
|||
let solc;
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const constants = require('../../constants');
|
||||
const Utils = require('../../utils/utils');
|
||||
|
||||
function findImports(filename) {
|
||||
const ProcessWrapper = require('../../process/processWrapper');
|
||||
|
||||
class SolcProcess extends ProcessWrapper {
|
||||
|
||||
findImports(filename) {
|
||||
if (filename.startsWith('http') || filename.startsWith('git')) {
|
||||
const fileObj = Utils.getExternalContractUrl(filename);
|
||||
filename = fileObj.filePath;
|
||||
|
@ -22,20 +24,35 @@ function findImports(filename) {
|
|||
return {error: 'File not found'};
|
||||
}
|
||||
|
||||
loadCompiler(solcLocation) {
|
||||
this.solc = require(solcLocation);
|
||||
}
|
||||
|
||||
compile(jsonObj, cb) {
|
||||
// TODO: only available in 0.4.11; need to make versions warn about this
|
||||
let output = this.solc.compileStandardWrapper(JSON.stringify(jsonObj), this.findImports);
|
||||
cb(output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let solcProcess;
|
||||
|
||||
process.on('message', function (msg) {
|
||||
if (msg.action === "init") {
|
||||
solcProcess = new SolcProcess(msg.options);
|
||||
return process.send({result: "initiated"});
|
||||
}
|
||||
|
||||
if (msg.action === 'loadCompiler') {
|
||||
solc = require(msg.solcLocation);
|
||||
solcProcess.loadCompiler(msg.requirePath);
|
||||
process.send({result: "loadedCompiler"});
|
||||
}
|
||||
|
||||
if (msg.action === 'compile') {
|
||||
// TODO: only available in 0.4.11; need to make versions warn about this
|
||||
let output = solc.compileStandardWrapper(JSON.stringify(msg.jsonObj), findImports);
|
||||
solcProcess.compile(msg.jsonObj, (output) => {
|
||||
process.send({result: "compilation", output: output});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
process.on('exit', function () {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,58 +1,59 @@
|
|||
let utils = require('../../utils/utils.js');
|
||||
let fs = require('../../core/fs.js');
|
||||
let solcProcess;
|
||||
let compilerLoaded = false;
|
||||
let currentSolcVersion = require('../../../package.json').dependencies.solc;
|
||||
const ProcessLauncher = require('../../process/processLauncher');
|
||||
|
||||
class SolcW {
|
||||
|
||||
constructor(options) {
|
||||
this.logger = options.logger;
|
||||
this.events = options.events;
|
||||
this.compilerLoaded = false;
|
||||
this.solcProcess = null;
|
||||
}
|
||||
|
||||
load_compiler(done) {
|
||||
const self = this;
|
||||
if (compilerLoaded) {
|
||||
if (this.compilerLoaded) {
|
||||
done();
|
||||
}
|
||||
solcProcess = require('child_process').fork(utils.joinPath(__dirname, '/solcP.js'));
|
||||
solcProcess.once('message', function (msg) {
|
||||
if (msg.result !== 'loadedCompiler') {
|
||||
return;
|
||||
}
|
||||
compilerLoaded = true;
|
||||
this.solcProcess = new ProcessLauncher({
|
||||
modulePath: utils.joinPath(__dirname, 'solcP.js'),
|
||||
logger: self.logger,
|
||||
events: self.events
|
||||
});
|
||||
this.solcProcess.send({action: "init", options: {}});
|
||||
|
||||
this.solcProcess.subscribeTo('result', 'loadedCompiler', () => {
|
||||
self.compilerLoaded = true;
|
||||
done();
|
||||
});
|
||||
|
||||
this.events.request("version:get:solc", function(solcVersion) {
|
||||
if (solcVersion === currentSolcVersion) {
|
||||
solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'});
|
||||
self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'});
|
||||
} else {
|
||||
self.events.request("version:getPackageLocation", "solc", solcVersion, function(err, location) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
let requirePath = fs.dappPath(location);
|
||||
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
|
||||
self.solcProcess.send({action: 'loadCompiler', requirePath: requirePath});
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isCompilerLoaded() {
|
||||
return (compilerLoaded === true);
|
||||
return (this.compilerLoaded === true);
|
||||
}
|
||||
|
||||
compile(jsonObj, done) {
|
||||
solcProcess.once('message', function (msg) {
|
||||
if (msg.result !== 'compilation') {
|
||||
return;
|
||||
}
|
||||
this.solcProcess.subscribeTo('result', 'compilation', (msg) => {
|
||||
done(JSON.parse(msg.output));
|
||||
});
|
||||
solcProcess.send({action: 'compile', jsonObj: jsonObj});
|
||||
|
||||
this.solcProcess.send({action: 'compile', jsonObj: jsonObj});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue