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

refactor!: remove gno build command #1297

Merged
merged 5 commits into from
Nov 16, 2023
Merged
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
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 @@
verbose bool
skipFmt bool
skipImports bool
gobuild bool
goBinary string
gofmtBinary string
output string
Expand All @@ -30,6 +31,11 @@
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 @@
"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 @@
if err != nil {
err = fmt.Errorf("%s: precompile: %w", filepath, err)
io.ErrPrintfln("%s", err.Error())

errCount++
}
}
Expand All @@ -134,6 +146,27 @@
return fmt.Errorf("%d precompile errors", errCount)
}

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

Check warning on line 153 in gnovm/cmd/gno/precompile.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/precompile.go#L152-L153

Added lines #L152 - L153 were not covered by tests

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 @@

return nil
}

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

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

Check warning on line 262 in gnovm/cmd/gno/precompile.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/precompile.go#L261-L262

Added lines #L261 - L262 were not covered by tests

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
Loading