From 80c80e9beb526db74d14c864395ba173336c9fe8 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Tue, 9 Oct 2018 15:12:33 +0200 Subject: [PATCH] fix(commands/build): don't start blockchain node when `--contracts` is used Prior to this commit `$ embark build --contracts` spinned up a blockchain node which is not necessary as `--contracts` can be seen as a "compile only" option. This commit ensures we don't start any web3 services with `--contracts` is used. --- cmd/cmd_controller.js | 21 ++++++++++++--------- lib/core/engine.js | 13 +++++++++---- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index 5b0c1d657..20d265447 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -205,22 +205,25 @@ class EmbarkController { engine.startService("processManager"); engine.startService("libraryManager"); engine.startService("codeRunner"); - engine.startService("web3"); if (!options.onlyCompile) { + engine.startService("web3"); + engine.startService("deployment", {onlyCompile: options.onlyCompile}); engine.startService("pipeline"); - } - engine.startService("deployment", {onlyCompile: options.onlyCompile}); - if (!options.onlyCompile) { engine.startService("storage"); engine.startService("codeGenerator"); + } else { + engine.startService('compiler'); } callback(); }, - function deploy(callback) { - engine.events.request('deploy:contracts', function (err) { - callback(err); - }); + function buildOrBuildAndDeploy(callback) { + if (options.onlyCompile) { + engine.events.request('contracts:build', {}, err => callback(err)); + } else { + // deploy:contracts will trigger a build as well + engine.events.request('deploy:contracts', err => callback(err)); + } }, function waitForWriteFinish(callback) { if (options.onlyCompile) { @@ -229,7 +232,7 @@ class EmbarkController { } engine.logger.info("Finished deploying".underline); engine.events.on('outputDone', (err) => { - engine.logger.info(__("finished building").underline); + engine.logger.info(__("Finished building").underline); callback(err, true); }); } diff --git a/lib/core/engine.js b/lib/core/engine.js index 393c16018..7e31a3138 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -63,6 +63,7 @@ class Engine { "pipeline": this.pipelineService, "codeRunner": this.codeRunnerService, "codeGenerator": this.codeGeneratorService, + "compiler": this.setupCompilerAndContractsManagerService, "deployment": this.deploymentService, "fileWatcher": this.fileWatchService, "webServer": this.webServerService, @@ -178,17 +179,21 @@ class Engine { this.events.on('asset-changed', addToCargo); } + setupCompilerAndContractsManagerService(options) { + this.registerModule('compiler', {plugins: this.plugins, disableOptimizations: options.disableOptimizations}); + this.registerModule('solidity', {ipc: this.ipc, useDashboard: this.useDashboard}); + this.registerModule('vyper'); + this.registerModule('contracts_manager', {compileOnceOnly: options.compileOnceOnly}); + } + deploymentService(options) { let self = this; - this.registerModule('compiler', {plugins: self.plugins, disableOptimizations: options.disableOptimizations}); - this.registerModule('solidity', {ipc: self.ipc, useDashboard: this.useDashboard}); - this.registerModule('vyper'); + this.setupCompilerAndContractsManagerService(options); this.registerModule('profiler'); this.registerModule('deploytracker', {trackContracts: options.trackContracts}); this.registerModule('specialconfigs'); this.registerModule('console_listener', {ipc: self.ipc}); - this.registerModule('contracts_manager', {compileOnceOnly: options.compileOnceOnly}); this.registerModule('deployment', {plugins: this.plugins, onlyCompile: options.onlyCompile}); this.events.on('file-event', function (fileType) {