Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Compile command #914

Merged
merged 25 commits into from
Jun 5, 2019
Merged

Compile command #914

merged 25 commits into from
Jun 5, 2019

Conversation

spalladino
Copy link
Contributor

@spalladino spalladino commented May 29, 2019

Adds a new zos compile command to the CLI, which will use either truffle compile or call solc directly from zOS.

The workflow for compiling now is as follows:

  1. If there is a truffle.js config file, then truffle compile is called as usual, and returns
  2. The compilers list is downloaded (cached in ~/.solc/list.json, expires after 2hs)
  3. If the user chose a specific version, this version is matched against the compilers list, first by release (0.5.8), then by specific build (0.5.10-nightly.2019.5.28)
  4. If no version was set by the user, the most recent release that satisfies all contract pragmas is used
  5. If there are already compiled artifacts, their mtime is more recent than all of the sources, and they were compiled with the same version as the resolved one, then no compilation is needed, and returns
  6. If there is a local solc in path, and its version matches the resolved one, it is used
  7. If not, the corresponding solcjs is downloaded and stored in ~/.solc
  8. The compiler is run, artifacts written, and warnings logged

If zos compile is manually called at any time, its settings are saved in the zos.json file, and any further compilation is run using zos instead of truffle.

Note for reviewers: this PR starts from an original PR by Facu with a custom compiler, and then builds on top of it. It also includes code from resolver-engine, plus a few bits from buidler, as well as a custom solc-wrapper package. I'd suggest reviewing by-commit, since it's a large set of changes.

Fixes #854

Copy link
Contributor

@jbcarpanelli jbcarpanelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding work @spalladino! You literally wrote a bulletproof zos compiler in a couple of days! Loved it.
Please let me know when it's ready for a final review. As you may have noticed, we will have to fix some conflicts between this branch and the one of the zos-config file.

packages/cli/solc/solc Show resolved Hide resolved
packages/cli/src/commands/compile.ts Outdated Show resolved Hide resolved
async compileWithSolc(compilerOptions?: CompilerOptions): Promise<void> {
const inputDir = Contracts.getLocalContractsDir();
const outputDir = Contracts.getLocalBuildDir();
const options = { ... this.getSettings(), ... compilerOptions };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone through the compile command, and if you call it without having a truffle.js/truffle-config.js file, this line will throw: TypeError: Cannot read property 'getSettings' of undefined. changing this to Compiler will do the trick though (and use our solc compiler)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, good catch. I'll wait for your PR and review this with the latest config version.

packages/cli/src/models/compiler/Compiler.ts Outdated Show resolved Hide resolved
export function compilerSettingsMatch(s1: CompilerVersionOptions, s2: CompilerVersionOptions) {
if (!s1 || !s2) return false;

/* tslint:disable:triple-equals */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not longer relevant since we removed tslint 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's by design, I wanted to accept comparing runs set as both strings and numbers.

packages/cli/src/models/initializer/truffle/Truffle.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ylv-io ylv-io left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splendid work @spalladino! I like amount of comments and the structure of the code. I don't know what is your previous knowledge on solc complier and how much of a code is taken from other source but technical depth looks impressive!
🚢 🚀

packages/cli/src/commands/compile.ts Outdated Show resolved Hide resolved
packages/cli/src/models/compiler/Compiler.ts Outdated Show resolved Hide resolved
packages/cli/src/models/compiler/Compiler.ts Outdated Show resolved Hide resolved
packages/cli/src/models/compiler/Compiler.ts Outdated Show resolved Hide resolved
packages/cli/src/models/compiler/Compiler.ts Show resolved Hide resolved
packages/cli/src/models/compiler/Compiler.ts Outdated Show resolved Hide resolved
export function compilerSettingsMatch(s1: CompilerVersionOptions, s2: CompilerVersionOptions) {
if (!s1 || !s2) return false;

/* tslint:disable:triple-equals */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not longer relevant since we removed tslint 😃

packages/cli/src/utils/try.ts Show resolved Hide resolved
@spalladino spalladino marked this pull request as ready for review June 4, 2019 21:40
@spalladino spalladino added the status:ready-to-merge Order mergify to merge label Jun 4, 2019
@ylv-io ylv-io self-requested a review June 4, 2019 21:59
Truffle binary could be installed globally.
IsLocalContract check from getContractNames depends on an absolute path, which makes GreeterImpl to be returned only in the machine where it was compiled.
@mergify mergify bot merged commit 0a88c11 into master Jun 5, 2019
@mergify mergify bot deleted the feature/compiler branch June 5, 2019 16:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:ready-to-merge Order mergify to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a solidity compiler to CLI
3 participants