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

fix: remove goimports #4963

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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
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)
}