Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Mar 30, 2024
1 parent 6d76bd0 commit f871d10
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ jobs:
run: go build -v ./cmd/...

- name: Test
run: go run ./script/run-test -v
run: go run ./script/run-test -v -cover -coverpkg github.com/xhd2015/xgo/runtime/... -coverprofile covers/cover.out

- name: Print coverage
run: cd runtime && go tool cover --func ../covers/cover-runtime.out

- name: Build Release
run: go run ./script/build-release
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@

# generated traces
/runtime/test/**/*.json
/test/**/*.json
/test/**/*.json

# coverage
/covers
cover*.out
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

# xgo
[![Go Reference](https://pkg.go.dev/badge/github.com/xhd2015/xgo.svg)](https://pkg.go.dev/github.com/xhd2015/xgo)
[![Go Report Card](https://goreportcard.com/badge/github.com/xhd2015/xgo)](https://goreportcard.com/report/github.com/xhd2015/xgo)
[![Go Coverage](https://img.shields.io/badge/Coverage-71.9%25-brightgreen)](https://github.com/xhd2015/xgo/actions)
[![CI](https://github.com/xhd2015/xgo/workflows/Go/badge.svg)](https://github.com/xhd2015/xgo/actions)

**English | [简体中文](./README_zh_cn.md)**

Expand Down
9 changes: 4 additions & 5 deletions cmd/xgo/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ func getVscodeDebugFile(tmpDir string, vscode string) (vscodeDebugFile string, s
} else if vscode == "stdout" || strings.HasPrefix(vscode, stdoutParamPrefix) {
vscodeDebugFile = filepath.Join(tmpDir, "vscode_launch.json")
} else {
f, err := os.Stat(vscode)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
return "", "", fmt.Errorf("check vscode debug flag: %w", err)
f, statErr := os.Stat(vscode)
if statErr != nil {
if !errors.Is(statErr, os.ErrNotExist) {
return "", "", fmt.Errorf("check vscode debug flag: %w", statErr)

}
err = nil
// treat as file
}
if f != nil && f.IsDir() {
Expand Down
22 changes: 10 additions & 12 deletions cmd/xgo/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func patchRuntimeAndCompiler(origGoroot string, goroot string, xgoSrc string, go
return fmt.Errorf("requires goroot")
}
if isDevelopment && xgoSrc == "" {
return fmt.Errorf("requries xgoSrc")
return fmt.Errorf("requires xgoSrc")
}
if !isDevelopment && !revisionChanged {
return nil
Expand Down Expand Up @@ -892,12 +892,11 @@ func syncGoroot(goroot string, dstDir string, forceCopy bool) error {
return fmt.Errorf("bad goroot: %s", goroot)
}

dstFile, err := os.Stat(dstGoBin)
if err != nil {
if !os.IsNotExist(err) {
return err
dstFile, statErr := os.Stat(dstGoBin)
if statErr != nil {
if !os.IsNotExist(statErr) {
return statErr
}
err = nil
}

if dstFile != nil && !dstFile.IsDir() && dstFile.Size() == srcFile.Size() {
Expand Down Expand Up @@ -965,7 +964,7 @@ func buildInstrumentTool(goroot string, xgoSrc string, compilerBin string, compi
// but if that is not found, we can fallback to ~/.xgo/bin/exec_tool
// because exec_tool changes rarely, so it is safe to use
// an older version.
// we may add version to check if exec_tool is compitable
// we may add version to check if exec_tool is compatible
func findBuiltExecTool() (string, error) {
dirName := filepath.Dir(os.Args[0])
absDirName, err := filepath.Abs(dirName)
Expand Down Expand Up @@ -1008,12 +1007,11 @@ func buildCompiler(goroot string, output string) error {
}

func compareAndUpdateCompilerID(compilerFile string, compilerIDFile string) (changed bool, err error) {
prevData, err := ioutil.ReadFile(compilerIDFile)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
return false, err
prevData, statErr := ioutil.ReadFile(compilerIDFile)
if statErr != nil {
if !errors.Is(statErr, os.ErrNotExist) {
return false, statErr
}
err = nil
}
prevID := string(prevData)
curID, err := getBuildID(compilerFile)
Expand Down
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.

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 = "e0f9e969d9f62daa515c94bbde128f91a029b38e+1"
const NUMBER = 131
const REVISION = "6d76bd0ec32e7b161f19ac216fc42af3eccecadd+1"
const NUMBER = 132

func getRevision() string {
return fmt.Sprintf("%s %s BUILD_%d", VERSION, REVISION, NUMBER)
Expand Down
8 changes: 4 additions & 4 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 = "e0f9e969d9f62daa515c94bbde128f91a029b38e+1"
const NUMBER = 131
const REVISION = "6d76bd0ec32e7b161f19ac216fc42af3eccecadd+1"
const NUMBER = 132

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down Expand Up @@ -40,7 +40,7 @@ func checkVersion() error {
return errors.New("newer xgo available, consider run 'xgo upgrade'")
}
// only one case is feasible: XGO_NUMBER >= runtime NUMBER
// because xgo can be compitable with older sdk
// because xgo can be compatible with older sdk
return nil
}
var updateCmd string
Expand All @@ -49,5 +49,5 @@ func checkVersion() error {
} else {
updateCmd = "go get github.com/xhd2015/xgo/runtime@latest"
}
return fmt.Errorf("xgo v%s maybe incompitable with xgo/runtime v%s, consider run '%s'", XGO_VERSION, VERSION, updateCmd)
return fmt.Errorf("xgo v%s maybe incompatible with xgo/runtime v%s, consider run '%s'", XGO_VERSION, VERSION, updateCmd)
}
52 changes: 49 additions & 3 deletions script/run-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func main() {
var xgoTestOnly bool
var xgoRuntimeTestOnly bool
var xgoDefaultTestOnly bool

var cover bool
var coverpkgs []string
var coverprofile string
for i := 0; i < n; i++ {
arg := args[i]
if arg == "--exclude" {
Expand Down Expand Up @@ -103,6 +107,20 @@ func main() {
xgoDefaultTestOnly = true
continue
}
if arg == "-cover" {
cover = true
continue
}
if arg == "-coverpkg" {
coverpkgs = append(coverpkgs, args[i+1])
i++
continue
}
if arg == "-coverprofile" {
coverprofile = args[i+1]
i++
continue
}
if arg == "--" {
if i+1 < n {
remainArgs = append(remainArgs, args[i+1:]...)
Expand All @@ -116,6 +134,14 @@ func main() {
fmt.Fprintf(os.Stderr, "unknown flag: %s\n", arg)
os.Exit(1)
}
if coverprofile != "" {
absProfile, err := filepath.Abs(coverprofile)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
coverprofile = absProfile
}
goRelease := "go-release"
var goroots []string
_, err := os.Stat(goRelease)
Expand Down Expand Up @@ -199,23 +225,43 @@ func main() {
runXgoTestFlag = false
runDefault = true
}
addArgs := func(args []string, variant string) []string {
if cover {
args = append(args, "-cover")
}
for _, coverPkg := range coverpkgs {
args = append(args, "-coverpkg", coverPkg)
}
if coverprofile != "" {
var prefix string
var suffix string
idx := strings.LastIndex(coverprofile, ".")
if idx < 0 {
prefix = coverprofile
} else {
prefix, suffix = coverprofile[:idx], coverprofile[idx:]
}
args = append(args, "-coverprofile", prefix+"-"+variant+suffix)
}
return args
}
if runXgoTestFlag {
err := runXgoTest(goroot, remainArgs, remainTests)
err := runXgoTest(goroot, addArgs(remainArgs, "xgo"), remainTests)
if err != nil {
fmt.Fprintf(os.Stdout, "FAIL %s: %v(%v)\n", goroot, err, time.Since(begin))
os.Exit(1)
}
}

if runRuntimeTestFlag {
err := runRuntimeTest(goroot, remainArgs, remainTests)
err := runRuntimeTest(goroot, addArgs(remainArgs, "runtime"), remainTests)
if err != nil {
fmt.Fprintf(os.Stdout, "FAIL %s: %v(%v)\n", goroot, err, time.Since(begin))
os.Exit(1)
}
}
if runDefault {
err := runDefaultTest(goroot, remainArgs, remainTests)
err := runDefaultTest(goroot, addArgs(remainArgs, "default"), remainTests)
if err != nil {
fmt.Fprintf(os.Stdout, "FAIL %s: %v(%v)\n", goroot, err, time.Since(begin))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion test/func_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestFuncList(t *testing.T) {
expectMainLines := []string{
"func:main example",
"func:main someInt.value",
// "func:main (*someInt).inc", // this output is replaced with a simplier display name
// "func:main (*someInt).inc", // this output is replaced with a simpler display name
"func:main someInt.inc",
}

Expand Down

0 comments on commit f871d10

Please sign in to comment.