Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from CruzMolina/compileLigoEntry
Browse files Browse the repository at this point in the history
Compile-ligo: Entry point support
  • Loading branch information
CruzMolina authored Oct 10, 2019
2 parents 096a038 + 6d7e8a7 commit 93bbf79
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
12 changes: 7 additions & 5 deletions packages/compile-ligo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -65,6 +65,7 @@ compile.display = (paths, { quiet, working_directory, logger }) => {
}
logger.log(`> Compiling ${contract}`);
});
logger.log(`> Using entry point "${entryPoint}"`);
}
};

Expand All @@ -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)
Expand All @@ -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
Expand Down
30 changes: 28 additions & 2 deletions packages/compile-ligo/test/test_compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
});
});
});
});

0 comments on commit 93bbf79

Please sign in to comment.