mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
common/compiler: support 'optimize-runs' arg for solc
This commit is contained in:
parent
6a2d2869f6
commit
b940dd529a
2 changed files with 11 additions and 1 deletions
|
|
@ -31,6 +31,8 @@ import (
|
|||
|
||||
var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
||||
|
||||
var optimizeRuns int64 = 200
|
||||
|
||||
type Contract struct {
|
||||
Code string `json:"code"`
|
||||
Info ContractInfo `json:"info"`
|
||||
|
|
@ -67,12 +69,20 @@ func (s *Solidity) makeArgs() []string {
|
|||
"--combined-json", "bin,abi,userdoc,devdoc",
|
||||
"--optimize", // code optimizer switched on
|
||||
}
|
||||
if optimizeRuns != 200 {
|
||||
p = append(p, "-optimize-runs",strconv.FormatInt(optimizeRuns, 10))
|
||||
}
|
||||
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
|
||||
p[1] += ",metadata"
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// SetOptimizeRuns set the number of optimize runs for solc
|
||||
func SetOptimizeRuns(_optimizeRuns int64) {
|
||||
optimizeRuns = _optimizeRuns
|
||||
}
|
||||
|
||||
// SolidityVersion runs solc and parses its version output.
|
||||
func SolidityVersion(solc string) (*Solidity, error) {
|
||||
if solc == "" {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func skipWithoutSolc(t *testing.T) {
|
|||
|
||||
func TestCompiler(t *testing.T) {
|
||||
skipWithoutSolc(t)
|
||||
|
||||
SetOptimizeRuns(2000)
|
||||
contracts, err := CompileSolidityString("", testSource)
|
||||
if err != nil {
|
||||
t.Fatalf("error compiling source. result %v: %v", contracts, err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue