Skip to content

Commit

Permalink
refac!: remove gno build command
Browse files Browse the repository at this point in the history
Closes: gnolang#1242

In favor of `gno precompile --build`
  • Loading branch information
tbruyelle committed Oct 26, 2023
1 parent ca5ce0f commit 5d27a41
Show file tree
Hide file tree
Showing 22 changed files with 220 additions and 262 deletions.
92 changes: 0 additions & 92 deletions gnovm/cmd/gno/build.go

This file was deleted.

11 changes: 0 additions & 11 deletions gnovm/cmd/gno/build_test.go

This file was deleted.

1 change: 0 additions & 1 deletion gnovm/cmd/gno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func newGnocliCmd(io *commands.IO) *commands.Command {
newTestCmd(io),
newLintCmd(io),
newRunCmd(io),
newBuildCmd(io),
newPrecompileCmd(io),
newCleanCmd(io),
newReplCmd(),
Expand Down
41 changes: 40 additions & 1 deletion gnovm/cmd/gno/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type precompileCfg struct {
verbose bool
skipFmt bool
skipImports bool
gobuild bool
goBinary string
gofmtBinary string
output string
Expand Down Expand Up @@ -85,6 +86,13 @@ func (c *precompileCfg) RegisterFlags(fs *flag.FlagSet) {
"do not precompile imports recursively",
)

fs.BoolVar(
&c.gobuild,
"gobuild",
false,
"run go build on generated go files, ignoring test files",
)

fs.StringVar(
&c.goBinary,
"go-binary",
Expand Down Expand Up @@ -125,7 +133,6 @@ func execPrecompile(cfg *precompileCfg, args []string, io *commands.IO) error {
if err != nil {
err = fmt.Errorf("%s: precompile: %w", filepath, err)
io.ErrPrintfln("%s", err.Error())

errCount++
}
}
Expand All @@ -134,6 +141,27 @@ func execPrecompile(cfg *precompileCfg, args []string, io *commands.IO) error {
return fmt.Errorf("%d precompile errors", errCount)
}

if cfg.gobuild {
paths, err := gnoPackagesFromArgs(args)
if err != nil {
return fmt.Errorf("list packages: %w", err)
}

errCount = 0
for _, pkgPath := range paths {
_ = pkgPath
err = goBuildFileOrPkg(pkgPath, cfg)
if err != nil {
err = fmt.Errorf("%s: build pkg: %w", pkgPath, err)
io.ErrPrintfln("%s\n", err.Error())
errCount++
}
}
if errCount > 0 {
return fmt.Errorf("%d build errors", errCount)
}
}

return nil
}

Expand Down Expand Up @@ -219,3 +247,14 @@ func precompileFile(srcPath string, opts *precompileOptions) error {

return nil
}

func goBuildFileOrPkg(fileOrPkg string, cfg *precompileCfg) error {
verbose := cfg.verbose
goBinary := cfg.goBinary

if verbose {
fmt.Fprintf(os.Stderr, "%s\n", fileOrPkg)
}

return gno.PrecompileBuildPackage(fileOrPkg, goBinary)
}
19 changes: 6 additions & 13 deletions gnovm/cmd/gno/precompile_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package main

import "testing"
import (
"testing"

func TestPrecompileApp(t *testing.T) {
tc := []testMainCase{
{
args: []string{"precompile"},
errShouldBe: "flag: help requested",
},
"github.com/rogpeppe/go-internal/testscript"
)

// {args: []string{"precompile", "..."}, stdoutShouldContain: "..."},
// TODO: recursive
// TODO: valid files
// TODO: invalid files
}
testMainCaseRun(t, tc)
func TestPrecompile(t *testing.T) {
testscript.Run(t, setupTestScript(t, "testdata/gno_precompile"))
}
7 changes: 4 additions & 3 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error {
if verbose {
io.ErrPrintfln("=== PREC %s", pkg.Dir)
}
precompileOpts := newPrecompileOptions(&precompileCfg{
precompileCfg := &precompileCfg{
output: tempdirRoot,
})
}
precompileOpts := newPrecompileOptions(precompileCfg)
err := precompilePkg(importPath(pkg.Dir), precompileOpts)
if err != nil {
io.ErrPrintln(err)
Expand All @@ -231,7 +232,7 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error {
if err != nil {
return errors.New("cannot resolve build dir")
}
err = goBuildFileOrPkg(tempDir, defaultBuildOptions)
err = goBuildFileOrPkg(tempDir, precompileCfg)
if err != nil {
io.ErrPrintln(err)
io.ErrPrintln("FAIL")
Expand Down
6 changes: 0 additions & 6 deletions gnovm/cmd/gno/testdata/gno_build/empty_dir.txtar

This file was deleted.

27 changes: 0 additions & 27 deletions gnovm/cmd/gno/testdata/gno_build/invalid_gno_files.txtar

This file was deleted.

30 changes: 0 additions & 30 deletions gnovm/cmd/gno/testdata/gno_build/invalid_go_files.txtar

This file was deleted.

6 changes: 0 additions & 6 deletions gnovm/cmd/gno/testdata/gno_build/no_args.txtar

This file was deleted.

12 changes: 0 additions & 12 deletions gnovm/cmd/gno/testdata/gno_build/no_gno_files.txtar

This file was deleted.

19 changes: 0 additions & 19 deletions gnovm/cmd/gno/testdata/gno_build/no_go_files.txtar

This file was deleted.

16 changes: 0 additions & 16 deletions gnovm/cmd/gno/testdata/gno_build/no_gomod.txtar

This file was deleted.

23 changes: 0 additions & 23 deletions gnovm/cmd/gno/testdata/gno_build/ok.txtar

This file was deleted.

6 changes: 6 additions & 0 deletions gnovm/cmd/gno/testdata/gno_precompile/01_no_args.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run gno precompile without args

! gno precompile

! stdout .+
stderr 'flag: help requested'
6 changes: 6 additions & 0 deletions gnovm/cmd/gno/testdata/gno_precompile/02_empty_dir.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run gno precompile on an empty dir

gno precompile .

! stdout .+
! stderr .+
Loading

0 comments on commit 5d27a41

Please sign in to comment.