diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/misc/cgo/stdio | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.zip gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.bz2 |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/misc/cgo/stdio')
-rw-r--r-- | libgo/misc/cgo/stdio/overlaydir_test.go | 81 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/stdio_test.go | 64 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/chain.go (renamed from libgo/misc/cgo/stdio/chain.go) | 2 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/chain.out (renamed from libgo/misc/cgo/stdio/chain.out) | 0 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/fib.go (renamed from libgo/misc/cgo/stdio/fib.go) | 2 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/fib.out (renamed from libgo/misc/cgo/stdio/fib.out) | 0 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/hello.go (renamed from libgo/misc/cgo/stdio/hello.go) | 2 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/hello.out (renamed from libgo/misc/cgo/stdio/hello.out) | 0 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/run.out (renamed from libgo/misc/cgo/stdio/run.out) | 0 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/stdio/file.go (renamed from libgo/misc/cgo/stdio/file.go) | 0 | ||||
-rw-r--r-- | libgo/misc/cgo/stdio/testdata/stdio/stdio.go (renamed from libgo/misc/cgo/stdio/stdio.go) | 0 |
11 files changed, 148 insertions, 3 deletions
diff --git a/libgo/misc/cgo/stdio/overlaydir_test.go b/libgo/misc/cgo/stdio/overlaydir_test.go new file mode 100644 index 0000000..8a8dcdb --- /dev/null +++ b/libgo/misc/cgo/stdio/overlaydir_test.go @@ -0,0 +1,81 @@ +// 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 + } + + symBase, err := filepath.Rel(srcRoot, dstRoot) + if err != nil { + symBase, 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.Mkdir(dstPath, perm) + } + + // If the OS supports symlinks, use them instead of copying bytes. + if err := os.Symlink(filepath.Join(symBase, suffix), 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/libgo/misc/cgo/stdio/stdio_test.go b/libgo/misc/cgo/stdio/stdio_test.go new file mode 100644 index 0000000..ab5d328 --- /dev/null +++ b/libgo/misc/cgo/stdio/stdio_test.go @@ -0,0 +1,64 @@ +// 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 ( + "bytes" + "io/ioutil" + "log" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" +) + +func TestMain(m *testing.M) { + log.SetFlags(log.Lshortfile) + os.Exit(testMain(m)) +} + +func testMain(m *testing.M) int { + GOPATH, err := ioutil.TempDir("", "cgostdio") + if err != nil { + log.Panic(err) + } + defer os.RemoveAll(GOPATH) + os.Setenv("GOPATH", GOPATH) + + // 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 { + log.Panic(err) + } + if err := os.Chdir(modRoot); err != nil { + log.Panic(err) + } + os.Setenv("PWD", modRoot) + if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil { + log.Panic(err) + } + + return m.Run() +} + +func TestTestRun(t *testing.T) { + if os.Getenv("GOOS") == "android" { + t.Skip("subpackage stdio is not available on android") + } + out, err := exec.Command("go", "env", "GOROOT").Output() + if err != nil { + t.Fatal(err) + } + GOROOT := string(bytes.TrimSpace(out)) + + cmd := exec.Command("go", "run", filepath.Join(GOROOT, "test", "run.go"), "-", ".") + out, err = cmd.CombinedOutput() + if err != nil { + t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out) + } + t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out) +} diff --git a/libgo/misc/cgo/stdio/chain.go b/libgo/misc/cgo/stdio/testdata/chain.go index cdc3852..6c3f406 100644 --- a/libgo/misc/cgo/stdio/chain.go +++ b/libgo/misc/cgo/stdio/testdata/chain.go @@ -14,7 +14,7 @@ import ( "runtime" "strconv" - "../stdio" + "cgostdio/stdio" ) const N = 10 diff --git a/libgo/misc/cgo/stdio/chain.out b/libgo/misc/cgo/stdio/testdata/chain.out index 963cf9b..963cf9b 100644 --- a/libgo/misc/cgo/stdio/chain.out +++ b/libgo/misc/cgo/stdio/testdata/chain.out diff --git a/libgo/misc/cgo/stdio/fib.go b/libgo/misc/cgo/stdio/testdata/fib.go index 58f185c..49cb0ea 100644 --- a/libgo/misc/cgo/stdio/fib.go +++ b/libgo/misc/cgo/stdio/testdata/fib.go @@ -17,7 +17,7 @@ import ( "runtime" "strconv" - "../stdio" + "cgostdio/stdio" ) func fibber(c, out chan int64, i int64) { diff --git a/libgo/misc/cgo/stdio/fib.out b/libgo/misc/cgo/stdio/testdata/fib.out index 17ff503..17ff503 100644 --- a/libgo/misc/cgo/stdio/fib.out +++ b/libgo/misc/cgo/stdio/testdata/fib.out diff --git a/libgo/misc/cgo/stdio/hello.go b/libgo/misc/cgo/stdio/testdata/hello.go index 56220d3..046bfee 100644 --- a/libgo/misc/cgo/stdio/hello.go +++ b/libgo/misc/cgo/stdio/testdata/hello.go @@ -8,7 +8,7 @@ package main -import "../stdio" +import "cgostdio/stdio" func main() { stdio.Stdout.WriteString(stdio.Greeting + "\n") diff --git a/libgo/misc/cgo/stdio/hello.out b/libgo/misc/cgo/stdio/testdata/hello.out index 4b5fa63..4b5fa63 100644 --- a/libgo/misc/cgo/stdio/hello.out +++ b/libgo/misc/cgo/stdio/testdata/hello.out diff --git a/libgo/misc/cgo/stdio/run.out b/libgo/misc/cgo/stdio/testdata/run.out index c0e4965..c0e4965 100644 --- a/libgo/misc/cgo/stdio/run.out +++ b/libgo/misc/cgo/stdio/testdata/run.out diff --git a/libgo/misc/cgo/stdio/file.go b/libgo/misc/cgo/stdio/testdata/stdio/file.go index a024f2c..a024f2c 100644 --- a/libgo/misc/cgo/stdio/file.go +++ b/libgo/misc/cgo/stdio/testdata/stdio/file.go diff --git a/libgo/misc/cgo/stdio/stdio.go b/libgo/misc/cgo/stdio/testdata/stdio/stdio.go index d216e44..d216e44 100644 --- a/libgo/misc/cgo/stdio/stdio.go +++ b/libgo/misc/cgo/stdio/testdata/stdio/stdio.go |