This is an automated email from the ASF dual-hosted git repository.

riteshghorse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 917921fa177 [Go SDK] Fix most compile and bugs on Windows. (#25634)
917921fa177 is described below

commit 917921fa177596456d5fcf0b5b5e7d8ff1f17bc1
Author: Jeremy Edwards <[email protected]>
AuthorDate: Mon Mar 13 06:49:16 2023 -0700

    [Go SDK] Fix most compile and bugs on Windows. (#25634)
---
 .../pkg/beam/core/runtime/xlangx/expansionx/download_test.go |  2 +-
 sdks/go/pkg/beam/core/util/symtab/symtab_test.go             |  3 +++
 sdks/go/pkg/beam/io/filesystem/local/local_test.go           |  5 +++--
 sdks/go/pkg/beam/io/filesystem/memfs/memory.go               |  7 +++++--
 sdks/go/pkg/beam/io/filesystem/memfs/memory_test.go          | 11 +++++------
 sdks/go/pkg/beam/io/filesystem/util.go                       | 12 ++++++++++++
 sdks/go/test/integration/internal/jars/run_nonunix.go        |  3 ++-
 7 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download_test.go 
b/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download_test.go
index f466a333f91..9779c236189 100644
--- a/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download_test.go
+++ b/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download_test.go
@@ -172,7 +172,7 @@ func TestJarExists_bad(t *testing.T) {
 }
 
 func getGeneratedNumberInFile(fileName, jarPrefix string) string {
-       tmpFileNameSplit := strings.Split(fileName, "/")
+       tmpFileNameSplit := strings.Split(fileName, string(filepath.Separator))
        tmpFileName := tmpFileNameSplit[len(tmpFileNameSplit)-1]
        numSuffix := strings.TrimPrefix(tmpFileName, jarPrefix)
        return strings.TrimSuffix(numSuffix, ".jar")
diff --git a/sdks/go/pkg/beam/core/util/symtab/symtab_test.go 
b/sdks/go/pkg/beam/core/util/symtab/symtab_test.go
index 80c637132ac..78f8adeceaf 100644
--- a/sdks/go/pkg/beam/core/util/symtab/symtab_test.go
+++ b/sdks/go/pkg/beam/core/util/symtab/symtab_test.go
@@ -85,6 +85,9 @@ func TestSym2Addr(t *testing.T) {
        }
 
        bin := strings.TrimSuffix(fname, ".go")
+       if runtime.GOOS == "windows" {
+               bin += ".exe"
+       }
        defer os.Remove(bin)
 
        gotool := filepath.Join(runtime.GOROOT(), "bin", "go")
diff --git a/sdks/go/pkg/beam/io/filesystem/local/local_test.go 
b/sdks/go/pkg/beam/io/filesystem/local/local_test.go
index 6da8619956e..b1f650a835a 100644
--- a/sdks/go/pkg/beam/io/filesystem/local/local_test.go
+++ b/sdks/go/pkg/beam/io/filesystem/local/local_test.go
@@ -135,11 +135,12 @@ func TestLocal_util(t *testing.T) {
 
 func TestLocal_rename(t *testing.T) {
        ctx := context.Background()
-       dirPath := filepath.Join(os.TempDir(), "beamgolocalfilesystemtest")
+       tempDir := t.TempDir()
+       dirPath := filepath.Join(tempDir, "beamgolocalfilesystemtest")
        filePath1 := filepath.Join(dirPath, "file1.txt")
        filePath2 := filepath.Join(dirPath, "file2.txt")
        t.Cleanup(func() {
-               os.RemoveAll(dirPath)
+               os.RemoveAll(tempDir)
        })
 
        c, err := filesystem.New(ctx, dirPath)
diff --git a/sdks/go/pkg/beam/io/filesystem/memfs/memory.go 
b/sdks/go/pkg/beam/io/filesystem/memfs/memory.go
index c31aa3fe0f6..4637750d5a6 100644
--- a/sdks/go/pkg/beam/io/filesystem/memfs/memory.go
+++ b/sdks/go/pkg/beam/io/filesystem/memfs/memory.go
@@ -22,7 +22,7 @@ import (
        "fmt"
        "io"
        "os"
-       "path/filepath"
+       "runtime"
        "sort"
        "strings"
        "sync"
@@ -59,7 +59,7 @@ func (f *fs) List(_ context.Context, glob string) ([]string, 
error) {
 
        var ret []string
        for k := range f.m {
-               matched, err := filepath.Match(globNoScheme, 
strings.TrimPrefix(k, "memfs://"))
+               matched, err := filesystem.Match(globNoScheme, 
strings.TrimPrefix(k, "memfs://"))
                if err != nil {
                        return nil, fmt.Errorf("invalid glob pattern: %w", err)
                }
@@ -145,6 +145,9 @@ func Write(key string, value []byte) {
 }
 
 func normalize(key string) string {
+       if runtime.GOOS == "windows" {
+               key = strings.ReplaceAll(key, "\\", "/")
+       }
        if strings.HasPrefix(key, "memfs://") {
                return key
        }
diff --git a/sdks/go/pkg/beam/io/filesystem/memfs/memory_test.go 
b/sdks/go/pkg/beam/io/filesystem/memfs/memory_test.go
index 3944ba72456..6f76ee0759e 100644
--- a/sdks/go/pkg/beam/io/filesystem/memfs/memory_test.go
+++ b/sdks/go/pkg/beam/io/filesystem/memfs/memory_test.go
@@ -18,7 +18,6 @@ package memfs
 import (
        "context"
        "os"
-       "path/filepath"
        "testing"
 
        "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem"
@@ -155,17 +154,17 @@ func TestListTable(t *testing.T) {
                        name: "dirs",
                        files: []string{
                                "fizzbuzz",
-                               filepath.Join("xyz", "12"),
-                               filepath.Join("xyz", "1234"),
-                               filepath.Join("xyz", "1235"),
+                               "xyz/12",
+                               "xyz/1234",
+                               "xyz/1235",
                                "foobar",
                                "baz",
                                "bazfoo",
                        },
                        pattern: "memfs://xyz/123*",
                        want: []string{
-                               "memfs://" + filepath.Join("xyz", "1234"),
-                               "memfs://" + filepath.Join("xyz", "1235"),
+                               "memfs://xyz/1234",
+                               "memfs://xyz/1235",
                        },
                },
        } {
diff --git a/sdks/go/pkg/beam/io/filesystem/util.go 
b/sdks/go/pkg/beam/io/filesystem/util.go
index 264f34d2843..66d1472b664 100644
--- a/sdks/go/pkg/beam/io/filesystem/util.go
+++ b/sdks/go/pkg/beam/io/filesystem/util.go
@@ -19,6 +19,9 @@ import (
        "context"
        "fmt"
        "io"
+       "path/filepath"
+       "runtime"
+       "strings"
 )
 
 // Read fully reads the given file from the file system.
@@ -101,6 +104,15 @@ func Rename(ctx context.Context, fs Interface, oldpath, 
newpath string) error {
        return nil
 }
 
+// Match is a platform agnostic version of filepath.Match where \ is treated 
as / on Windows.
+func Match(pattern, name string) (bool, error) {
+       // Windows accepts / and \ as directory separators. For the sake of 
consistency with other schemes such as memfs:// we'll convert \ to /.
+       if runtime.GOOS == "windows" {
+               return filepath.Match(strings.ReplaceAll(pattern, "/", "//"), 
strings.ReplaceAll(name, "/", "//"))
+       }
+       return filepath.Match(pattern, name)
+}
+
 type unimplementedError struct {
        fs          Interface
        iface, mthd string
diff --git a/sdks/go/test/integration/internal/jars/run_nonunix.go 
b/sdks/go/test/integration/internal/jars/run_nonunix.go
index 189f2ab2720..2d392e7cfa2 100644
--- a/sdks/go/test/integration/internal/jars/run_nonunix.go
+++ b/sdks/go/test/integration/internal/jars/run_nonunix.go
@@ -21,6 +21,7 @@ package jars
 
 import (
        "fmt"
+       "os/exec"
        "runtime"
        "time"
 )
@@ -29,7 +30,7 @@ import (
 // non-unix version does not handle timeout durations.
 func getTimeoutRunner() runCallback {
        // Wrap run with error handling for OS that does not support timeout 
duration.
-       return func(dur time.Duration, jar string, args ...string) (*Process, 
error) {
+       return func(dur time.Duration, jar string, args ...string) (Process, 
error) {
                // Currently, we hard-fail here if a duration is provided but 
timeout is unsupported. If
                // we ever decide to soft-fail instead, this is the code to 
change.
                if dur != 0 {

Reply via email to