// 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"
"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
import (
"bufio"
"bytes"
+ "cmd/cgo/internal/cgotest"
"debug/elf"
"flag"
"fmt"
// 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 {
+++ /dev/null
-// 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
- })
-}
import (
"bufio"
"bytes"
+ "cmd/cgo/internal/cgotest"
"debug/elf"
"debug/pe"
"encoding/binary"
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 {
+++ /dev/null
-// 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
- })
-}
import (
"bytes"
+ "cmd/cgo/internal/cgotest"
"internal/testenv"
"log"
"os"
// 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 {
+++ /dev/null
-// 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
- })
-}
+++ /dev/null
-// 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
- })
-}
import (
"bytes"
+ "cmd/cgo/internal/cgotest"
"context"
"flag"
"fmt"
"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)
+++ /dev/null
-// 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
- })
-}
import (
"bufio"
"bytes"
+ "cmd/cgo/internal/cgotest"
"debug/elf"
"encoding/binary"
"flag"
// 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 {
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
}
}
package so_test
import (
+ "cmd/cgo/internal/cgotest"
"internal/testenv"
"log"
"os"
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 {
+++ /dev/null
-// 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
- })
-}
import (
"bytes"
+ "cmd/cgo/internal/cgotest"
"internal/testenv"
"log"
"os"
// 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 {