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/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/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)