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); compiler.compile_contracts(contractFiles, cb);
}); });
this.registerModule('solidity'); this.registerModule('solidity', {useIpc: options.useIpc});
this.registerModule('vyper'); this.registerModule('vyper');
this.registerModule('profiler'); this.registerModule('profiler');
this.registerModule('deploytracker'); this.registerModule('deploytracker');

View File

@ -3,12 +3,13 @@ let SolcW = require('./solcW.js');
class Solidity { class Solidity {
constructor(embark, _options) { constructor(embark, options) {
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
this.contractDirectories = embark.config.contractDirectories; this.contractDirectories = embark.config.contractDirectories;
this.solcAlreadyLoaded = false; this.solcAlreadyLoaded = false;
this.solcW = null; this.solcW = null;
this.useIpc = options.useIpc;
embark.registerCompiler(".sol", this.compile_solidity.bind(this)); embark.registerCompiler(".sol", this.compile_solidity.bind(this));
} }
@ -48,7 +49,7 @@ class Solidity {
if (self.solcAlreadyLoaded) { if (self.solcAlreadyLoaded) {
return callback(); 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.logger.info(__("loading solc compiler") + "..");
self.solcW.load_compiler(function (err) { 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; let currentSolcVersion = require('../../../package.json').dependencies.solc;
const ProcessLauncher = require('../../process/processLauncher'); const ProcessLauncher = require('../../process/processLauncher');
const uuid = require('uuid/v1'); const uuid = require('uuid/v1');
let ipc = require('node-ipc')
let socketPath = "/tmp/embark.sock"
class SolcW { class SolcW {
constructor(options) { constructor(options) {
this.logger = options.logger; this.logger = options.logger;
this.events = options.events; this.events = options.events;
this.useIpc = options.useIpc;
this.compilerLoaded = false; this.compilerLoaded = false;
this.solcProcess = null; this.solcProcess = null;
} }
load_compiler(done) { load_compiler(done) {
const self = this; 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) { if (this.compilerLoaded) {
return done(); return done();
} }
@ -30,6 +49,23 @@ class SolcW {
done(); 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) { this.events.request("version:get:solc", function(solcVersion) {
if (solcVersion === currentSolcVersion) { if (solcVersion === currentSolcVersion) {
self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'}); self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'});
@ -51,6 +87,18 @@ class SolcW {
compile(jsonObj, done) { compile(jsonObj, done) {
const id = uuid(); 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) => { this.solcProcess.once('result', 'compilation-' + id, (msg) => {
done(JSON.parse(msg.output)); done(JSON.parse(msg.output));
}); });

View File

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

View File

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

View File

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