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 tests on windows #109

Merged
merged 1 commit into from
May 14, 2024
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
2 changes: 1 addition & 1 deletion cmd/xgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func handleBuild(cmd string, args []string) error {
return nil
}
}
instrumentGo := filepath.Join(instrumentGoroot, "bin", "go")
instrumentGo := filepath.Join(instrumentGoroot, "bin", "go"+osinfo.EXE_SUFFIX)
subPaths, mainModule, err := goinfo.ResolveMainModule(projectDir, remainArgs)
if err != nil {
if !errors.Is(err, goinfo.ErrGoModNotFound) && !errors.Is(err, goinfo.ErrGoModDoesNotHaveModule) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/xgo/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ func syncGoroot(goroot string, instrumentGoroot string, fullSyncRecordFile strin
return err
}
var goBinaryChanged bool = true
srcGoBin := filepath.Join(goroot, "bin", "go")
dstGoBin := filepath.Join(instrumentGoroot, "bin", "go")
srcGoBin := filepath.Join(goroot, "bin", "go"+osinfo.EXE_SUFFIX)
dstGoBin := filepath.Join(instrumentGoroot, "bin", "go"+osinfo.EXE_SUFFIX)

srcFile, err := os.Stat(srcGoBin)
if err != nil {
return nil
return err
}
if srcFile.IsDir() {
return fmt.Errorf("bad goroot: %s", goroot)
Expand Down
23 changes: 18 additions & 5 deletions cmd/xgo/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@ package main

import (
"path/filepath"
"runtime"
"testing"
)

// go test -run TestFilePathDir -v ./cmd/xgo
func TestFilePathDir(t *testing.T) {
var testCases = []struct {

type testCase struct {
Name string
Dir string
}{
}
var testCases = []testCase{
{"", "."},
{".", "."},
{"/", "/"},
{"/tmp", "/"},
{"//tmp", "/"},
}
if runtime.GOOS != "windows" {
testCases = append(testCases, []testCase{
{"/", "/"},
{"/tmp", "/"},
{"//tmp", "/"},
}...)
} else {
testCases = append(testCases, []testCase{
{"/", "\\"},
{"/tmp", "\\"},
{"//tmp", "\\\\tmp"},
}...)
}

for _, testCase := range testCases {
Expand Down
6 changes: 3 additions & 3 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"
)

const VERSION = "1.0.33"
const REVISION = "045b9e4ba45b4ef1e74d71cf64ffcff98761eaef+1"
const NUMBER = 214
const VERSION = "1.0.34"
const REVISION = "d73b24dafc105fe4610e9130b0db429892961b80+1"
const NUMBER = 215

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
9 changes: 7 additions & 2 deletions cmd/xgo/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func loadDependency(goroot string, goBinary string, goVersion *goinfo.GoVersion,
}
vendorModPath := filepath.Join(vendorDir, modPath)
vendorModFile := filepath.Join(vendorModPath, "go.mod")
replaceModFile := filepath.Join(tmpProjectDir, vendorModFile)
replaceModFile := filepath.Join(tmpProjectDir, asSubPath(vendorModFile))
// replace goMod => vendor=>

// NOTE: if replace without require, go will automatically add
Expand Down Expand Up @@ -490,6 +490,11 @@ func addBlankImports(goroot string, goBinary string, projectDir string, pkgArgs
return replace, nil
}

// when doing filepath.Join(a,b),
// on windows, if b has :, everything fails
func asSubPath(path string) string {
return fileutil.CleanSpecial(path)
}
func addBlankImportForPackage(srcDir string, dstDir string, imports []string, files []string, allFile bool) (map[string]string, error) {
if len(files) == 0 {
// no files
Expand All @@ -509,7 +514,7 @@ func addBlankImportForPackage(srcDir string, dstDir string, imports []string, fi
mapping := make(map[string]string, len(files))
for _, file := range files {
srcFile := filepath.Join(srcDir, file)
dstFile := filepath.Join(dstDir, srcFile)
dstFile := filepath.Join(dstDir, asSubPath(srcFile))
err := filecopy.CopyFileAll(srcFile, dstFile)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import "fmt"

const VERSION = "1.0.33"
const REVISION = "045b9e4ba45b4ef1e74d71cf64ffcff98761eaef+1"
const NUMBER = 214
const VERSION = "1.0.34"
const REVISION = "d73b24dafc105fe4610e9130b0db429892961b80+1"
const NUMBER = 215

func getRevision() string {
revSuffix := ""
Expand Down
6 changes: 3 additions & 3 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"
)

const VERSION = "1.0.33"
const REVISION = "045b9e4ba45b4ef1e74d71cf64ffcff98761eaef+1"
const NUMBER = 214
const VERSION = "1.0.34"
const REVISION = "d73b24dafc105fe4610e9130b0db429892961b80+1"
const NUMBER = 215

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
1 change: 1 addition & 0 deletions runtime/test/mock_stdlib/mock_stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// go run ./script/run-test/ --include go1.22.1 --xgo-runtime-test-only -run TestMockTimeNow -v ./test/mock_stdlib
func TestMockTimeNow(t *testing.T) {
now1 := time.Now()
time.Sleep(1 * time.Millisecond)
now2 := time.Now()

d1 := now2.Sub(now1)
Expand Down
6 changes: 5 additions & 1 deletion script/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ func generateFuncHelperCode(srcFile string) (*genInfo, error) {

funcStubCode := getSlice(code, fset, st.Pos(), st.End())

helperCode := getSlice(code, fset, astFile.Name.End(), astFile.FileEnd)
// TODO: use astFile.FileEnd
var fileEnd token.Pos
fileEnd = astFile.End()

helperCode := getSlice(code, fset, astFile.Name.End(), fileEnd)
return &genInfo{
funcStub: funcStubCode,
helperCode: helperCode,
Expand Down
15 changes: 8 additions & 7 deletions support/netutil/netutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ func IsTCPAddrServing(url string, timeout time.Duration) (bool, error) {

func ServePort(port int, autoIncrPort bool, watchTimeout time.Duration, watch func(port int), doWithPort func(port int) error) error {
for {
serving, err := IsTCPAddrServing(net.JoinHostPort("localhost", strconv.Itoa(port)), 20*time.Millisecond)
if err != nil {
return err
}
if serving {
continue
}

// open url after 500ms, waiting for port opening to check if error
portErr := make(chan struct{})
if watchTimeout > 0 && watch != nil {
Expand All @@ -27,13 +35,6 @@ func ServePort(port int, autoIncrPort bool, watchTimeout time.Duration, watch fu
})
}

serving, err := IsTCPAddrServing(net.JoinHostPort("localhost", strconv.Itoa(port)), 20*time.Millisecond)
if err != nil {
return err
}
if serving {
continue
}
err = doWithPort(port)
if err == nil {
return nil
Expand Down
Loading