From 05dea5844afdd505bfd92b93ca9b7a0d2930c33b Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 30 Aug 2018 13:27:18 -0400 Subject: [PATCH] Fix the way we pass compiler options instead of assuming via the environment --- lib/core/config.js | 2 +- lib/modules/compiler/index.js | 9 ++++----- lib/modules/contracts_manager/index.js | 6 +++++- lib/modules/solidity/index.js | 4 ++-- lib/modules/vyper/index.js | 2 +- lib/tests/test.js | 3 ++- test/compiler.js | 4 ++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index 0cdfd181..a43d4c5d 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -332,7 +332,7 @@ Config.prototype.loadEmbarkConfigFile = function() { var configObject = { options: { solc: { - "optimize": (this.env != 'test'), + "optimize": true, "optimize-runs": 200 } } diff --git a/lib/modules/compiler/index.js b/lib/modules/compiler/index.js index 017d2055..5758a8d0 100644 --- a/lib/modules/compiler/index.js +++ b/lib/modules/compiler/index.js @@ -7,13 +7,12 @@ class Compiler { this.events = embark.events; this.logger = embark.logger; - this.events.setCommandHandler("compiler:contracts", function(contractFiles, cb) { - self.compile_contracts(contractFiles, cb); + this.events.setCommandHandler("compiler:contracts", function(contractFiles, options, cb) { + self.compile_contracts(contractFiles, options, cb); }); - } - compile_contracts(contractFiles, cb) { + compile_contracts(contractFiles, options, cb) { const self = this; let available_compilers = {}; @@ -42,7 +41,7 @@ class Compiler { if (!matchingFiles || !matchingFiles.length) { return callback(); } - compiler.call(compiler, matchingFiles, function (err, compileResult) { + compiler.call(compiler, matchingFiles, options, function (err, compileResult) { Object.assign(compiledObject, compileResult); callback(err, compileResult); }); diff --git a/lib/modules/contracts_manager/index.js b/lib/modules/contracts_manager/index.js index cde53b81..394f6de0 100644 --- a/lib/modules/contracts_manager/index.js +++ b/lib/modules/contracts_manager/index.js @@ -17,6 +17,7 @@ class ContractsManager { this.deployOnlyOnConfig = false; this.compileError = false; this.compileOnceOnly = options.compileOnceOnly; + this.disableOptimizations = options.disableOptimizations; self.events.setCommandHandler('contracts:list', (cb) => { cb(self.compileError, self.listContracts()); @@ -63,6 +64,9 @@ class ContractsManager { build(done) { let self = this; self.contracts = {}; + + let compilerOptions = {disableOptimizations: this.disableOptimizations}; + async.waterfall([ function loadContractFiles(callback) { self.events.request("config:contractsFiles", (contractsFiles) => { @@ -82,7 +86,7 @@ class ContractsManager { // Only compile once for tests return callback(); } - self.events.request("compiler:contracts", self.contractsFiles, function (err, compiledObject) { + self.events.request("compiler:contracts", self.contractsFiles, compilerOptions, function (err, compiledObject) { self.compiledContracts = compiledObject; callback(err); }); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index aeaa7320..a410bede 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -16,7 +16,7 @@ class Solidity { embark.registerCompiler(".sol", this.compile_solidity.bind(this)); } - compile_solidity(contractFiles, cb) { + compile_solidity(contractFiles, options, cb) { if (!contractFiles.length) { return cb(); } @@ -66,7 +66,7 @@ class Solidity { sources: input, settings: { optimizer: { - enabled: self.options.optimize, + enabled: (!options.disableOptimizations && self.options.optimize), runs: self.options["optimize-runs"] }, outputSelection: { diff --git a/lib/modules/vyper/index.js b/lib/modules/vyper/index.js index f8ca1760..1dd8e4b7 100644 --- a/lib/modules/vyper/index.js +++ b/lib/modules/vyper/index.js @@ -32,7 +32,7 @@ class Vyper { }); } - compile_vyper(contractFiles, cb) { + compile_vyper(contractFiles, _options, cb) { const self = this; if (!contractFiles || !contractFiles.length) { return cb(); diff --git a/lib/tests/test.js b/lib/tests/test.js index 8f239c5a..56c18712 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -109,7 +109,8 @@ class Test { }); this.engine.startService("deployment", { trackContracts: false, - compileOnceOnly: true + compileOnceOnly: true, + disableOptimizations: true }); this.events.request('deploy:setGasLimit', 6000000); } diff --git a/test/compiler.js b/test/compiler.js index 43c37d56..95cb44e0 100644 --- a/test/compiler.js +++ b/test/compiler.js @@ -79,7 +79,7 @@ describe('embark.Compiler', function() { compiler.compile_solidity([ readFile('test/contracts/simple_storage.sol'), readFile('test/contracts/token.sol') - ], function(err, compiledContracts) { + ], {}, function(err, compiledContracts) { assert.deepEqual(compiledContracts, expectedObject); done(); }); @@ -122,7 +122,7 @@ describe('embark.Compiler', function() { compiler.compile_solidity([ readFile('test/contracts/simple_storage.sol'), readFile('test/contracts/token.sol') - ], function(err, compiledContracts) { + ], {}, function(err, compiledContracts) { assert.deepEqual(compiledContracts, expectedObject); done(); });