Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d88261f

Browse files
committed
time: don't depend on the io package
The time package has never depended on the io package until a recent change during Go 1.7 to use the io.Seek* constants. The go/build dependency check didn't catch this because "time" was allowed to depend on meta package group "L0", which included "io". Adding the "io" package broke one of Dmitry's tools. The tool is fixable, but it's also not necessary for us to depend on "io" at all for some constants. Mirror the constants instead, and change deps_test.go to prevent an io dependency in the future. Change-Id: I74325228565279a74fa4a2f419643f5710e3e09f Reviewed-on: https://go-review.googlesource.com/22960 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 561c948 commit d88261f

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

src/go/build/deps_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,19 @@ var pkgDeps = map[string][]string{
136136
"internal/syscall/unix": {"L0", "syscall"},
137137
"internal/syscall/windows": {"L0", "syscall", "internal/syscall/windows/sysdll"},
138138
"internal/syscall/windows/registry": {"L0", "syscall", "internal/syscall/windows/sysdll", "unicode/utf16"},
139-
"time": {"L0", "syscall", "internal/syscall/windows/registry"},
139+
"time": {
140+
// "L0" without the "io" package:
141+
"errors",
142+
"runtime",
143+
"runtime/internal/atomic",
144+
"sync",
145+
"sync/atomic",
146+
"unsafe",
147+
// Other time dependencies:
148+
"internal/syscall/windows/registry",
149+
"syscall",
150+
},
151+
140152
"os": {"L1", "os", "syscall", "time", "internal/syscall/windows"},
141153
"path/filepath": {"L2", "os", "syscall"},
142154
"io/ioutil": {"L2", "os", "path/filepath", "time"},

src/time/sys_plan9.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package time
88

99
import (
1010
"errors"
11-
"io"
1211
"syscall"
1312
)
1413

@@ -56,9 +55,9 @@ func closefd(fd uintptr) {
5655
}
5756

5857
func preadn(fd uintptr, buf []byte, off int) error {
59-
whence := io.SeekStart
58+
whence := seekStart
6059
if off < 0 {
61-
whence = io.SeekEnd
60+
whence = seekEnd
6261
}
6362
if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil {
6463
return err

src/time/sys_unix.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package time
88

99
import (
1010
"errors"
11-
"io"
1211
"syscall"
1312
)
1413

@@ -56,9 +55,9 @@ func closefd(fd uintptr) {
5655
}
5756

5857
func preadn(fd uintptr, buf []byte, off int) error {
59-
whence := io.SeekStart
58+
whence := seekStart
6059
if off < 0 {
61-
whence = io.SeekEnd
60+
whence = seekEnd
6261
}
6362
if _, err := syscall.Seek(int(fd), int64(off), whence); err != nil {
6463
return err

src/time/sys_windows.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package time
66

77
import (
88
"errors"
9-
"io"
109
"syscall"
1110
)
1211

@@ -53,9 +52,9 @@ func closefd(fd uintptr) {
5352
}
5453

5554
func preadn(fd uintptr, buf []byte, off int) error {
56-
whence := io.SeekStart
55+
whence := seekStart
5756
if off < 0 {
58-
whence = io.SeekEnd
57+
whence = seekEnd
5958
}
6059
if _, err := syscall.Seek(syscall.Handle(fd), int64(off), whence); err != nil {
6160
return err

src/time/zoneinfo_read.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ package time
1111

1212
import "errors"
1313

14+
// Copies of io.Seek* constants to avoid importing "io":
15+
const (
16+
seekStart = 0
17+
seekCurrent = 1
18+
seekEnd = 2
19+
)
20+
1421
// Simple I/O interface to binary blob of data.
1522
type data struct {
1623
p []byte

0 commit comments

Comments
 (0)