use ipc for compiler

This commit is contained in:
Iuri Matias 2018-06-04 13:12:51 -04:00
parent a866cd9e2b
commit b16c06025b
6 changed files with 56 additions and 12 deletions

View File

@ -182,7 +182,7 @@ class Engine {
compiler.compile_contracts(contractFiles, cb);
});
this.registerModule('solidity');
this.registerModule('solidity', {useIpc: options.useIpc});
this.registerModule('vyper');
this.registerModule('profiler');
this.registerModule('deploytracker');

View File

@ -3,12 +3,13 @@ let SolcW = require('./solcW.js');
class Solidity {
constructor(embark, _options) {
constructor(embark, options) {
this.logger = embark.logger;
this.events = embark.events;
this.contractDirectories = embark.config.contractDirectories;
this.solcAlreadyLoaded = false;
this.solcW = null;
this.useIpc = options.useIpc;
embark.registerCompiler(".sol", this.compile_solidity.bind(this));
}
@ -48,7 +49,7 @@ class Solidity {
if (self.solcAlreadyLoaded) {
return callback();
}
self.solcW = new SolcW({logger: self.logger, events: self.events});
self.solcW = new SolcW({logger: self.logger, events: self.events, useIpc: self.useIpc});
self.logger.info(__("loading solc compiler") + "..");
self.solcW.load_compiler(function (err) {

View File

@ -3,18 +3,37 @@ let fs = require('../../core/fs.js');
let currentSolcVersion = require('../../../package.json').dependencies.solc;
const ProcessLauncher = require('../../process/processLauncher');
const uuid = require('uuid/v1');
let ipc = require('node-ipc')
let socketPath = "/tmp/embark.sock"
class SolcW {
constructor(options) {
this.logger = options.logger;
this.events = options.events;
this.useIpc = options.useIpc;
this.compilerLoaded = false;
this.solcProcess = null;
}
load_compiler(done) {
const self = this;
if (self.useIpc) {
// try to connect, if it can't then continue
self.compilerLoaded = true;
ipc.config.silent = true;
function connecting(socket) {
ipc.of['embark'].on('connect',function() {
done();
});
}
ipc.connectTo('embark', socketPath, connecting);
return;
}
if (this.compilerLoaded) {
return done();
}
@ -30,6 +49,23 @@ class SolcW {
done();
});
ipc.config.silent = true;
function _connecting() {
ipc.server.on(
'message',
function(data, socket) {
self.compile(data.message, (result) => {
ipc.server.emit(socket, 'message', {action: 'compilation', message: result});
});
}
);
}
ipc.serve(socketPath, _connecting)
ipc.server.start()
this.logger.info(`pid ${process.pid} listening on ${socketPath}`);
this.events.request("version:get:solc", function(solcVersion) {
if (solcVersion === currentSolcVersion) {
self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'});
@ -51,6 +87,18 @@ class SolcW {
compile(jsonObj, done) {
const id = uuid();
let a = new Date();
console.dir("doing compile");
if (this.useIpc) {
ipc.of['embark'].once('message', function(msg) {
done(msg.message);
});
ipc.of['embark'].emit('message', {action: 'compile', message: jsonObj});
return;
}
this.solcProcess.once('result', 'compilation-' + id, (msg) => {
done(JSON.parse(msg.output));
});

View File

@ -64,7 +64,8 @@ class Test {
web3: this.web3
});
this.engine.startService("deployment", {
trackContracts: false
trackContracts: false,
useIpc: true
});
this.engine.startService("codeGenerator");
}

View File

@ -54,6 +54,7 @@
"ipfs-api": "17.2.4",
"live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git",
"merge": "^1.2.0",
"node-ipc": "^9.1.1",
"os-locale": "^2.1.0",
"p-iteration": "^1.1.7",
"parse-json": "^4.0.0",

View File

@ -3,7 +3,7 @@
"enabled": true,
"ipfs_bin": "ipfs",
"available_providers": ["ipfs", "swarm"],
"available_providers": ["ipfs"],
"upload": {
"provider": "ipfs",
@ -18,13 +18,6 @@
]
},
"development": {
"enabled": true,
"upload": {
"provider": "swarm",
"host": "localhost",
"port": 8500,
"getUrl": "http://localhost:8500/bzzr:/"
}
},
"livenet": {
"enabled": true,