Skip to content

Commit

Permalink
fix: remove goimports (#4963)
Browse files Browse the repository at this point in the history
* ci: uninstall goimports
  • Loading branch information
simlecode authored Jun 23, 2022
1 parent 677fb92 commit a8b6579
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/baisc_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ jobs:
sudo apt-get update
sudo apt-get -o Acquire::Retries=3 install make ncftp mesa-opencl-icd ocl-icd-opencl-dev gcc git bzr jq pkg-config curl clang build-essential hwloc libhwloc-dev wget -y && sudo apt upgrade -y
- name: install goimports
run: |
go install golang.org/x/tools/cmd/goimports
- name: Build
env:
GOPROXY: "https://proxy.golang.org,direct"
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ test-venus-shared:

bundle-gen:
cd venus-devtool && go run ./bundle-gen/*.go --dst ./../venus-shared/builtin-actors/builtin_actors_gen.go
goimports -w venus-shared/builtin-actors/builtin_actors_gen.go

api-gen:
cd ./venus-devtool/ && go run ./api-gen/ proxy
Expand All @@ -81,7 +80,6 @@ api-perm:
cd venus-devtool && go run ./compatible/apis/*.go perm > ../venus-shared/compatible-checks/api-perm.txt

compatible-actor: actor-templates actor-sources actor-render
goimports -w -format-only venus-shared/actors/*

actor-templates:
cd venus-devtool && go run ./compatible/actors/*.go templates --dst ../venus-shared/actors/ > ../venus-shared/compatible-checks/actor-templates.txt
Expand Down
13 changes: 10 additions & 3 deletions venus-devtool/bundle-gen/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"text/template"

"github.com/urfave/cli/v2"

"github.com/filecoin-project/venus/venus-devtool/util"
builtinactors "github.com/filecoin-project/venus/venus-shared/builtin-actors"
)

Expand All @@ -24,13 +27,17 @@ func main() {
return err
}

fi, err := os.Create(ctx.String("dst"))
buf := &bytes.Buffer{}
if err := tmpl.Execute(buf, metadata); err != nil {
return err
}

formatted, err := util.FmtFile("", buf.Bytes())
if err != nil {
return err
}
defer fi.Close() //nolint

return tmpl.Execute(fi, metadata)
return ioutil.WriteFile(ctx.String("dst"), formatted, 0744)
},
}

Expand Down
8 changes: 4 additions & 4 deletions venus-devtool/compatible/actors/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package main
import (
"bytes"
"fmt"
"go/format"
"os"
"path/filepath"
"strings"
"text/template"

"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/venus/venus-devtool/util"
)

func importPath(v int) string {
Expand Down Expand Up @@ -72,9 +72,9 @@ func renderSingle(t *template.Template, dir string) error {
return fmt.Errorf("render single template: %w", err)
}

formatted, err := format.Source(buf.Bytes())
formatted, err := util.FmtFile("", buf.Bytes())
if err != nil {
return fmt.Errorf("format go source file: %w", err)
return fmt.Errorf("format go source file : %w", err)
}

err = os.WriteFile(filepath.Join(dir, t.Name()+".go"), formatted, 0644)
Expand All @@ -99,7 +99,7 @@ func renderSeparated(t *template.Template, dir string) error {
return fmt.Errorf("render separated template for ver %d: %w", v, err)
}

formatted, err := format.Source(buf.Bytes())
formatted, err := util.FmtFile("", buf.Bytes())
if err != nil {
return fmt.Errorf("format go source file for ver %d: %w", v, err)
}
Expand Down
2 changes: 1 addition & 1 deletion venus-devtool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/multiformats/go-multiaddr v0.5.0
github.com/urfave/cli/v2 v2.3.0
github.com/whyrusleeping/cbor-gen v0.0.0-20220323183124-98fa8256a799
golang.org/x/tools v0.1.10
)

require (
Expand Down Expand Up @@ -155,7 +156,6 @@ require (
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220418201149-a630d4f3e7a2 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
15 changes: 7 additions & 8 deletions venus-devtool/inline-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"text/template"

"github.com/filecoin-project/venus/venus-devtool/util"
)

const (
Expand Down Expand Up @@ -111,11 +112,13 @@ func main() {

if rewrite {
fmt.Printf("write %s\n", path)
if err := ioutil.WriteFile(path, []byte(strings.Join(outLines, "\n")), 0664); err != nil {
formatted, err := util.FmtFile("", []byte(strings.Join(outLines, "\n")))
if err != nil {
return err
}
if err := ioutil.WriteFile(path, formatted, 0664); err != nil {
return err
}

fmtFile(path)
}

return nil
Expand All @@ -124,7 +127,3 @@ func main() {
panic(err)
}
}

func fmtFile(path string) {
exec.Command("gofmt", "-s", "-l", "-w", path).Run()
}
7 changes: 7 additions & 0 deletions venus-devtool/util/fmt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package util

import "golang.org/x/tools/imports"

func FmtFile(path string, src []byte) ([]byte, error) {
return imports.Process(path, src, nil)
}

0 comments on commit a8b6579

Please sign in to comment.