Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ Note: this commandline interface is not compatible with `solc` provided by the S
used in combination with an Ethereum client via the `eth.compile.solidity()` RPC method. Please refer to the
[Solidity compiler documentation](https://solidity.readthedocs.io/) for instructions to install `solc`.

Typical scenario:
```bash
solcjs-get
solcjs -o output --bin --abi contract.sol
```

or for a specific compiler:
```bash
solcjs-get --list
solcjs-get soljson-v0.3.5+commit.5f97274.js
solcjs -o output --comp soljson-v0.3.5+commit.5f97274.js --bin --abi contract.sol
```

### Usage in Projects

#### From early versions
Expand Down
70 changes: 0 additions & 70 deletions downloadCurrentVersion.js

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"description": "Solidity compiler",
"main": "index.js",
"bin": {
"solcjs": "solcjs"
"solcjs": "solcjs",
"solcjs-get": "solcjs-get"
},
"scripts": {
"lint": "semistandard",
"prepublish": "node downloadCurrentVersion.js && node verifyVersion.js",
"prepublish": "./solcjs-get",
"pretest": "npm run lint",
"test": "tape ./test/index.js",
"clean": "rm -rf *.abi *.bin output",
"coverage": "istanbul cover node_modules/tape/bin/tape ./test/index.js",
"coveralls": "npm run coverage && coveralls <coverage/lcov.info"
},
Expand All @@ -28,6 +30,7 @@
"index.js",
"linker.js",
"solcjs",
"solcjs-get",
"soljson.js",
"translate.js",
"wrapper.js"
Expand Down
61 changes: 56 additions & 5 deletions solcjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var originalUncaughtExceptionListeners = process.listeners("uncaughtException");

var fs = require('fs-extra');
var path = require('path');
var solc = require('./index.js');

// FIXME: remove annoying exception catcher of Emscripten
// see https://github.com/chriseth/browser-solidity/issues/167
process.removeAllListeners('uncaughtException');
Expand Down Expand Up @@ -34,16 +34,44 @@ var yargs = require('yargs')
})
.option('output-dir', {
alias: 'o',
describe: 'Output directory for the contracts.',
describe: 'Output directory for the contracts. Defaults to ./',
type: 'string'
})
.option('compiler', {
alias: 'comp',
describe: 'Select a specific solidity compiler. Compilers´ location is ~/.soljs/',
type: 'string'
})
.version(solc.version())
.global([ 'version', 'optimize' ])
.showHelpOnFail(false, 'Specify --help for available options')
.help()

var argv = yargs.argv;
var files = argv._;
var destination = argv['output-dir'] || '.'
var destination = argv['output-dir'] || '.';
var compiler = argv.compiler;

// here we get the default version of the compiler
solc = require('./index.js');

function getVersion(path){
return path.replace('soljson-', '').replace('.js','');
}

// if the user needs a specific one, we load it
if (compiler ){
console.log("Custom compiler requested: " + compiler);
var expectedPath = './'+path.join('bin', compiler);

//solc = solc.setupMethods(require(expectedPath));
solc = solc.useVersion(getVersion(compiler));
console.log("compiler version:" + solc.version());
}

if (argv.version){
console.log( solc.version());
process.exit(0);
}

function abort (msg) {
console.error(msg || 'Error occured');
Expand All @@ -66,10 +94,13 @@ if (argv['standard-json']) {
console.log(solc.compileStandard(input));
process.exit(0);
} else if (files.length === 0) {
console.error('Must provide a file');
console.error('You must provide at least one file to compile.');
process.exit(1);
}

if (!files.length)
abort('You must provide at least one file to compile.');

if (!(argv.bin || argv.abi)) {
abort('Invalid option selected, must specify either --bin or --abi');
}
Expand All @@ -84,6 +115,9 @@ for (var i = 0; i < files.length; i++) {
}
}

// TODO: to bring back once https://github.com/ethereum/solc-js/issues/22 is clarified
console.log("Compiling with version: " + solc.version());

var output = solc.compile({ sources: sources }, argv.optimize ? 1 : 0);
if (!output) {
abort('No output from compiler');
Expand Down Expand Up @@ -113,6 +147,23 @@ function writeFile (file, content) {
});
}

if (output.errors) {
// TODO: Remove once the following is clarified:
// https://github.com/ethereum/solc-js/issues/53
// only leave the console.error

if (output.errors[0].indexOf('Warning') > 0) {
console.log('Compiled with Warnings: ', output.errors);
} else {
console.error('Compiled with Errors: ', output.errors);
}
} else if (output.warnings) {
console.warn('Compiled with Warnings: ', output.warnings);
} else {
console.log('Compiled with sucess.');
}

fs.ensureDirSync (destination);
for (var contractName in output.contracts) {
var contractFileName = contractName.replace(/[:./]/g, '_');

Expand Down
136 changes: 136 additions & 0 deletions solcjs-get
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env node

// This is used to download the correct binary version
// as part of the prepublish step.

var pkg = require('./package.json');
var fs = require('fs-extra');
var https = require('https');
var MemoryStream = require('memorystream');
var path = require('path');
var compilerDir = 'bin';

var yargs = require('yargs')
.usage('Usage: [options| version]')
.option('list', {
describe: 'List all the versions',
type: 'bool'
})
.option('all', {
describe: 'Download all the versions. Additionnaly, use --nightly to get the nightly builds.',
type: 'bool'
})
.option('nightly', {
describe: 'Combined with --all, it adds the nightly to the list',
type: 'bool'
})
.option('releases', {
describe: 'Get all the release builds',
type: 'bool'
})
.option('clean', {
describe: 'Delete all the compiler in ./bin',
type: 'bool'
})
.showHelpOnFail(false, 'Specify --help for available options')
.help();

var argv = yargs.argv;
var requestedVersion = argv._[0];

function getVersionList (cb) {
console.log('Retrieving available version list...');

var mem = new MemoryStream(null, { readable: false });
https.get('https://ethereum.github.io/solc-bin/bin/list.json', function (response) {
if (response.statusCode !== 200) {
console.log('Error downloading file: ' + response.statusCode);
process.exit(1);
}
response.pipe(mem);
response.on('end', function () {
cb(mem.toString());
});
});
}

function downloadBinary (version, cb) {
console.log('Downloading version', version);
var targetPath = path.join(compilerDir, version);

https.get('https://ethereum.github.io/solc-bin/bin/' + version, function (response) {
if (response.statusCode !== 200) {
console.log('Error downloading file: ' + response.statusCode);
process.exit(1);
}

fs.ensureDirSync(compilerDir);

var file = fs.createWriteStream(targetPath);

response.pipe(file);
file.on('finish', function () {
file.close(function () {
console.log('Done.');
if (cb) cb(targetPath);
});
});
});
}

if (argv.list) {
console.log('Getting the list of all versions ...');
getVersionList(function (list) {
list = JSON.parse(list).builds;
for (var i = list.length - 1; i >= 0; i--) {
console.log(list[i].version, list[i].path);
}
process.exit(0);
});
} else if (argv.clean) {
console.log('Removing all local compilers in ' + compilerDir + ' ...');
fs.remove(compilerDir, function (err) {
if (err) return console.error(err);

console.log('Success! Cleaned ' + compilerDir);
process.exit(0);
});
} else if (argv.all) {
console.log('Getting all the versions ...');
getVersionList(function (list) {
list = JSON.parse(list).builds;
for (var i = list.length - 1; i >= 0; i--) {
var target = list[i].path;
if (target.indexOf('nightly') > 0 && !argv.nightly) continue;

downloadBinary(target);
}
});
} else if (argv.releases) {
console.log('Getting all the releases ...');
getVersionList(function (list) {
list = JSON.parse(list).releases;
for (var key in list) {
downloadBinary(list[key]);
}
});
} else {
getVersionList(function (list) {
list = JSON.parse(list);

var wanted = null;
if (requestedVersion) {
console.log('Requested version: ' + requestedVersion);
wanted = requestedVersion;
} else {
console.log('Requested version: latest release');
wanted = list.releases[pkg.version.match(/^(\d+\.\d+\.\d+)$/)[1]];
}

downloadBinary(wanted, function (file) {
if (!requestedVersion){
fs.copy(file, 'soljson.js'); // for backward compatibility
}
});
});
}
4 changes: 4 additions & 0 deletions test/Simple/simple.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract SimpleContract{
address addr;

}
18 changes: 18 additions & 0 deletions test/cli-solcjs-get
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const tape = require('tape');
const spawn = require('tape-spawn');

tape('CLI solcjs-get', function (t) {
t.test('--list', function (st) {
var spt = spawn(st, './solcjs-get --list');
spt.stderr.empty();
spt.succeeds();
spt.end();
});

t.test('Get latest', function (st) {
var spt = spawn(st, './solcjs-get');
spt.stderr.empty();
spt.succeeds();
spt.end();
});
});
Loading