Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove gno mod download #2673

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions gnovm/cmd/gno/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/gnolang/gno/gnovm/pkg/gnomod"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/errors"
"go.uber.org/multierr"
)

Expand All @@ -29,7 +28,6 @@ func newModCmd(io commands.IO) *commands.Command {
)

cmd.AddSubCommands(
newModDownloadCmd(io),
newModInitCmd(),
newModTidy(io),
newModWhy(io),
Expand All @@ -38,22 +36,6 @@ func newModCmd(io commands.IO) *commands.Command {
return cmd
}

func newModDownloadCmd(io commands.IO) *commands.Command {
cfg := &modDownloadCfg{}

return commands.NewCommand(
commands.Metadata{
Name: "download",
ShortUsage: "download [flags]",
ShortHelp: "download modules to local cache",
},
cfg,
func(_ context.Context, args []string) error {
return execModDownload(cfg, args, io)
},
)
}

func newModInitCmd() *commands.Command {
return commands.NewCommand(
commands.Metadata{
Expand Down Expand Up @@ -122,79 +104,6 @@ For example:
)
}

type modDownloadCfg struct {
remote string
verbose bool
}

func (c *modDownloadCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.remote,
"remote",
"test3.gno.land:26657",
"remote for fetching gno modules",
)

fs.BoolVar(
&c.verbose,
"v",
false,
"verbose output when running",
)
}

func execModDownload(cfg *modDownloadCfg, args []string, io commands.IO) error {
if len(args) > 0 {
return flag.ErrHelp
}

path, err := os.Getwd()
if err != nil {
return err
}
modPath := filepath.Join(path, "gno.mod")
if !isFileExist(modPath) {
return errors.New("gno.mod not found")
}

// read gno.mod
data, err := os.ReadFile(modPath)
if err != nil {
return fmt.Errorf("readfile %q: %w", modPath, err)
}

// parse gno.mod
gnoMod, err := gnomod.Parse(modPath, data)
if err != nil {
return fmt.Errorf("parse: %w", err)
}
// sanitize gno.mod
gnoMod.Sanitize()

// validate gno.mod
if err := gnoMod.Validate(); err != nil {
return fmt.Errorf("validate: %w", err)
}

// fetch dependencies
if err := gnoMod.FetchDeps(gnomod.GetGnoModPath(), cfg.remote, cfg.verbose); err != nil {
return fmt.Errorf("fetch: %w", err)
}

gomod, err := gnomod.GnoToGoMod(*gnoMod)
if err != nil {
return fmt.Errorf("sanitize: %w", err)
}

// write go.mod file
err = gomod.Write(filepath.Join(path, "go.mod"))
if err != nil {
return fmt.Errorf("write go.mod file: %w", err)
}

return nil
}

func execModInit(args []string) error {
if len(args) > 1 {
return flag.ErrHelp
Expand Down
64 changes: 0 additions & 64 deletions gnovm/cmd/gno/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,6 @@ func TestModApp(t *testing.T) {
errShouldBe: "flag: help requested",
},

// test `gno mod download`
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/empty_dir",
simulateExternalRepo: true,
errShouldBe: "gno.mod not found",
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/empty_gnomod",
simulateExternalRepo: true,
errShouldBe: "validate: requires module",
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/invalid_module_name",
simulateExternalRepo: true,
errShouldContain: "usage: module module/path",
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/minimalist_gnomod",
simulateExternalRepo: true,
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/require_remote_module",
simulateExternalRepo: true,
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/require_invalid_module",
simulateExternalRepo: true,
errShouldContain: "fetch: writepackage: querychain",
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/invalid_module_version1",
simulateExternalRepo: true,
errShouldContain: "usage: require module/path v1.2.3",
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/invalid_module_version2",
simulateExternalRepo: true,
errShouldContain: "invalid: must be of the form v1.2.3",
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/replace_with_dir",
simulateExternalRepo: true,
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/replace_with_module",
simulateExternalRepo: true,
},
{
args: []string{"mod", "download"},
testDir: "../../tests/integ/replace_with_invalid_module",
simulateExternalRepo: true,
errShouldContain: "fetch: writepackage: querychain",
},

// test `gno mod init` with no module name
{
args: []string{"mod", "init"},
Expand Down
5 changes: 0 additions & 5 deletions gnovm/cmd/gno/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ func isGnoFile(f fs.DirEntry) bool {
return !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".gno") && !f.IsDir()
}

func isFileExist(path string) bool {
_, err := os.Stat(path)
return err == nil
}

func gnoFilesFromArgsRecursively(args []string) ([]string, error) {
var paths []string

Expand Down
30 changes: 0 additions & 30 deletions gnovm/pkg/gnomod/fetch.go

This file was deleted.

66 changes: 0 additions & 66 deletions gnovm/pkg/gnomod/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ package gnomod
import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"strings"

gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
)
Expand Down Expand Up @@ -146,68 +142,6 @@ func (f *File) Resolve(r *modfile.Require) module.Version {
return r.Mod
}

// FetchDeps fetches and writes gno.mod packages
// in GOPATH/pkg/gnomod/
func (f *File) FetchDeps(path string, remote string, verbose bool) error {
for _, r := range f.Require {
mod := f.Resolve(r)
if r.Mod.Path != mod.Path {
if modfile.IsDirectoryPath(mod.Path) {
continue
}
}
indirect := ""
if r.Indirect {
indirect = "// indirect"
}

_, err := os.Stat(PackageDir(path, mod))
if !os.IsNotExist(err) {
if verbose {
log.Println("cached", mod.Path, indirect)
}
continue
}
if verbose {
log.Println("fetching", mod.Path, indirect)
}
requirements, err := writePackage(remote, path, mod.Path)
if err != nil {
return fmt.Errorf("writepackage: %w", err)
}

modFile := new(File)
modFile.AddModuleStmt(mod.Path)
for _, req := range requirements {
path := req[1 : len(req)-1] // trim leading and trailing `"`
if strings.HasSuffix(path, modFile.Module.Mod.Path) {
continue
}

if !gno.IsStdlib(path) {
modFile.AddNewRequire(path, "v0.0.0-latest", true)
}
}

err = modFile.FetchDeps(path, remote, verbose)
if err != nil {
return err
}
goMod, err := GnoToGoMod(*modFile)
if err != nil {
return err
}
pkgPath := PackageDir(path, mod)
goModFilePath := filepath.Join(pkgPath, "go.mod")
err = goMod.Write(goModFilePath)
if err != nil {
return err
}
}

return nil
}

// writes file to the given absolute file path
func (f *File) Write(fname string) error {
f.Syntax.Cleanup()
Expand Down
Loading
Loading