Commit 5e60f1dc authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

bindgen: fix build (#8733)

The bindgen command was causing a panic without this change. We should
not be coupling bindgen to op-e2e. There is no reason to trigger the
init function inside of op-e2e when running bindgen. This commit
dedupes the `FindMonoRepoRoot` function by putting it into a common
location where it can be consumed. Not bindgen no longer depends on
op-e2e. The op-e2e package is for tests, not defining library functions
that are used elsewhere in the repo.
parent f2229b8b
...@@ -3,10 +3,11 @@ package config ...@@ -3,10 +3,11 @@ package config
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io/fs" "io/fs"
"os" "os"
"path/filepath" "path/filepath"
op_service "github.com/ethereum-optimism/optimism/op-service"
) )
var DevnetPresetId = 901 var DevnetPresetId = 901
...@@ -17,7 +18,7 @@ func DevnetPreset() (*Preset, error) { ...@@ -17,7 +18,7 @@ func DevnetPreset() (*Preset, error) {
return nil, err return nil, err
} }
root, err := findMonorepoRoot(cwd) root, err := op_service.FindMonorepoRoot(cwd)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -42,25 +43,3 @@ func DevnetPreset() (*Preset, error) { ...@@ -42,25 +43,3 @@ func DevnetPreset() (*Preset, error) {
ChainConfig: ChainConfig{Preset: DevnetPresetId, L1Contracts: l1Contracts}, ChainConfig: ChainConfig{Preset: DevnetPresetId, L1Contracts: l1Contracts},
}, nil }, nil
} }
// findMonorepoRoot will recursively search upwards for a go.mod file.
// This depends on the structure of the monorepo having a go.mod file at the root.
func findMonorepoRoot(startDir string) (string, error) {
dir, err := filepath.Abs(startDir)
if err != nil {
return "", err
}
for {
modulePath := filepath.Join(dir, "go.mod")
if _, err := os.Stat(modulePath); err == nil {
return dir, nil
}
parentDir := filepath.Dir(dir)
// Check if we reached the filesystem root
if parentDir == dir {
break
}
dir = parentDir
}
return "", fmt.Errorf("monorepo root not found")
}
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/ethereum-optimism/optimism/op-bindings/etherscan" "github.com/ethereum-optimism/optimism/op-bindings/etherscan"
"github.com/ethereum-optimism/optimism/op-e2e/config" op_service "github.com/ethereum-optimism/optimism/op-service"
oplog "github.com/ethereum-optimism/optimism/op-service/log" oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -134,7 +134,7 @@ func parseConfigBase(logger log.Logger, c *cli.Context) (bindGenGeneratorBase, e ...@@ -134,7 +134,7 @@ func parseConfigBase(logger log.Logger, c *cli.Context) (bindGenGeneratorBase, e
return bindGenGeneratorBase{}, err return bindGenGeneratorBase{}, err
} }
monoRepoPath, err := config.FindMonorepoRoot(cwd) monoRepoPath, err := op_service.FindMonorepoRoot(cwd)
if err != nil { if err != nil {
return bindGenGeneratorBase{}, err return bindGenGeneratorBase{}, err
} }
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis" "github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-e2e/external" "github.com/ethereum-optimism/optimism/op-e2e/external"
op_service "github.com/ethereum-optimism/optimism/op-service"
oplog "github.com/ethereum-optimism/optimism/op-service/log" oplog "github.com/ethereum-optimism/optimism/op-service/log"
) )
...@@ -49,7 +50,7 @@ func init() { ...@@ -49,7 +50,7 @@ func init() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
root, err := FindMonorepoRoot(cwd) root, err := op_service.FindMonorepoRoot(cwd)
if err != nil { if err != nil {
panic(err) panic(err)
} }
...@@ -158,25 +159,3 @@ func allExist(filenames ...string) error { ...@@ -158,25 +159,3 @@ func allExist(filenames ...string) error {
} }
return nil return nil
} }
// FindMonorepoRoot will recursively search upwards for a go.mod file.
// This depends on the structure of the monorepo having a go.mod file at the root.
func FindMonorepoRoot(startDir string) (string, error) {
dir, err := filepath.Abs(startDir)
if err != nil {
return "", err
}
for {
modulePath := filepath.Join(dir, "go.mod")
if _, err := os.Stat(modulePath); err == nil {
return dir, nil
}
parentDir := filepath.Dir(dir)
// Check if we reached the filesystem root
if parentDir == dir {
break
}
dir = parentDir
}
return "", fmt.Errorf("monorepo root not found")
}
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
"path/filepath"
"reflect" "reflect"
"strings" "strings"
"syscall" "syscall"
...@@ -119,3 +120,25 @@ func CloseAction(fn func(ctx context.Context, shutdown <-chan struct{}) error) e ...@@ -119,3 +120,25 @@ func CloseAction(fn func(ctx context.Context, shutdown <-chan struct{}) error) e
return err return err
} }
} }
// FindMonorepoRoot will recursively search upwards for a go.mod file.
// This depends on the structure of the monorepo having a go.mod file at the root.
func FindMonorepoRoot(startDir string) (string, error) {
dir, err := filepath.Abs(startDir)
if err != nil {
return "", err
}
for {
modulePath := filepath.Join(dir, "go.mod")
if _, err := os.Stat(modulePath); err == nil {
return dir, nil
}
parentDir := filepath.Dir(dir)
// Check if we reached the filesystem root
if parentDir == dir {
break
}
dir = parentDir
}
return "", fmt.Errorf("monorepo root not found")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment