]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: merge overlayDir into one package
authorAustin Clements <austin@google.com>
Mon, 22 May 2023 14:32:31 +0000 (10:32 -0400)
committerAustin Clements <austin@google.com>
Mon, 22 May 2023 20:56:09 +0000 (20:56 +0000)
There are many copies of overlaydir_test.go between the cgo tests
from when these couldn't share code. Now that they can, merge these
copies into a cmd/cgo/internal/cgotest package.

Change-Id: I203217f5d08e6306cb049a13718652cf7c447b80
Reviewed-on: https://go-review.googlesource.com/c/go/+/497078
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 files changed:
src/cmd/cgo/internal/cgotest/overlaydir.go [moved from src/cmd/cgo/internal/testso/overlaydir_test.go with 85% similarity]
src/cmd/cgo/internal/testcarchive/carchive_test.go
src/cmd/cgo/internal/testcarchive/overlaydir_test.go [deleted file]
src/cmd/cgo/internal/testcshared/cshared_test.go
src/cmd/cgo/internal/testcshared/overlaydir_test.go [deleted file]
src/cmd/cgo/internal/testlife/life_test.go
src/cmd/cgo/internal/testlife/overlaydir_test.go [deleted file]
src/cmd/cgo/internal/testplugin/overlaydir_test.go [deleted file]
src/cmd/cgo/internal/testplugin/plugin_test.go
src/cmd/cgo/internal/testshared/overlaydir_test.go [deleted file]
src/cmd/cgo/internal/testshared/shared_test.go
src/cmd/cgo/internal/testso/so_test.go
src/cmd/cgo/internal/teststdio/overlaydir_test.go [deleted file]
src/cmd/cgo/internal/teststdio/stdio_test.go

similarity index 85%
rename from src/cmd/cgo/internal/testso/overlaydir_test.go
rename to src/cmd/cgo/internal/cgotest/overlaydir.go
index 09a1d512f1e5fb548722313f4308a5d93890ae85..c6b161545dfe067e95f006c6303a196eb8865f61 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package so_test
+package cgotest
 
 import (
        "io"
@@ -11,11 +11,8 @@ import (
        "strings"
 )
 
-// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
-//
-// TODO: Once we no longer need to support the misc module in GOPATH mode,
-// factor this function out into a package to reduce duplication.
-func overlayDir(dstRoot, srcRoot string) error {
+// OverlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
+func OverlayDir(dstRoot, srcRoot string) error {
        dstRoot = filepath.Clean(dstRoot)
        if err := os.MkdirAll(dstRoot, 0777); err != nil {
                return err
index cdb90fd130a72ba8dbc63482415031af6996e13a..ef59101b1c0c3a85300c8e12235cfc85b11ffe29 100644 (file)
@@ -12,6 +12,7 @@ package carchive_test
 import (
        "bufio"
        "bytes"
+       "cmd/cgo/internal/cgotest"
        "debug/elf"
        "flag"
        "fmt"
@@ -82,7 +83,7 @@ func testMain(m *testing.M) int {
        // Copy testdata into GOPATH/src/testarchive, along with a go.mod file
        // declaring the same path.
        modRoot := filepath.Join(GOPATH, "src", "testcarchive")
-       if err := overlayDir(modRoot, "testdata"); err != nil {
+       if err := cgotest.OverlayDir(modRoot, "testdata"); err != nil {
                log.Panic(err)
        }
        if err := os.Chdir(modRoot); err != nil {
diff --git a/src/cmd/cgo/internal/testcarchive/overlaydir_test.go b/src/cmd/cgo/internal/testcarchive/overlaydir_test.go
deleted file mode 100644 (file)
index 67974c5..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package carchive_test
-
-import (
-       "io"
-       "os"
-       "path/filepath"
-       "strings"
-)
-
-// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
-//
-// TODO: Once we no longer need to support the misc module in GOPATH mode,
-// factor this function out into a package to reduce duplication.
-func overlayDir(dstRoot, srcRoot string) error {
-       dstRoot = filepath.Clean(dstRoot)
-       if err := os.MkdirAll(dstRoot, 0777); err != nil {
-               return err
-       }
-
-       srcRoot, err := filepath.Abs(srcRoot)
-       if err != nil {
-               return err
-       }
-
-       return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
-               if err != nil || srcPath == srcRoot {
-                       return err
-               }
-
-               suffix := strings.TrimPrefix(srcPath, srcRoot)
-               for len(suffix) > 0 && suffix[0] == filepath.Separator {
-                       suffix = suffix[1:]
-               }
-               dstPath := filepath.Join(dstRoot, suffix)
-
-               perm := info.Mode() & os.ModePerm
-               if info.Mode()&os.ModeSymlink != 0 {
-                       info, err = os.Stat(srcPath)
-                       if err != nil {
-                               return err
-                       }
-                       perm = info.Mode() & os.ModePerm
-               }
-
-               // Always copy directories (don't symlink them).
-               // If we add a file in the overlay, we don't want to add it in the original.
-               if info.IsDir() {
-                       return os.MkdirAll(dstPath, perm|0200)
-               }
-
-               // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(srcPath, dstPath); err == nil {
-                       return nil
-               }
-
-               // Otherwise, copy the bytes.
-               src, err := os.Open(srcPath)
-               if err != nil {
-                       return err
-               }
-               defer src.Close()
-
-               dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
-               if err != nil {
-                       return err
-               }
-
-               _, err = io.Copy(dst, src)
-               if closeErr := dst.Close(); err == nil {
-                       err = closeErr
-               }
-               return err
-       })
-}
index d1d79b72b0e3d6c9b81085a219f384aae3d49dad..0f98f2c1dcd5b8dd7be1243e7e321a5854b38313 100644 (file)
@@ -7,6 +7,7 @@ package cshared_test
 import (
        "bufio"
        "bytes"
+       "cmd/cgo/internal/cgotest"
        "debug/elf"
        "debug/pe"
        "encoding/binary"
@@ -137,7 +138,7 @@ func testMain(m *testing.M) int {
        os.Setenv("GOPATH", GOPATH)
 
        modRoot := filepath.Join(GOPATH, "src", "testcshared")
-       if err := overlayDir(modRoot, "testdata"); err != nil {
+       if err := cgotest.OverlayDir(modRoot, "testdata"); err != nil {
                log.Panic(err)
        }
        if err := os.Chdir(modRoot); err != nil {
diff --git a/src/cmd/cgo/internal/testcshared/overlaydir_test.go b/src/cmd/cgo/internal/testcshared/overlaydir_test.go
deleted file mode 100644 (file)
index 85d6b44..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package cshared_test
-
-import (
-       "io"
-       "os"
-       "path/filepath"
-       "strings"
-)
-
-// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
-//
-// TODO: Once we no longer need to support the misc module in GOPATH mode,
-// factor this function out into a package to reduce duplication.
-func overlayDir(dstRoot, srcRoot string) error {
-       dstRoot = filepath.Clean(dstRoot)
-       if err := os.MkdirAll(dstRoot, 0777); err != nil {
-               return err
-       }
-
-       srcRoot, err := filepath.Abs(srcRoot)
-       if err != nil {
-               return err
-       }
-
-       return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
-               if err != nil || srcPath == srcRoot {
-                       return err
-               }
-
-               suffix := strings.TrimPrefix(srcPath, srcRoot)
-               for len(suffix) > 0 && suffix[0] == filepath.Separator {
-                       suffix = suffix[1:]
-               }
-               dstPath := filepath.Join(dstRoot, suffix)
-
-               perm := info.Mode() & os.ModePerm
-               if info.Mode()&os.ModeSymlink != 0 {
-                       info, err = os.Stat(srcPath)
-                       if err != nil {
-                               return err
-                       }
-                       perm = info.Mode() & os.ModePerm
-               }
-
-               // Always copy directories (don't symlink them).
-               // If we add a file in the overlay, we don't want to add it in the original.
-               if info.IsDir() {
-                       return os.MkdirAll(dstPath, perm|0200)
-               }
-
-               // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(srcPath, dstPath); err == nil {
-                       return nil
-               }
-
-               // Otherwise, copy the bytes.
-               src, err := os.Open(srcPath)
-               if err != nil {
-                       return err
-               }
-               defer src.Close()
-
-               dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
-               if err != nil {
-                       return err
-               }
-
-               _, err = io.Copy(dst, src)
-               if closeErr := dst.Close(); err == nil {
-                       err = closeErr
-               }
-               return err
-       })
-}
index 7beeaa98238f9ed44e04852d85c53168aff6bf2d..e93d29c4d978b7658aedb985ace73cb96c84123e 100644 (file)
@@ -6,6 +6,7 @@ package life_test
 
 import (
        "bytes"
+       "cmd/cgo/internal/cgotest"
        "internal/testenv"
        "log"
        "os"
@@ -30,7 +31,7 @@ func testMain(m *testing.M) int {
        // Copy testdata into GOPATH/src/cgolife, along with a go.mod file
        // declaring the same path.
        modRoot := filepath.Join(GOPATH, "src", "cgolife")
-       if err := overlayDir(modRoot, "testdata"); err != nil {
+       if err := cgotest.OverlayDir(modRoot, "testdata"); err != nil {
                log.Panic(err)
        }
        if err := os.Chdir(modRoot); err != nil {
diff --git a/src/cmd/cgo/internal/testlife/overlaydir_test.go b/src/cmd/cgo/internal/testlife/overlaydir_test.go
deleted file mode 100644 (file)
index 034c836..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package life_test
-
-import (
-       "io"
-       "os"
-       "path/filepath"
-       "strings"
-)
-
-// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
-//
-// TODO: Once we no longer need to support the misc module in GOPATH mode,
-// factor this function out into a package to reduce duplication.
-func overlayDir(dstRoot, srcRoot string) error {
-       dstRoot = filepath.Clean(dstRoot)
-       if err := os.MkdirAll(dstRoot, 0777); err != nil {
-               return err
-       }
-
-       srcRoot, err := filepath.Abs(srcRoot)
-       if err != nil {
-               return err
-       }
-
-       return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
-               if err != nil || srcPath == srcRoot {
-                       return err
-               }
-
-               suffix := strings.TrimPrefix(srcPath, srcRoot)
-               for len(suffix) > 0 && suffix[0] == filepath.Separator {
-                       suffix = suffix[1:]
-               }
-               dstPath := filepath.Join(dstRoot, suffix)
-
-               perm := info.Mode() & os.ModePerm
-               if info.Mode()&os.ModeSymlink != 0 {
-                       info, err = os.Stat(srcPath)
-                       if err != nil {
-                               return err
-                       }
-                       perm = info.Mode() & os.ModePerm
-               }
-
-               // Always copy directories (don't symlink them).
-               // If we add a file in the overlay, we don't want to add it in the original.
-               if info.IsDir() {
-                       return os.MkdirAll(dstPath, perm|0200)
-               }
-
-               // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(srcPath, dstPath); err == nil {
-                       return nil
-               }
-
-               // Otherwise, copy the bytes.
-               src, err := os.Open(srcPath)
-               if err != nil {
-                       return err
-               }
-               defer src.Close()
-
-               dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
-               if err != nil {
-                       return err
-               }
-
-               _, err = io.Copy(dst, src)
-               if closeErr := dst.Close(); err == nil {
-                       err = closeErr
-               }
-               return err
-       })
-}
diff --git a/src/cmd/cgo/internal/testplugin/overlaydir_test.go b/src/cmd/cgo/internal/testplugin/overlaydir_test.go
deleted file mode 100644 (file)
index e2c32d8..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package plugin_test
-
-import (
-       "io"
-       "os"
-       "path/filepath"
-       "strings"
-)
-
-// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
-//
-// TODO: Once we no longer need to support the misc module in GOPATH mode,
-// factor this function out into a package to reduce duplication.
-func overlayDir(dstRoot, srcRoot string) error {
-       dstRoot = filepath.Clean(dstRoot)
-       if err := os.MkdirAll(dstRoot, 0777); err != nil {
-               return err
-       }
-
-       srcRoot, err := filepath.Abs(srcRoot)
-       if err != nil {
-               return err
-       }
-
-       return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
-               if err != nil || srcPath == srcRoot {
-                       return err
-               }
-
-               suffix := strings.TrimPrefix(srcPath, srcRoot)
-               for len(suffix) > 0 && suffix[0] == filepath.Separator {
-                       suffix = suffix[1:]
-               }
-               dstPath := filepath.Join(dstRoot, suffix)
-
-               perm := info.Mode() & os.ModePerm
-               if info.Mode()&os.ModeSymlink != 0 {
-                       info, err = os.Stat(srcPath)
-                       if err != nil {
-                               return err
-                       }
-                       perm = info.Mode() & os.ModePerm
-               }
-
-               // Always copy directories (don't symlink them).
-               // If we add a file in the overlay, we don't want to add it in the original.
-               if info.IsDir() {
-                       return os.MkdirAll(dstPath, perm|0200)
-               }
-
-               // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(srcPath, dstPath); err == nil {
-                       return nil
-               }
-
-               // Otherwise, copy the bytes.
-               src, err := os.Open(srcPath)
-               if err != nil {
-                       return err
-               }
-               defer src.Close()
-
-               dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
-               if err != nil {
-                       return err
-               }
-
-               _, err = io.Copy(dst, src)
-               if closeErr := dst.Close(); err == nil {
-                       err = closeErr
-               }
-               return err
-       })
-}
index e211a96304a938b2348805ca3e649a325c618381..4c8e3d7833a5f1b172100ee294b1b50e7f632296 100644 (file)
@@ -6,6 +6,7 @@ package plugin_test
 
 import (
        "bytes"
+       "cmd/cgo/internal/cgotest"
        "context"
        "flag"
        "fmt"
@@ -80,7 +81,7 @@ func testMain(m *testing.M) int {
                "testdata":                           modRoot,
                filepath.Join("altpath", "testdata"): altRoot,
        } {
-               if err := overlayDir(dstRoot, srcRoot); err != nil {
+               if err := cgotest.OverlayDir(dstRoot, srcRoot); err != nil {
                        log.Panic(err)
                }
                prettyPrintf("mkdir -p %s\n", dstRoot)
diff --git a/src/cmd/cgo/internal/testshared/overlaydir_test.go b/src/cmd/cgo/internal/testshared/overlaydir_test.go
deleted file mode 100644 (file)
index eb587a2..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package shared_test
-
-import (
-       "io"
-       "os"
-       "path/filepath"
-       "strings"
-)
-
-// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
-//
-// TODO: Once we no longer need to support the misc module in GOPATH mode,
-// factor this function out into a package to reduce duplication.
-func overlayDir(dstRoot, srcRoot string) error {
-       dstRoot = filepath.Clean(dstRoot)
-       if err := os.MkdirAll(dstRoot, 0777); err != nil {
-               return err
-       }
-
-       srcRoot, err := filepath.Abs(srcRoot)
-       if err != nil {
-               return err
-       }
-
-       return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
-               if err != nil || srcPath == srcRoot {
-                       return err
-               }
-
-               suffix := strings.TrimPrefix(srcPath, srcRoot)
-               for len(suffix) > 0 && suffix[0] == filepath.Separator {
-                       suffix = suffix[1:]
-               }
-               dstPath := filepath.Join(dstRoot, suffix)
-
-               perm := info.Mode() & os.ModePerm
-               if info.Mode()&os.ModeSymlink != 0 {
-                       info, err = os.Stat(srcPath)
-                       if err != nil {
-                               return err
-                       }
-                       perm = info.Mode() & os.ModePerm
-               }
-
-               // Always copy directories (don't symlink them).
-               // If we add a file in the overlay, we don't want to add it in the original.
-               if info.IsDir() {
-                       return os.MkdirAll(dstPath, perm|0200)
-               }
-
-               // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(srcPath, dstPath); err == nil {
-                       return nil
-               }
-
-               // Otherwise, copy the bytes.
-               src, err := os.Open(srcPath)
-               if err != nil {
-                       return err
-               }
-               defer src.Close()
-
-               dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
-               if err != nil {
-                       return err
-               }
-
-               _, err = io.Copy(dst, src)
-               if closeErr := dst.Close(); err == nil {
-                       err = closeErr
-               }
-               return err
-       })
-}
index 05e87b9d50c76c51c26b37f1d0d6833ca51ec84f..6596d88952c8b81a8cbf6d8e3337378e61ac2d14 100644 (file)
@@ -7,6 +7,7 @@ package shared_test
 import (
        "bufio"
        "bytes"
+       "cmd/cgo/internal/cgotest"
        "debug/elf"
        "encoding/binary"
        "flag"
@@ -203,7 +204,7 @@ func TestMain(m *testing.M) {
 // It returns the directory within gopath at which the module root is located.
 func cloneTestdataModule(gopath string) (string, error) {
        modRoot := filepath.Join(gopath, "src", "testshared")
-       if err := overlayDir(modRoot, "testdata"); err != nil {
+       if err := cgotest.OverlayDir(modRoot, "testdata"); err != nil {
                return "", err
        }
        if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module testshared\n"), 0644); err != nil {
@@ -255,7 +256,7 @@ func cloneGOROOTDeps(goroot string) error {
                if testing.Verbose() {
                        fmt.Fprintf(os.Stderr, "+ cp -r %s %s\n", filepath.Join(oldGOROOT, dir), filepath.Join(goroot, dir))
                }
-               if err := overlayDir(filepath.Join(goroot, dir), filepath.Join(oldGOROOT, dir)); err != nil {
+               if err := cgotest.OverlayDir(filepath.Join(goroot, dir), filepath.Join(oldGOROOT, dir)); err != nil {
                        return err
                }
        }
index e7fa0cadc315e9523a3b23a2f8f5f902b99504ab..e011167f388ed3656f909a435c53830e29f61d9b 100644 (file)
@@ -5,6 +5,7 @@
 package so_test
 
 import (
+       "cmd/cgo/internal/cgotest"
        "internal/testenv"
        "log"
        "os"
@@ -38,7 +39,7 @@ func testSO(t *testing.T, dir string) {
        defer os.RemoveAll(GOPATH)
 
        modRoot := filepath.Join(GOPATH, "src", "cgosotest")
-       if err := overlayDir(modRoot, filepath.Join("testdata", dir)); err != nil {
+       if err := cgotest.OverlayDir(modRoot, filepath.Join("testdata", dir)); err != nil {
                log.Panic(err)
        }
        if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgosotest\n"), 0666); err != nil {
diff --git a/src/cmd/cgo/internal/teststdio/overlaydir_test.go b/src/cmd/cgo/internal/teststdio/overlaydir_test.go
deleted file mode 100644 (file)
index 027ebf1..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package stdio_test
-
-import (
-       "io"
-       "os"
-       "path/filepath"
-       "strings"
-)
-
-// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
-//
-// TODO: Once we no longer need to support the misc module in GOPATH mode,
-// factor this function out into a package to reduce duplication.
-func overlayDir(dstRoot, srcRoot string) error {
-       dstRoot = filepath.Clean(dstRoot)
-       if err := os.MkdirAll(dstRoot, 0777); err != nil {
-               return err
-       }
-
-       srcRoot, err := filepath.Abs(srcRoot)
-       if err != nil {
-               return err
-       }
-
-       return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
-               if err != nil || srcPath == srcRoot {
-                       return err
-               }
-
-               suffix := strings.TrimPrefix(srcPath, srcRoot)
-               for len(suffix) > 0 && suffix[0] == filepath.Separator {
-                       suffix = suffix[1:]
-               }
-               dstPath := filepath.Join(dstRoot, suffix)
-
-               perm := info.Mode() & os.ModePerm
-               if info.Mode()&os.ModeSymlink != 0 {
-                       info, err = os.Stat(srcPath)
-                       if err != nil {
-                               return err
-                       }
-                       perm = info.Mode() & os.ModePerm
-               }
-
-               // Always copy directories (don't symlink them).
-               // If we add a file in the overlay, we don't want to add it in the original.
-               if info.IsDir() {
-                       return os.MkdirAll(dstPath, perm|0200)
-               }
-
-               // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(srcPath, dstPath); err == nil {
-                       return nil
-               }
-
-               // Otherwise, copy the bytes.
-               src, err := os.Open(srcPath)
-               if err != nil {
-                       return err
-               }
-               defer src.Close()
-
-               dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
-               if err != nil {
-                       return err
-               }
-
-               _, err = io.Copy(dst, src)
-               if closeErr := dst.Close(); err == nil {
-                       err = closeErr
-               }
-               return err
-       })
-}
index f191c50a42744ae3c9f4a3b49bfc02407735c7af..3883422d6f08ac77b8cba6ac01d1fb85e9ab0f32 100644 (file)
@@ -6,6 +6,7 @@ package stdio_test
 
 import (
        "bytes"
+       "cmd/cgo/internal/cgotest"
        "internal/testenv"
        "log"
        "os"
@@ -31,7 +32,7 @@ func testMain(m *testing.M) int {
        // Copy testdata into GOPATH/src/cgostdio, along with a go.mod file
        // declaring the same path.
        modRoot := filepath.Join(GOPATH, "src", "cgostdio")
-       if err := overlayDir(modRoot, "testdata"); err != nil {
+       if err := cgotest.OverlayDir(modRoot, "testdata"); err != nil {
                log.Panic(err)
        }
        if err := os.Chdir(modRoot); err != nil {