From 9380f1ccc237f456908933a035060f1609eb2425 Mon Sep 17 00:00:00 2001 From: Norman Date: Fri, 10 Jan 2025 05:35:52 +0100 Subject: [PATCH] fix: gnodev, gnogensis Signed-off-by: Norman --- contribs/gnodev/pkg/dev/node.go | 5 ----- contribs/gnodev/pkg/dev/packages.go | 8 ++++---- .../gnogenesis/internal/txs/txs_add_packages.go | 2 +- gnovm/pkg/packages/analyze_packages.go | 16 +++++++++------- gnovm/pkg/packages/load.go | 13 +------------ 5 files changed, 15 insertions(+), 29 deletions(-) diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index 1be0d51a05c..3ebcd657b6d 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -16,7 +16,6 @@ import ( "github.com/gnolang/gno/gno.land/pkg/gnoland" "github.com/gnolang/gno/gno.land/pkg/gnoland/ugnot" "github.com/gnolang/gno/gno.land/pkg/integration" - "github.com/gnolang/gno/gnovm/pkg/gnolang" "github.com/gnolang/gno/gnovm/pkg/packages" "github.com/gnolang/gno/tm2/pkg/amino" tmcfg "github.com/gnolang/gno/tm2/pkg/bft/config" @@ -250,10 +249,6 @@ func (n *Node) updatePackages(paths ...string) error { // Update or add package in the current known list. for _, pkg := range pkgslist { - if pkg.ImportPath != "" && gnolang.IsStdlib(pkg.ImportPath) { - continue - } - n.pkgs[pkg.Dir] = Package{ Package: pkg, Creator: deployer, diff --git a/contribs/gnodev/pkg/dev/packages.go b/contribs/gnodev/pkg/dev/packages.go index c69e12061ff..41ba499458d 100644 --- a/contribs/gnodev/pkg/dev/packages.go +++ b/contribs/gnodev/pkg/dev/packages.go @@ -98,10 +98,6 @@ func NewPackagesMap(cfg *packages.LoadConfig, ppaths []PackagePath) (PackagesMap continue } - if pkg.ImportPath != "" && gnolang.IsStdlib(pkg.ImportPath) { - continue - } - if _, ok := pkgs[pkg.Dir]; ok { continue // skip } @@ -136,6 +132,10 @@ func (pm PackagesMap) Load(fee std.Fee, start time.Time) ([]gnoland.TxWithMetada metatxs := make([]gnoland.TxWithMetadata, 0, len(nonDraft)) for _, modPkg := range nonDraft { + if modPkg.ImportPath == "" || gnolang.IsStdlib(modPkg.ImportPath) { + continue + } + pkg := pm[modPkg.Dir] if pkg.Creator.IsZero() { return nil, fmt.Errorf("no creator set for %q", pkg.Dir) diff --git a/contribs/gnogenesis/internal/txs/txs_add_packages.go b/contribs/gnogenesis/internal/txs/txs_add_packages.go index a79a847408b..daabc726bf0 100644 --- a/contribs/gnogenesis/internal/txs/txs_add_packages.go +++ b/contribs/gnogenesis/internal/txs/txs_add_packages.go @@ -125,7 +125,7 @@ func execTxsAddPackages( parsedTxs := make([]gnoland.TxWithMetadata, 0) for _, path := range args { // Generate transactions from the packages (recursively) - loadCfg := &packages.LoadConfig{IO: io, SelfContained: true} + loadCfg := &packages.LoadConfig{IO: io, Deps: true} txs, err := gnoland.LoadPackagesFromDir(loadCfg, path, creator, genesisDeployFee) if err != nil { return fmt.Errorf("unable to load txs from directory, %w", err) diff --git a/gnovm/pkg/packages/analyze_packages.go b/gnovm/pkg/packages/analyze_packages.go index e30e93865e9..84f7e298a9a 100644 --- a/gnovm/pkg/packages/analyze_packages.go +++ b/gnovm/pkg/packages/analyze_packages.go @@ -73,14 +73,16 @@ func readPkgDir(pkgDir string, importPath string, fset *token.FileSet) *Package ImportPath: importPath, } - stdlibsPath := filepath.Join(gnoenv.RootDir(), "gnovm", "stdlibs") - if strings.HasPrefix(filepath.Clean(pkg.Dir), stdlibsPath) { - libPath, err := filepath.Rel(stdlibsPath, pkg.Dir) - if err != nil { - pkg.Errors = append(pkg.Errors, err) - return pkg + if pkg.ImportPath == "" { + stdlibsPath := filepath.Join(gnoenv.RootDir(), "gnovm", "stdlibs") + if strings.HasPrefix(filepath.Clean(pkg.Dir), stdlibsPath) { + libPath, err := filepath.Rel(stdlibsPath, pkg.Dir) + if err != nil { + pkg.Errors = append(pkg.Errors, err) + return pkg + } + pkg.ImportPath = libPath } - pkg.ImportPath = libPath } files := []string{} diff --git a/gnovm/pkg/packages/load.go b/gnovm/pkg/packages/load.go index 5a8f062089a..b82e58d7ced 100644 --- a/gnovm/pkg/packages/load.go +++ b/gnovm/pkg/packages/load.go @@ -120,18 +120,7 @@ func Load(conf *LoadConfig, patterns ...string) (PkgList, error) { // check if this is a stdlib and queue it if gnolang.IsStdlib(imp) { - dir := filepath.Join(gnoroot, "gnovm", "stdlibs", filepath.FromSlash(imp)) - dirInfo, err := os.Stat(dir) - if err == nil && !dirInfo.IsDir() { - err = fmt.Errorf("%q is not a directory", dir) - } - if err != nil { - pkg.Errors = append(pkg.Errors, err) - delete(queuedByPkgPath, imp) // stop trying to get this lib, we can't - continue - } - - pkg := readPkgDir(dir, imp, fset) + pkg := readPkgDir(filepath.Join(gnoroot, "gnovm", "stdlibs", filepath.FromSlash(imp)), imp, fset) markForVisit(pkg) continue }