Skip to content

Commit

Permalink
refactor!: remove gno build command (#1297)
Browse files Browse the repository at this point in the history
Closes: #1242

In favor of `gno precompile -gobuild`. 

As seen in the tests written for `gno build` in this PR #1103, the
command's behavior is kinda unexpected. It actually doesn't care about
the syntax of gno files and only relies on go files found in the path
passed as an argument.

Because of that, I chose to name the flag `-gobuild` instead of `-build`
because I found that represents better what's really happening when this
flag is provided.

As mentioned in the linked issue, `gno build` will be re-implemented in
the future with an other behavior.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
tbruyelle authored Nov 16, 2023
1 parent 24d89a4 commit 0c68394
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 275 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
with:
go-version: ${{ matrix.goversion }}
- run: go install -v ./gnovm/cmd/gno
- run: go run ./gnovm/cmd/gno precompile --verbose ./examples
- run: go run ./gnovm/cmd/gno build --verbose ./examples
- run: go run ./gnovm/cmd/gno precompile --verbose --gobuild ./examples
test:
strategy:
fail-fast: false
Expand Down
92 changes: 0 additions & 92 deletions gnovm/cmd/gno/build.go

This file was deleted.

25 changes: 0 additions & 25 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
46 changes: 45 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 All @@ -30,6 +31,11 @@ type precompileOptions struct {
precompiled map[importPath]struct{}
}

var defaultPrecompileCfg = &precompileCfg{
verbose: false,
goBinary: "go",
}

func newPrecompileOptions(cfg *precompileCfg) *precompileOptions {
return &precompileOptions{cfg, map[importPath]struct{}{}}
}
Expand Down Expand Up @@ -85,6 +91,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 +138,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 +146,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 +252,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)
}
32 changes: 20 additions & 12 deletions gnovm/cmd/gno/precompile_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
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"
"github.com/stretchr/testify/require"

// {args: []string{"precompile", "..."}, stdoutShouldContain: "..."},
// TODO: recursive
// TODO: valid files
// TODO: invalid files
"github.com/gnolang/gno/gnovm/pkg/integration"
)

func Test_ScriptsPrecompile(t *testing.T) {
p := testscript.Params{
Dir: "testdata/gno_precompile",
}

if coverdir, ok := integration.ResolveCoverageDir(); ok {
err := integration.SetupTestscriptsCoverage(&p, coverdir)
require.NoError(t, err)
}
testMainCaseRun(t, tc)

err := integration.SetupGno(&p, t.TempDir())
require.NoError(t, err)

testscript.Run(t, p)
}
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,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, defaultPrecompileCfg)
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.

Loading

0 comments on commit 0c68394

Please sign in to comment.