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
import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
op_service "github.com/ethereum-optimism/optimism/op-service"
)
var DevnetPresetId = 901
......@@ -17,7 +18,7 @@ func DevnetPreset() (*Preset, error) {
return nil, err
}
root, err := findMonorepoRoot(cwd)
root, err := op_service.FindMonorepoRoot(cwd)
if err != nil {
return nil, err
}
......@@ -42,25 +43,3 @@ func DevnetPreset() (*Preset, error) {
ChainConfig: ChainConfig{Preset: DevnetPresetId, L1Contracts: l1Contracts},
}, 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 (
"os"
"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"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
......@@ -134,7 +134,7 @@ func parseConfigBase(logger log.Logger, c *cli.Context) (bindGenGeneratorBase, e
return bindGenGeneratorBase{}, err
}
monoRepoPath, err := config.FindMonorepoRoot(cwd)
monoRepoPath, err := op_service.FindMonorepoRoot(cwd)
if err != nil {
return bindGenGeneratorBase{}, err
}
......
......@@ -16,6 +16,7 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"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"
)
......@@ -49,7 +50,7 @@ func init() {
if err != nil {
panic(err)
}
root, err := FindMonorepoRoot(cwd)
root, err := op_service.FindMonorepoRoot(cwd)
if err != nil {
panic(err)
}
......@@ -158,25 +159,3 @@ func allExist(filenames ...string) error {
}
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 (
"fmt"
"os"
"os/signal"
"path/filepath"
"reflect"
"strings"
"syscall"
......@@ -119,3 +120,25 @@ func CloseAction(fn func(ctx context.Context, shutdown <-chan struct{}) error) e
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