compile

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MERGE_FLAG_NAME   string = "merge"
	EXCLUDE_FLAG_NAME string = "exclude"
	FILTER_FLAG_NAME  string = "filter"
)

Variables

View Source
var Command *cli.Command = &cli.Command{
	Name:      "compile",
	ArgsUsage: "<solc-version>",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:  MERGE_FLAG_NAME,
			Value: false,
			Usage: "write all bind codes to abis/bind.go",
		}, &cli.StringFlag{
			Name:    EXCLUDE_FLAG_NAME,
			Aliases: []string{"e", "exc"},
			Usage:   "Comma separated path to exclude from compile",
		}, &cli.StringFlag{
			Name:    FILTER_FLAG_NAME,
			Aliases: []string{"f"},
			Usage:   "Comma separated types to filter from binding",
		},
	},
	Action: func(ctx *cli.Context) error {
		if err := utils.SetDirPath(); err != nil {
			return nil
		}

		version, err := utils.ToSolcVersion(ctx.Args().First())
		if err != nil {
			return errors.Wrap(err, "utils.ToSolcVersion")
		}
		if err := utils.InstallSolc(version); err != nil {
			return errors.Wrap(err, "utils.InstallSolc")
		}

		// 2. solidity 컴파일 실행
		// 2-1. 컴파일 제외할 디렉토리 확인
		var excludes []string
		if ctx.IsSet(EXCLUDE_FLAG_NAME) {
			excludes = make([]string, 0)
			for _, path := range strings.Split(ctx.String(EXCLUDE_FLAG_NAME), ",") {
				if filepath.IsAbs(path) {
					excludes = append(excludes, path)
				} else if abs, err := filepath.Abs(path); err != nil {
					return errors.Wrap(err, fmt.Sprintf("%s is invalid filepath", path))
				} else {
					excludes = append(excludes, abs)
				}
			}
		}

		files, err := findSolFiles(utils.GetContractDir(), excludes)
		if err != nil {
			return errors.Wrap(err, "findSolFiles")
		}

		contracts, err := compile(version, utils.ReadRemappings(), files)
		if err != nil {
			return errors.Wrap(err, "compile")
		}

		if ctx.IsSet(FILTER_FLAG_NAME) {
			filters := make(map[string]struct{})
			for _, f := range strings.Split(ctx.String(FILTER_FLAG_NAME), ",") {
				filters[f] = struct{}{}
			}
			for name := range contracts {
				if _, ok := filters[name]; !ok {
					delete(contracts, name)
				}
			}
		}

		abisDir := utils.GetABIsDir()
		if _, err := os.Stat(abisDir); errors.Is(err, os.ErrNotExist) {
			if err := os.Mkdir(abisDir, 0755); err != nil {
				return errors.Wrap(err, abisDir)
			}
		}

		if ctx.Bool(MERGE_FLAG_NAME) {
			if err := abigenMerge(contracts); err != nil {
				return errors.Wrap(err, "abigenMerge")
			}
		} else {
			for name, compiled := range contracts {
				if err := abigen(name, compiled); err != nil {
					return errors.Wrap(err, name)
				}
			}
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL