Skip to content

Commit

Permalink
feat(compiler): add a new compiler api that checks for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville committed Jan 18, 2019
1 parent e72d648 commit df872fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/core/plugin.js
Expand Up @@ -94,7 +94,7 @@ Plugin.prototype.loadPlugin = function() {
this.pluginModule = this.pluginModule.default;
return new this.pluginModule(this);
}
(this.pluginModule.call(this, this));
this.pluginModule.call(this, this);
};

Plugin.prototype.loadInternalPlugin = function() {
Expand Down
33 changes: 28 additions & 5 deletions src/lib/modules/compiler/index.ts
@@ -1,3 +1,5 @@
import {Callback} from "../../../typings/callbacks";

const async = require("../../utils/async_extend.js");
import { Embark } from "../../../typings/embark";
import { CompilerPluginObject, Plugins } from "../../../typings/plugins";
Expand Down Expand Up @@ -27,15 +29,33 @@ class Compiler {
};

async.eachObject(this.getAvailableCompilers(),
(extension: string, compiler: any, next: any) => {
(extension: string, compilers: any, next: any) => {
const matchingFiles = contractFiles.filter(this.filesMatchingExtension(extension));
if (matchingFiles.length === 0) {
return next();
}

compiler.call(compiler, matchingFiles, compilerOptions, (err: any, compileResult: any) => {
Object.assign(compiledObject, compileResult);
next(err, compileResult);
async.someLimit(compilers, 1, (compiler: any, someCb: Callback<boolean>) => {
compiler.call(compiler, matchingFiles, compilerOptions, (err: any, compileResult: any) => {
if (err) {
return someCb(err);
}
if (compileResult === false) {
// Compiler not compatible, trying the next one
return someCb(null, false);
}
Object.assign(compiledObject, compileResult);
someCb(null, true);
});
}, (err: Error, result: boolean) => {
if (err) {
return next(err);
}
if (!result) {
// No compiler was compatible
return next(new Error(__("No installed compiler was compatible with your version of %s files", extension)));
}
next();
});
},
(err: any) => {
Expand All @@ -51,7 +71,10 @@ class Compiler {
private getAvailableCompilers() {
const available_compilers: { [index: string]: any } = {};
this.plugins.getPluginsProperty("compilers", "compilers").forEach((compilerObject: CompilerPluginObject) => {
available_compilers[compilerObject.extension] = compilerObject.cb;
if (!available_compilers[compilerObject.extension]) {
available_compilers[compilerObject.extension] = [];
}
available_compilers[compilerObject.extension].unshift(compilerObject.cb);
});
return available_compilers;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/modules/solidity/index.js
Expand Up @@ -77,7 +77,7 @@ class Solidity {
}
self.solcW = new SolcW(self.embark, {logger: self.logger, events: self.events, ipc: self.ipc, useDashboard: self.useDashboard, providerUrl: self.providerUrl});

self.logger.info(__("loading solc compiler") + "..");
self.logger.info(__("loading solc compiler") + "...");
self.solcW.load_compiler(function (err) {
self.solcAlreadyLoaded = true;
callback(err);
Expand Down

0 comments on commit df872fd

Please sign in to comment.