From a8b657958420fb2517fb45108f198413c2594988 Mon Sep 17 00:00:00 2001 From: tom <69969590+simlecode@users.noreply.github.com> Date: Thu, 23 Jun 2022 11:09:57 +0800 Subject: [PATCH] fix: remove goimports (#4963) * ci: uninstall goimports --- .github/workflows/baisc_checks.yml | 4 ---- Makefile | 2 -- venus-devtool/bundle-gen/main.go | 13 ++++++++++--- venus-devtool/compatible/actors/render.go | 8 ++++---- venus-devtool/go.mod | 2 +- venus-devtool/inline-gen/main.go | 15 +++++++-------- venus-devtool/util/fmt.go | 7 +++++++ 7 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 venus-devtool/util/fmt.go diff --git a/.github/workflows/baisc_checks.yml b/.github/workflows/baisc_checks.yml index dc2797feec..00d0eb1c5c 100644 --- a/.github/workflows/baisc_checks.yml +++ b/.github/workflows/baisc_checks.yml @@ -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" diff --git a/Makefile b/Makefile index 3e140be99d..936cd1581d 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/venus-devtool/bundle-gen/main.go b/venus-devtool/bundle-gen/main.go index 7209c8bb6f..02d618ee48 100644 --- a/venus-devtool/bundle-gen/main.go +++ b/venus-devtool/bundle-gen/main.go @@ -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" ) @@ -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) }, } diff --git a/venus-devtool/compatible/actors/render.go b/venus-devtool/compatible/actors/render.go index 60976629d8..30b593d683 100644 --- a/venus-devtool/compatible/actors/render.go +++ b/venus-devtool/compatible/actors/render.go @@ -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 { @@ -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) @@ -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) } diff --git a/venus-devtool/go.mod b/venus-devtool/go.mod index 27887fba33..1202e5c63d 100644 --- a/venus-devtool/go.mod +++ b/venus-devtool/go.mod @@ -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 ( @@ -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 diff --git a/venus-devtool/inline-gen/main.go b/venus-devtool/inline-gen/main.go index fef59c45b4..f914e0b302 100644 --- a/venus-devtool/inline-gen/main.go +++ b/venus-devtool/inline-gen/main.go @@ -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 ( @@ -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 @@ -124,7 +127,3 @@ func main() { panic(err) } } - -func fmtFile(path string) { - exec.Command("gofmt", "-s", "-l", "-w", path).Run() -} diff --git a/venus-devtool/util/fmt.go b/venus-devtool/util/fmt.go new file mode 100644 index 0000000000..d47f51db50 --- /dev/null +++ b/venus-devtool/util/fmt.go @@ -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) +}