The title is pretty much my question. Is there a way to compile just one contract in the contracts/ folder? If i have a lot of contracts in the Contracts forlder, but only need one, i stil have to wait for them all to compile when i compile from a fresh checkout.
executing truffle compile MyContract should compile contracts/MyContract.sol only, and not all the contracts in the folder.
Truffle ignores the final argument and compiles everything, which is slow when i have a bunch of different contracts in one project.
As explained, parse the positional arguments as names of contracts to compile, and if not specified, compile everything as usual.
I'm writing a Makefile to allow me to document how to build different parts of a system my team is making, and we want to speed up some workflows, including CI. in CI, for example, when testing one contract with one subsystem, we don't want to wait for everything to compile
This doesn't exist today but it should be pretty straightforward to add to @truffle/core's lib/commands/compile. PRs welcome, or we'll triage this and get to it sooner or later!
Thanks for suggesting!
Thanks for the quick reply!
I'm not too well versed in JS, so i'm not sure i can pull it off myself, but i might give it a shot over the weekend, see if i can find my way around the code. By all means though, don't wait for me "^_^
You might find the CONTRIBUTING.md a helpful doc before trying to dig in to Truffle's code.
@reuvenpo
When I needed to selectively compile a subset of all contracts, I recall to having resorted to the approach of using truffle-config.js to selectively compile contracts. In particular,
Note: In addition to specifying a relative path, you can also use globs/regular expressions to selectively compile contracts.
Thus, for a single contract, the truffle-config.js may look like akin to this:
module.exports = {
contracts_directory: "./contracts/subdirectory/MyContract.sol",
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
}
}
};
With this, whether you do truffle compile, migrate, or even test, only ./contracts/subdirectory/MyContract.sol will be involved, and all other contracts will be ignored, as far as I remember.
Ooh, if that works, you don't even need to put it in the config, you can just pass it as --contracts_directory <path/to/contract>! (Config values work as command line options typically)
But note, if your single contract file depends on other files, it starts to get a bit more complicated.
@icherkashin a technique that requires editing a js file would not be very viable for automation from a Makefile. There's also the issue that you, @gnidan , raised, that doing this will not work for contracts that span more than one file :/
This should be straightforward using compile.with_dependencies; is anybody actually looking at working on this?
Just in case someone's holding back on this because I said i might dog into it myself... I probably won't after all :/
@haltman-at what do you mean by compile.with_dependencies?
In @truffle/compile that is a method that is used to compile a source but also make sure to include all the dependencies for that file :) I'll go ahead and tackle this in the next week or so.
Ok. I will work on it. I have one question should we add extra flag like --compile-files=[list of files] or just assume that anything which is not a flag is a file to be compiled ? Just like it works with test.
One question. compile command is using legacy version from workflow-compile, compile-solidity, compile-vyper. This is where I should implement those changes. What about new/ folder in those packages ? Should I put my changes also there ?
It might be best if @gnidan chimes in for guidance on this one. I'm not entirely sure when we will be fully switched over to the non-legacy code.
There is already PR for this. #2713 So it is best to review it instead answering here.