Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ $ tronbox compile

To compile all contracts, use the `--compile-all` option.

To compile an specific set of contracts:

```bash
tronbox compile contracts/your_contract.sol contracts/another_contract.sol ...
```

Specify a network using the `--network` option. Network name must exist in the configuration. For details, see [Compile a Project](https://tronbox.io/docs/guides/compile-contracts).

### Migrate
Expand Down
28 changes: 27 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@
"publishConfig": {
"access": "public"
}
}
}
14 changes: 12 additions & 2 deletions src/components/Compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const compile = function (sources, options, callback) {

// Nothing to compile? Bail.
if (!Object.keys(sources).length) {
return callback(null, [], []);
return callback(null, [], [], {});
}

Object.keys(operatingSystemIndependentSources).forEach(function (file_path) {
Expand Down Expand Up @@ -160,6 +160,7 @@ const compile = function (sources, options, callback) {
deployedSourceMap: contract.evm.deployedBytecode.sourceMap,
ast: standardOutput.sources[source_path].ast,
abi: contract.abi,
metadata: contract.metadata,
bytecode: '0x' + contract.evm.bytecode.object,
deployedBytecode: '0x' + contract.evm.deployedBytecode.object,
unlinked_binary: '0x' + contract.evm.bytecode.object, // deprecated
Expand Down Expand Up @@ -236,6 +237,8 @@ function replaceLinkReferences(bytecode, linkReferences, libraryName) {
return bytecode;
}



function orderABI(contract) {
const { abi, contractName, ast } = contract;

Expand Down Expand Up @@ -288,6 +291,13 @@ compile.all = function (options, callback) {
});
};

//Compile an specific set of contracts or a single one
compile.specific = function (options, callback) {

options.paths = options.compileTargets;
compile.with_dependencies(options, callback);

};
// contracts_directory: String. Directory where .sol files can be found.
// build_directory: String. Optional. Directory where .sol.js files can be found. Only required if `all` is false.
// all: Boolean. Compile all sources found. Defaults to true. If false, will compare sources against built files
Expand Down Expand Up @@ -316,7 +326,7 @@ compile.necessary = function (options, callback) {
if (err) return callback(err);

if (updated.length === 0) {
return callback(null, [], {});
return callback(null, [], {}, {});
}

options.paths = updated;
Expand Down
3 changes: 3 additions & 0 deletions src/components/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function Config() {
return resolvePathInWorkingDirectory(value, 'build_directory');
}
},
build_info_directory: function () {
return path.join(self.working_directory, 'build-info');
},
contracts_directory: {
default: function () {
return path.join(self.working_directory, 'contracts');
Expand Down
8 changes: 7 additions & 1 deletion src/components/ContractSchema/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const pkgVersion = '2.0.1';
const pkgVersion = '2.0.2';
const Ajv = require('ajv');

const contractObjectSchema = require('./spec/contract-object.spec.json');
Expand Down Expand Up @@ -62,6 +62,12 @@ const properties = {
return value;
}
},
metadata: {
sources: ['metadata'],
transform(value) {
return typeof value == 'string' ? value : undefined;
}
},
sourceMap: {
sources: ['sourceMap', 'srcmap', 'evm.bytecode.sourceMap']
},
Expand Down
4 changes: 4 additions & 0 deletions src/components/ContractSchema/spec/contract-object.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
}
]
},
"metadata": {
"type": "string",
"description": "Solidity compiler metadata JSON"
},
"sourceMap": {
"allOf": [
{
Expand Down
21 changes: 14 additions & 7 deletions src/components/WorkflowCompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,30 @@ const Contracts = {
? options.networks?.compilers?.solc?.version
: options.compilers?.solc?.version;
options.logger.log(` - solc${options.evm ? '(EVM)' : ''}: ${solcVersion}`);
callback(err, abstractions, paths);
callback(err, abstractions, paths, solcStandardInput);
});
self.write_buildInfo(solcStandardInput, config, inputFileName)
} else {
options.logger.log('> Everything is up to date, there is nothing to compile.');
callback(null, [], paths);
callback(null, [], paths, solcStandardInput);
}
}

function start() {
options.logger.log('Compiling your contracts...');
options.logger.log('===========================');

// Compile specific contracts
if (config.compileTargets && config.compileTargets.length > 0) {
return compile.specific(config, finished);
}

//If ALL option is selected compile all contracts
if (config.all === true || config.compileAll === true) {
compile.all(config, finished);
} else {
compile.necessary(config, finished);
return compile.all(config, finished);
}
//Compile modified contracts if none of the above is true
return compile.necessary(config, finished);
}

getCompilerVersion(options)
Expand All @@ -104,8 +111,8 @@ const Contracts = {
if (!options.quietWrite) {
options.logger.log(
'Writing artifacts to .' +
path.sep +
path.relative(options.working_directory, options.contracts_build_directory)
path.sep +
path.relative(options.working_directory, options.contracts_build_directory)
);
}

Expand Down
21 changes: 19 additions & 2 deletions src/lib/commands/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ const version = require('../version');
const describe = 'Compile contract source files';

const command = {
command: 'compile',
command: 'compile [contracts...]',
describe,
builder: yargs => {
yargs
.usage(
`TronBox v${version.bundle}\n\n${describe}\n
Usage: $0 compile [<files...>] [--all] [--evm] [--quiet] `
)
.positional('contracts', {
describe: 'Specific contract source files to compile',
type: 'string'
})
.version(false)
.positional('files', {
describe: 'Specific contract files to compile',
Expand All @@ -31,6 +35,14 @@ Usage: $0 compile [<files...>] [--all] [--evm] [--quiet] `
}
})
.example('$0 compile', 'Compile all contracts in the project')
.example(
'$0 compile contracts/MyContract.sol',
'Compile a specific contract and its dependencies'
)
.example(
'$0 compile contracts/A.sol contracts/B.sol',
'Compile multiple specific contracts'
)
.example('$0 compile --all', 'Compile all contracts, even if not changed')
.example('$0 compile --evm', 'Compile using EVM configuration')
.example('$0 compile contracts/Foo.sol', 'Compile a specific file')
Expand All @@ -43,13 +55,18 @@ Usage: $0 compile [<files...>] [--all] [--evm] [--quiet] `

if (options.quiet || options.silent) {
options.logger = {
log: function () {}
log: function () { }
};
}

options.files = options._.slice();

const config = Config.detect(options);

if (options.contracts && options.contracts.length > 0) {
config.compileTargets = options.contracts;
}

Contracts.compile(config, done);
}
};
Expand Down
1 change: 1 addition & 0 deletions test/abiv2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
src/js/metacoin-config.js
node_modules
build
build-info
.env

1 change: 1 addition & 0 deletions test/consolelogs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
src/js/metacoin-config.js
node_modules
build
build-info
.env

actual.log
Expand Down
1 change: 1 addition & 0 deletions test/evm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
src/js/metacoin-config.js
node_modules
build
build-info
.env

10 changes: 10 additions & 0 deletions test/runTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
echo 'Test abiv2'
cd abiv2
rm -rf build
rm -rf build-info
../../tronbox.dev test
cd ..

Expand All @@ -22,6 +23,7 @@ cd ..

echo 'Test init'
rm -rf build
rm -rf build-info
mkdir build
cd build
TRONBOX_CREATE_JAVASCRIPT_PROJECT_WITH_DEFAULTS=true ../../tronbox.dev init
Expand All @@ -30,6 +32,7 @@ cd ..

echo 'Test init metacoin'
rm -rf build
rm -rf build-info
mkdir build
cd build
TRONBOX_CREATE_JAVASCRIPT_METACOIN_PROJECT_WITH_DEFAULTS=true ../../tronbox.dev init
Expand All @@ -44,5 +47,12 @@ cd ..
echo 'Test evm'
cd evm
rm -rf build
rm -rf build-info
../../tronbox.dev test --evm
cd ..

echo 'Test compile & solcjson input file generation'
cd solcjsoninput
rm -rf build
rm -rf build-info
../../tronbox.dev test
Loading