diff --git a/packages/compile-ligo/index.js b/packages/compile-ligo/index.js index df9dbc59676..c466df847f6 100644 --- a/packages/compile-ligo/index.js +++ b/packages/compile-ligo/index.js @@ -53,7 +53,7 @@ compile.necessary = (options, callback) => { }); }; -compile.display = (paths, { quiet, working_directory, logger }) => { +compile.display = (paths, { quiet, working_directory, logger }, entryPoint) => { if (quiet !== true) { if (!Array.isArray(paths)) { paths = Object.keys(paths); @@ -65,6 +65,7 @@ compile.display = (paths, { quiet, working_directory, logger }) => { } logger.log(`> Compiling ${contract}`); }); + logger.log(`> Using entry point "${entryPoint}"`); } }; @@ -84,8 +85,8 @@ function checkLigo(callback) { } // Execute ligo for single source file -function execLigo(sourcePath, callback) { - const command = `docker run -v $PWD:$PWD --rm -i ligolang/ligo:next compile-contract ${sourcePath} main`; +function execLigo(sourcePath, entryPoint, callback) { + const command = `docker run -v $PWD:$PWD --rm -i ligolang/ligo:next compile-contract ${sourcePath} ${entryPoint}`; exec(command, { maxBuffer: 600 * 1024 }, (err, stdout, stderr) => { if (err) @@ -104,14 +105,15 @@ function execLigo(sourcePath, callback) { // compile all options.paths function compileAll(options, callback) { + const entryPoint = options._[0] || "main"; options.logger = options.logger || console; - compile.display(options.paths, options); + compile.display(options.paths, options, entryPoint); async.map( options.paths, (sourcePath, c) => { - execLigo(sourcePath, (err, compiledContract) => { + execLigo(sourcePath, entryPoint, (err, compiledContract) => { if (err) return c(err); // remove extension from filename diff --git a/packages/compile-ligo/test/test_compiler.js b/packages/compile-ligo/test/test_compiler.js index 6cd2a210a46..b41e7b093d3 100644 --- a/packages/compile-ligo/test/test_compiler.js +++ b/packages/compile-ligo/test/test_compiler.js @@ -7,13 +7,14 @@ describe("ligo compiler", () => { const defaultSettings = { contracts_directory: path.join(__dirname, "./sources/"), quiet: true, - all: true + all: true, + _: [] }; const config = new Config().merge(defaultSettings); it("compiles ligo contracts", done => { compile.all(config, (err, contracts, paths) => { - assert.equal(err, null, "Compiles without error"); + assert.equal(err, null, "Compiles with an error!"); paths.forEach(path => { assert( @@ -85,4 +86,29 @@ describe("ligo compiler", () => { done(); }); }); + + describe("when passed an entry point", () => { + const configWithValidEntryPoint = new Config() + .merge(defaultSettings) + .merge({ _: ["main"] }); + const configWithBadEntryPoint = new Config() + .merge(defaultSettings) + .merge({ _: ["bad"] }); + + it("compiles successfully when passed a valid entry", done => { + compile.all(configWithValidEntryPoint, (err, contracts) => { + assert.equal(err, null, "Compiled with an error!"); + assert(contracts, "Contracts missing!"); + done(); + }); + }); + + it("errors when passed an invalid entry", done => { + compile.all(configWithBadEntryPoint, (err, contracts) => { + assert(err, "Should not have compiled!"); + assert.equal(contracts, null, "Contracts should be missing!"); + done(); + }); + }); + }); });