mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
common/compiler: vyper compiler binding support
This commit is contained in:
parent
c10e4dd772
commit
49ff08be6d
2 changed files with 5 additions and 43 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package compiler wraps the Solidity compiler executable (solc).
|
// Package compiler wraps the Solidity and Vyper compiler executables (solc; vyper).
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -22,40 +22,13 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
var solVersionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
||||||
|
|
||||||
// Contract contains information about a compiled contract, alongside its code and runtime code.
|
|
||||||
type Contract struct {
|
|
||||||
Code string `json:"code"`
|
|
||||||
RuntimeCode string `json:"runtime-code"`
|
|
||||||
Info ContractInfo `json:"info"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContractInfo contains information about a compiled contract, including access
|
|
||||||
// to the ABI definition, source mapping, user and developer docs, and metadata.
|
|
||||||
//
|
|
||||||
// Depending on the source, language version, compiler version, and compiler
|
|
||||||
// options will provide information about how the contract was compiled.
|
|
||||||
type ContractInfo struct {
|
|
||||||
Source string `json:"source"`
|
|
||||||
Language string `json:"language"`
|
|
||||||
LanguageVersion string `json:"languageVersion"`
|
|
||||||
CompilerVersion string `json:"compilerVersion"`
|
|
||||||
CompilerOptions string `json:"compilerOptions"`
|
|
||||||
SrcMap string `json:"srcMap"`
|
|
||||||
SrcMapRuntime string `json:"srcMapRuntime"`
|
|
||||||
AbiDefinition interface{} `json:"abiDefinition"`
|
|
||||||
UserDoc interface{} `json:"userDoc"`
|
|
||||||
DeveloperDoc interface{} `json:"developerDoc"`
|
|
||||||
Metadata string `json:"metadata"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Solidity contains information about the solidity compiler.
|
// Solidity contains information about the solidity compiler.
|
||||||
type Solidity struct {
|
type Solidity struct {
|
||||||
|
|
@ -96,7 +69,7 @@ func SolidityVersion(solc string) (*Solidity, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
matches := versionRegexp.FindStringSubmatch(out.String())
|
matches := solVersionRegexp.FindStringSubmatch(out.String())
|
||||||
if len(matches) != 4 {
|
if len(matches) != 4 {
|
||||||
return nil, fmt.Errorf("can't parse solc version %q", out.String())
|
return nil, fmt.Errorf("can't parse solc version %q", out.String())
|
||||||
}
|
}
|
||||||
|
|
@ -209,14 +182,3 @@ func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion strin
|
||||||
return contracts, nil
|
return contracts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func slurpFiles(files []string) (string, error) {
|
|
||||||
var concat bytes.Buffer
|
|
||||||
for _, file := range files {
|
|
||||||
content, err := ioutil.ReadFile(file)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
concat.Write(content)
|
|
||||||
}
|
|
||||||
return concat.String(), nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func skipWithoutSolc(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompiler(t *testing.T) {
|
func TestSolidityCompiler(t *testing.T) {
|
||||||
skipWithoutSolc(t)
|
skipWithoutSolc(t)
|
||||||
|
|
||||||
contracts, err := CompileSolidityString("", testSource)
|
contracts, err := CompileSolidityString("", testSource)
|
||||||
|
|
@ -67,7 +67,7 @@ func TestCompiler(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompileError(t *testing.T) {
|
func TestSolidityCompileError(t *testing.T) {
|
||||||
skipWithoutSolc(t)
|
skipWithoutSolc(t)
|
||||||
|
|
||||||
contracts, err := CompileSolidityString("", testSource[4:])
|
contracts, err := CompileSolidityString("", testSource[4:])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue