Skip to content

Commit

Permalink
run gofmt -s -w
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Mar 30, 2024
1 parent 222b904 commit e0f9e96
Show file tree
Hide file tree
Showing 14 changed files with 421 additions and 420 deletions.
2 changes: 1 addition & 1 deletion cmd/trace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"net/http"
"os"
"os/exec"
"runtime/debug"
"runtime"
"runtime/debug"
"strings"
"time"

Expand Down
204 changes: 102 additions & 102 deletions cmd/xgo/log.go
Original file line number Diff line number Diff line change
@@ -1,102 +1,102 @@
package main

import (
"fmt"
"io"
"os"
"runtime"
"strings"
"time"

"github.com/xhd2015/xgo/support/osinfo"
)

var logDebugFile *os.File

func setupDebugLog(logDebugOption *string) (func(), error) {
var logDebugFileName string
if logDebugOption != nil {
logDebugFileName = *logDebugOption
if logDebugFileName == "" {
logDebugFileName = "debug.log"
}
}
if logDebugFileName == "" {
return nil, nil
}
return initLog(logDebugFileName)
}

func initLog(logDebugFileName string) (func(), error) {
if logDebugFileName == "stdout" {
logDebugFile = os.Stdout
return nil, nil
}
if logDebugFileName == "stderr" {
logDebugFile = os.Stderr
return nil, nil
}
var err error
logDebugFile, err = os.Create(logDebugFileName)
if err != nil {
return nil, fmt.Errorf("create log: %s %w", logDebugFileName, err)
}
return func() {
logDebugFile.Close()
}, nil
}

func logDebug(format string, args ...interface{}) {
if logDebugFile == nil {
return
}
fmt.Fprint(logDebugFile, time.Now().Format("2006-01-02 15:04:05"), " ")
fmt.Fprintf(logDebugFile, format, args...)
if !strings.HasSuffix(format, "\n") {
fmt.Fprintln(logDebugFile)
}
logDebugFile.Sync()
}

func logStartup() {
logDebug("start: %v", os.Args)
logDebug("runtime.GOOS=%s", runtime.GOOS)
logDebug("runtime.GOARCH=%s", runtime.GOARCH)
logDebug("runtime.Version()=%s", runtime.Version())
logDebug("runtime.GOROOT()=%s", runtime.GOROOT())
logDebug("os exe suffix: %s", osinfo.EXE_SUFFIX)
logDebug("os force copy unsym: %v", osinfo.FORCE_COPY_UNSYM)
}

// if [[ $verbose = true ]];then
//
// tail -fn1 "$shdir/compile.log" &
// trap "kill -9 $!" EXIT
// fi
func tailLog(logFile string) {
file, err := os.OpenFile(logFile, os.O_RDONLY|os.O_CREATE, 0755)
if err != nil {
fmt.Fprintf(os.Stderr, "open compile log: %v\n", err)
return
}
_, err = file.Seek(0, io.SeekEnd)
if err != nil {
fmt.Fprintf(os.Stderr, "seek tail compile log: %v\n", err)
return
}
buf := make([]byte, 1024)
for {
n, err := file.Read(buf)
if n > 0 {
os.Stdout.Write(buf[:n])
}
if err != nil {
if err == io.EOF {
time.Sleep(50 * time.Millisecond)
continue
}
fmt.Fprintf(os.Stderr, "tail compile log: %v\n", err)
return
}
}
}
package main

import (
"fmt"
"io"
"os"
"runtime"
"strings"
"time"

"github.com/xhd2015/xgo/support/osinfo"
)

var logDebugFile *os.File

func setupDebugLog(logDebugOption *string) (func(), error) {
var logDebugFileName string
if logDebugOption != nil {
logDebugFileName = *logDebugOption
if logDebugFileName == "" {
logDebugFileName = "debug.log"
}
}
if logDebugFileName == "" {
return nil, nil
}
return initLog(logDebugFileName)
}

func initLog(logDebugFileName string) (func(), error) {
if logDebugFileName == "stdout" {
logDebugFile = os.Stdout
return nil, nil
}
if logDebugFileName == "stderr" {
logDebugFile = os.Stderr
return nil, nil
}
var err error
logDebugFile, err = os.Create(logDebugFileName)
if err != nil {
return nil, fmt.Errorf("create log: %s %w", logDebugFileName, err)
}
return func() {
logDebugFile.Close()
}, nil
}

func logDebug(format string, args ...interface{}) {
if logDebugFile == nil {
return
}
fmt.Fprint(logDebugFile, time.Now().Format("2006-01-02 15:04:05"), " ")
fmt.Fprintf(logDebugFile, format, args...)
if !strings.HasSuffix(format, "\n") {
fmt.Fprintln(logDebugFile)
}
logDebugFile.Sync()
}

func logStartup() {
logDebug("start: %v", os.Args)
logDebug("runtime.GOOS=%s", runtime.GOOS)
logDebug("runtime.GOARCH=%s", runtime.GOARCH)
logDebug("runtime.Version()=%s", runtime.Version())
logDebug("runtime.GOROOT()=%s", runtime.GOROOT())
logDebug("os exe suffix: %s", osinfo.EXE_SUFFIX)
logDebug("os force copy unsym: %v", osinfo.FORCE_COPY_UNSYM)
}

// if [[ $verbose = true ]];then
//
// tail -fn1 "$shdir/compile.log" &
// trap "kill -9 $!" EXIT
// fi
func tailLog(logFile string) {
file, err := os.OpenFile(logFile, os.O_RDONLY|os.O_CREATE, 0755)
if err != nil {
fmt.Fprintf(os.Stderr, "open compile log: %v\n", err)
return
}
_, err = file.Seek(0, io.SeekEnd)
if err != nil {
fmt.Fprintf(os.Stderr, "seek tail compile log: %v\n", err)
return
}
buf := make([]byte, 1024)
for {
n, err := file.Read(buf)
if n > 0 {
os.Stdout.Write(buf[:n])
}
if err != nil {
if err == io.EOF {
time.Sleep(50 * time.Millisecond)
continue
}
fmt.Fprintf(os.Stderr, "tail compile log: %v\n", err)
return
}
}
}
2 changes: 1 addition & 1 deletion cmd/xgo/patch/runtime_def_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions cmd/xgo/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func handleTool(tool string, args []string) error {
n := len(tools)
for i := n - 1; i >= 0; i-- {
var invoked bool
invoked,lastErr = tryHandleTool(tools[i], args)
invoked, lastErr = tryHandleTool(tools[i], args)
if invoked {
return lastErr
}
Expand All @@ -37,15 +37,15 @@ func handleTool(tool string, args []string) error {
return lastErr
}

func tryHandleTool(tool string, args []string) (invoked bool,err error) {
func tryHandleTool(tool string, args []string) (invoked bool, err error) {
baseName := filepath.Base(tool)
if baseName != tool {
return false,fmt.Errorf("unknown tool: %s", tool)
return false, fmt.Errorf("unknown tool: %s", tool)
}
curName := filepath.Base(os.Args[0])
if baseName == curName {
// cannot invoke itself
return false,fmt.Errorf("unknown tool: %s", tool)
return false, fmt.Errorf("unknown tool: %s", tool)
}
dirName := filepath.Dir(os.Args[0])
toolExec := filepath.Join(dirName, tool)
Expand All @@ -54,7 +54,7 @@ func tryHandleTool(tool string, args []string) (invoked bool,err error) {
stat, statErr := os.Stat(toolExec)
if statErr != nil {
if !errors.Is(statErr, os.ErrNotExist) {
return false,fmt.Errorf("unknown tool: %s", tool)
return false, fmt.Errorf("unknown tool: %s", tool)
}
retryHome = true
} else if stat.IsDir() {
Expand All @@ -64,14 +64,14 @@ func tryHandleTool(tool string, args []string) (invoked bool,err error) {
// try ~/.xgo/bin/tool
home, homeErr := os.UserHomeDir()
if homeErr != nil {
return false,fmt.Errorf("unknown tool: %s", tool)
return false, fmt.Errorf("unknown tool: %s", tool)
}
toolExec = filepath.Join(home, ".xgo", "bin", tool)
stat, statErr := os.Stat(toolExec)
if statErr != nil || stat.IsDir() {
return false,fmt.Errorf("unknown tool: %s", tool)
return false, fmt.Errorf("unknown tool: %s", tool)
}
}

return true,cmd.Run(toolExec, args...)
return true, cmd.Run(toolExec, args...)
}
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.11"
const REVISION = "6fbaa7172da907f64dcd754f7b573ab08559b913+1"
const NUMBER = 129
const REVISION = "222b904213504b65394523b4f310b5e52c9520d9+1"
const NUMBER = 130

func getRevision() string {
return fmt.Sprintf("%s %s BUILD_%d", VERSION, REVISION, NUMBER)
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.11"
const REVISION = "6fbaa7172da907f64dcd754f7b573ab08559b913+1"
const NUMBER = 129
const REVISION = "222b904213504b65394523b4f310b5e52c9520d9+1"
const NUMBER = 130

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
4 changes: 2 additions & 2 deletions support/filecopy/copy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package filecopy

import (
"fmt"
"io"
"io/fs"
"os"
Expand All @@ -9,7 +10,6 @@ import (
"strings"
"sync"
"sync/atomic"
"fmt"
)

type Options struct {
Expand Down Expand Up @@ -48,7 +48,7 @@ func copyReplaceDir(srcDir string, targetDir string, opts *Options) error {
if srcDir == "" {
return fmt.Errorf("requires srcDir")
}

// fmt.Printf("targetDir: %s\n",targetDir)

// delete safety check
Expand Down
20 changes: 10 additions & 10 deletions support/osinfo/osinfo_nonwin.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//go:build !windows
// +build !windows

package osinfo

const EXE_SUFFIX = ""

// when copy files, should use
// symbolic as long as possible
const FORCE_COPY_UNSYM = false
//go:build !windows
// +build !windows

package osinfo

const EXE_SUFFIX = ""

// when copy files, should use
// symbolic as long as possible
const FORCE_COPY_UNSYM = false
20 changes: 10 additions & 10 deletions support/osinfo/osinfo_win.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//go:build windows
// +build windows

package osinfo

const EXE_SUFFIX = ".exe"

// when copy files, don't use
// symbolic as it may cause failure
const FORCE_COPY_UNSYM = true
//go:build windows
// +build windows

package osinfo

const EXE_SUFFIX = ".exe"

// when copy files, don't use
// symbolic as it may cause failure
const FORCE_COPY_UNSYM = true
5 changes: 3 additions & 2 deletions test/testdata/generic_param/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type List[T any] struct {
}

func (l List[T]) CloneLen() int { return 1 }
func (l *List[T]) Len() int { return 1 }
func (l *List[T]) Len() int { return 1 }

// ERR: generic type cannot be alias
// type List2[T any] = List[T]
Expand All @@ -50,5 +50,6 @@ func reverse[T any, V int64 | float64](s []T) []T {
}
return r
}

// cannot compile, at least one generic param
// func noParam[]()
// func noParam[]()
Loading

0 comments on commit e0f9e96

Please sign in to comment.