diff --git a/cmd/xgo/main.go b/cmd/xgo/main.go index 9ab6daf9..1bc6c2dd 100644 --- a/cmd/xgo/main.go +++ b/cmd/xgo/main.go @@ -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) { diff --git a/cmd/xgo/patch.go b/cmd/xgo/patch.go index 87dd7625..b15fff29 100644 --- a/cmd/xgo/patch.go +++ b/cmd/xgo/patch.go @@ -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) diff --git a/cmd/xgo/path_test.go b/cmd/xgo/path_test.go index 686c8233..52942c42 100644 --- a/cmd/xgo/path_test.go +++ b/cmd/xgo/path_test.go @@ -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 { diff --git a/cmd/xgo/runtime_gen/core/version.go b/cmd/xgo/runtime_gen/core/version.go index a846f676..995862ae 100755 --- a/cmd/xgo/runtime_gen/core/version.go +++ b/cmd/xgo/runtime_gen/core/version.go @@ -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 = "" diff --git a/cmd/xgo/trace.go b/cmd/xgo/trace.go index 3e275d59..262f9f7f 100644 --- a/cmd/xgo/trace.go +++ b/cmd/xgo/trace.go @@ -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 @@ -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 @@ -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 diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 066b2a5d..b4636635 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -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 := "" diff --git a/runtime/core/version.go b/runtime/core/version.go index a846f676..995862ae 100644 --- a/runtime/core/version.go +++ b/runtime/core/version.go @@ -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 = "" diff --git a/runtime/test/mock_stdlib/mock_stdlib_test.go b/runtime/test/mock_stdlib/mock_stdlib_test.go index 38f7c441..5af085b6 100644 --- a/runtime/test/mock_stdlib/mock_stdlib_test.go +++ b/runtime/test/mock_stdlib/mock_stdlib_test.go @@ -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) diff --git a/script/generate/main.go b/script/generate/main.go index 76d5d853..58a4c957 100644 --- a/script/generate/main.go +++ b/script/generate/main.go @@ -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, diff --git a/support/netutil/netutil.go b/support/netutil/netutil.go index 6dd4849d..37ec105b 100644 --- a/support/netutil/netutil.go +++ b/support/netutil/netutil.go @@ -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 { @@ -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