Skip to content
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
33 changes: 2 additions & 31 deletions .github/workflows/easyjson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: easyjson

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
test:
Expand Down Expand Up @@ -32,32 +32,3 @@ jobs:

- name: Build and Run tests
run: make

test-non-amd64:
runs-on: ubuntu-latest
name: Test on ${{ matrix.distro }} ${{ matrix.arch }}
strategy:
matrix:
include:
- arch: ppc64le
distro: ubuntu20.04
steps:
- uses: actions/checkout@v2
- uses: uraimo/run-on-arch-action@master
with:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
install: |
apt-get update
apt install -y curl wget make gcc
latestGo=$(curl "https://golang.org/VERSION?m=text")
wget --quiet "https://dl.google.com/go/${latestGo}.linux-${{ matrix.arch }}.tar.gz"
rm -f $(which go)
rm -rf /usr/local/go
tar -C /usr/local -xzf "${latestGo}.linux-${{ matrix.arch }}.tar.gz"
run: |
export PATH=/usr/local/go/bin:$PATH
export PATH=~/go/bin:$PATH
printf "Go Version: $(go version)\n"
go install golang.org/x/lint/golint@latest
make
114 changes: 57 additions & 57 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,37 @@ func (g *Generator) writeStub() error {
if err != nil {
return err
}
defer f.Close()
defer func() { _ = f.Close() }()

if g.BuildTags != "" {
fmt.Fprintln(f, "// +build ", g.BuildTags)
fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "// +build ", g.BuildTags)
_, _ = fmt.Fprintln(f)
}
fmt.Fprintln(f, "// TEMPORARY AUTOGENERATED FILE: easyjson stub code to make the package")
fmt.Fprintln(f, "// compilable during generation.")
fmt.Fprintln(f)
fmt.Fprintln(f, "package ", g.PkgName)
_, _ = fmt.Fprintln(f, "// TEMPORARY AUTOGENERATED FILE: easyjson stub code to make the package")
_, _ = fmt.Fprintln(f, "// compilable during generation.")
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "package ", g.PkgName)

if len(g.Types) > 0 {
fmt.Fprintln(f)
fmt.Fprintln(f, "import (")
fmt.Fprintln(f, ` "`+pkgWriter+`"`)
fmt.Fprintln(f, ` "`+pkgLexer+`"`)
fmt.Fprintln(f, ")")
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "import (")
_, _ = fmt.Fprintln(f, ` "`+pkgWriter+`"`)
_, _ = fmt.Fprintln(f, ` "`+pkgLexer+`"`)
_, _ = fmt.Fprintln(f, ")")
}

sort.Strings(g.Types)
for _, t := range g.Types {
fmt.Fprintln(f)
_, _ = fmt.Fprintln(f)
if !g.NoStdMarshalers {
fmt.Fprintln(f, "func (", t, ") MarshalJSON() ([]byte, error) { return nil, nil }")
fmt.Fprintln(f, "func (*", t, ") UnmarshalJSON([]byte) error { return nil }")
_, _ = fmt.Fprintln(f, "func (", t, ") MarshalJSON() ([]byte, error) { return nil, nil }")
_, _ = fmt.Fprintln(f, "func (*", t, ") UnmarshalJSON([]byte) error { return nil }")
}

fmt.Fprintln(f, "func (", t, ") MarshalEasyJSON(w *jwriter.Writer) {}")
fmt.Fprintln(f, "func (*", t, ") UnmarshalEasyJSON(l *jlexer.Lexer) {}")
fmt.Fprintln(f)
fmt.Fprintln(f, "type EasyJSON_exporter_"+t+" *"+t)
_, _ = fmt.Fprintln(f, "func (", t, ") MarshalEasyJSON(w *jwriter.Writer) {}")
_, _ = fmt.Fprintln(f, "func (*", t, ") UnmarshalEasyJSON(l *jlexer.Lexer) {}")
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "type EasyJSON_exporter_"+t+" *"+t)
}
return nil
}
Expand All @@ -92,62 +92,62 @@ func (g *Generator) writeMain() (path string, err error) {
return "", err
}

fmt.Fprintln(f, "// +build ignore")
fmt.Fprintln(f)
fmt.Fprintln(f, "// TEMPORARY AUTOGENERATED FILE: easyjson bootstapping code to launch")
fmt.Fprintln(f, "// the actual generator.")
fmt.Fprintln(f)
fmt.Fprintln(f, "package main")
fmt.Fprintln(f)
fmt.Fprintln(f, "import (")
fmt.Fprintln(f, ` "fmt"`)
fmt.Fprintln(f, ` "os"`)
fmt.Fprintln(f)
fmt.Fprintf(f, " %q\n", genPackage)
_, _ = fmt.Fprintln(f, "// +build ignore")
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "// TEMPORARY AUTOGENERATED FILE: easyjson bootstapping code to launch")
_, _ = fmt.Fprintln(f, "// the actual generator.")
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "package main")
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "import (")
_, _ = fmt.Fprintln(f, ` "fmt"`)
_, _ = fmt.Fprintln(f, ` "os"`)
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintf(f, " %q\n", genPackage)
if len(g.Types) > 0 {
fmt.Fprintln(f)
fmt.Fprintf(f, " pkg %q\n", g.PkgPath)
}
fmt.Fprintln(f, ")")
fmt.Fprintln(f)
fmt.Fprintln(f, "func main() {")
fmt.Fprintf(f, " g := gen.NewGenerator(%q)\n", filepath.Base(g.OutName))
fmt.Fprintf(f, " g.SetPkg(%q, %q)\n", g.PkgName, g.PkgPath)
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintf(f, " pkg %q\n", g.PkgPath)
}
_, _ = fmt.Fprintln(f, ")")
_, _ = fmt.Fprintln(f)
_, _ = fmt.Fprintln(f, "func main() {")
_, _ = fmt.Fprintf(f, " g := gen.NewGenerator(%q)\n", filepath.Base(g.OutName))
_, _ = fmt.Fprintf(f, " g.SetPkg(%q, %q)\n", g.PkgName, g.PkgPath)
if g.BuildTags != "" {
fmt.Fprintf(f, " g.SetBuildTags(%q)\n", g.BuildTags)
_, _ = fmt.Fprintf(f, " g.SetBuildTags(%q)\n", g.BuildTags)
}
if g.SnakeCase {
fmt.Fprintln(f, " g.UseSnakeCase()")
_, _ = fmt.Fprintln(f, " g.UseSnakeCase()")
}
if g.LowerCamelCase {
fmt.Fprintln(f, " g.UseLowerCamelCase()")
_, _ = fmt.Fprintln(f, " g.UseLowerCamelCase()")
}
if g.OmitEmpty {
fmt.Fprintln(f, " g.OmitEmpty()")
_, _ = fmt.Fprintln(f, " g.OmitEmpty()")
}
if g.NoStdMarshalers {
fmt.Fprintln(f, " g.NoStdMarshalers()")
_, _ = fmt.Fprintln(f, " g.NoStdMarshalers()")
}
if g.DisallowUnknownFields {
fmt.Fprintln(f, " g.DisallowUnknownFields()")
_, _ = fmt.Fprintln(f, " g.DisallowUnknownFields()")
}
if g.SimpleBytes {
fmt.Fprintln(f, " g.SimpleBytes()")
_, _ = fmt.Fprintln(f, " g.SimpleBytes()")
}
if g.SkipMemberNameUnescaping {
fmt.Fprintln(f, " g.SkipMemberNameUnescaping()")
_, _ = fmt.Fprintln(f, " g.SkipMemberNameUnescaping()")
}

sort.Strings(g.Types)
for _, v := range g.Types {
fmt.Fprintln(f, " g.Add(pkg.EasyJSON_exporter_"+v+"(nil))")
_, _ = fmt.Fprintln(f, " g.Add(pkg.EasyJSON_exporter_"+v+"(nil))")
}

fmt.Fprintln(f, " if err := g.Run(os.Stdout); err != nil {")
fmt.Fprintln(f, " fmt.Fprintln(os.Stderr, err)")
fmt.Fprintln(f, " os.Exit(1)")
fmt.Fprintln(f, " }")
fmt.Fprintln(f, "}")
_, _ = fmt.Fprintln(f, " if err := g.Run(os.Stdout); err != nil {")
_, _ = fmt.Fprintln(f, " fmt.Fprintln(os.Stderr, err)")
_, _ = fmt.Fprintln(f, " os.Exit(1)")
_, _ = fmt.Fprintln(f, " }")
_, _ = fmt.Fprintln(f, "}")

src := f.Name()
if err := f.Close(); err != nil {
Expand All @@ -171,15 +171,15 @@ func (g *Generator) Run() error {
return err
}
if !g.LeaveTemps {
defer os.Remove(path)
defer func() { _ = os.Remove(path) }()
}

f, err := os.Create(g.OutName + ".tmp")
if err != nil {
return err
}
if !g.LeaveTemps {
defer os.Remove(f.Name()) // will not remove after rename
defer func() { _ = os.Remove(f.Name()) }() // will not remove after rename
}

execArgs := []string{"run"}
Expand All @@ -196,7 +196,7 @@ func (g *Generator) Run() error {
if err = cmd.Run(); err != nil {
return err
}
f.Close()
_ = f.Close()

// move unformatted file to out path
if g.NoFormat {
Expand All @@ -212,5 +212,5 @@ func (g *Generator) Run() error {
if err != nil {
return err
}
return ioutil.WriteFile(g.OutName, out, 0644)
return ioutil.WriteFile(g.OutName, out, 0644) // #nosec G306 -- g.OutName is autogenerated code file, 0644 is fine.
}
4 changes: 2 additions & 2 deletions buffer/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func putBuf(buf []byte) {
// avoid an extra allocation.
// We don't care about the length and we know the capability so
// we don't need to save anything else.
c.Put(unsafe.Pointer(&buf[:1][0]))
c.Put(unsafe.Pointer(&buf[:1][0])) // #nosec G103
}
}

const maxArraySize = uint((uint64(1) << 50 - 1) & uint64(^uint(0) >> 1))
const maxArraySize = uint((uint64(1)<<50 - 1) & uint64(^uint(0)>>1))

// getBuf gets a chunk from reuse pool or creates a new one if reuse failed.
func getBuf(size int) []byte {
Expand Down
2 changes: 1 addition & 1 deletion buffer/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestReadCloser(t *testing.T) {
if err != nil {
t.Errorf("ReadCloser() error: %v", err)
}
rc.Close() // Will always return nil
_ = rc.Close() // Will always return nil

got := out.Bytes()
if !bytes.Equal(got, want) {
Expand Down
2 changes: 1 addition & 1 deletion easyjson/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func main() {

for _, fname := range files {
if err := generate(fname); err != nil {
fmt.Fprintln(os.Stderr, err)
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Expand Down
Loading