diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2017-01-06 22:39:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 22:39:35 +0800 |
commit | e0fde022909d272e55fb9ea2d4f8cfe9f178dba8 (patch) | |
tree | 92897edefa0616b2d3823ebb34d8ec7f30c945fa /common/compiler/solidity.go | |
parent | 59b8245bbced3c0511623ecaa8b7d4e0434343cd (diff) | |
download | go-tangerine-e0fde022909d272e55fb9ea2d4f8cfe9f178dba8.tar.gz go-tangerine-e0fde022909d272e55fb9ea2d4f8cfe9f178dba8.tar.zst go-tangerine-e0fde022909d272e55fb9ea2d4f8cfe9f178dba8.zip |
common/compiler: remove workaround for solc 0.3.5 stdin bug (#3522)
The crash when compiling stdin was fixed in solc 0.3.6 (released
2016-08-10). While here, simplify the test so it runs with any solc
version.
Fixes #3484. The byte code was different for each run because recent
solc embeds the swarm hash of contract metadata into the code. When
compiling from stdin the name in the metadata is constant.
Diffstat (limited to 'common/compiler/solidity.go')
-rw-r--r-- | common/compiler/solidity.go | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go index b682107d9..b0ca9bd75 100644 --- a/common/compiler/solidity.go +++ b/common/compiler/solidity.go @@ -22,9 +22,7 @@ import ( "encoding/json" "errors" "fmt" - "io" "io/ioutil" - "os" "os/exec" "regexp" "strings" @@ -96,27 +94,16 @@ func CompileSolidityString(solc, source string) (map[string]*Contract, error) { if solc == "" { solc = "solc" } - // Write source to a temporary file. Compiling stdin used to be supported - // but seems to produce an exception with solc 0.3.5. - infile, err := ioutil.TempFile("", "geth-compile-solidity") - if err != nil { - return nil, err - } - defer os.Remove(infile.Name()) - if _, err := io.WriteString(infile, source); err != nil { - return nil, err - } - if err := infile.Close(); err != nil { - return nil, err - } - - return CompileSolidity(solc, infile.Name()) + args := append(solcParams, "--") + cmd := exec.Command(solc, append(args, "-")...) + cmd.Stdin = strings.NewReader(source) + return runsolc(cmd, source) } // CompileSolidity compiles all given Solidity source files. func CompileSolidity(solc string, sourcefiles ...string) (map[string]*Contract, error) { if len(sourcefiles) == 0 { - return nil, errors.New("solc: no source ") + return nil, errors.New("solc: no source files") } source, err := slurpFiles(sourcefiles) if err != nil { @@ -125,10 +112,13 @@ func CompileSolidity(solc string, sourcefiles ...string) (map[string]*Contract, if solc == "" { solc = "solc" } - - var stderr, stdout bytes.Buffer args := append(solcParams, "--") cmd := exec.Command(solc, append(args, sourcefiles...)...) + return runsolc(cmd, source) +} + +func runsolc(cmd *exec.Cmd, source string) (map[string]*Contract, error) { + var stderr, stdout bytes.Buffer cmd.Stderr = &stderr cmd.Stdout = &stdout if err := cmd.Run(); err != nil { |