ApeWorX / py-solc-x

Python wrapper and version management tool for the solc Solidity compiler.

Home Page:https://solcx.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatically determine possible kwargs for `solc_wrapper`

iamdefinitelyahuman opened this issue · comments

Originally posted by @iamdefinitelyahuman in #78 (comment)

solc_wrapper kwargs should be generalized / future-proofed by regexing the solc --help output. This would reduce a lot of overhead around checking exactly which flags were added in which version. A few flags require specific logic but the vast majority are only setting a flag or setting a flag and adding a string after it.. shouldn't be that hard to do.

Here's a quick hacky experiment I did:

>>> help_output = solcx.wrapper.solc_wrapper(help=True)
>>> opts = [i.lstrip() for i in help_output.split('\n') if i.lstrip().startswith('-')]
>>> [next(x for x in i.split(' ') if x.startswith('--')) for i in opts]
['--help', '--version', '--license', '--evm-version', '--pretty-json', '--libraries', '--revert-strings', '--output-dir', '--overwrite', '--combined-json', '--gas', '--standard-json', '--import-ast', '--combined-json', '--assemble', '--machine,', '--yul-optimizations', '--yul', '--machine,', '--yul-optimizations', '--strict-assembly', '--yul-optimizations', '--yul-dialect', '--machine', '--link', '--libraries', '--metadata-hash', '--metadata-literal', '--allow-paths', '--base-path', '--color', '--no-color', '--old-reporter', '--error-recovery', '--ignore-missing', '--optimize', '--optimize-runs', '--optimize-yul', '--no-optimize-yul', '--yul-optimizations', '--ast-json', '--ast-compact-json', '--asm', '--asm-json', '--opcodes', '--bin', '--bin-runtime', '--abi', '--ir', '--ir-optimized', '--ewasm', '--hashes', '--userdoc', '--devdoc', '--metadata', '--storage-layout']

It will require fairly thorough testing and there's no guarantee it won't be broken in a future solc release - but I think this could be done in a way that's just as reliable as what we have today.

Related - new layout for command-line help was merged 2 days ago.

ethereum/solidity#9076