Skip to content

Commit b39daa7

Browse files
committed
os,time: fix tests on iOS
When fixing tests for for self-hosted iOS builds, I broke hosted builds. Updates #31722 Change-Id: Id4e7d234fbd86cb2d29d320d75f4441efd663d12 Reviewed-on: https://go-review.googlesource.com/c/go/+/174698 Run-TryBot: Elias Naur <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 7ee2213 commit b39daa7

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/os/os_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ func TestChdirAndGetwd(t *testing.T) {
12041204
case "darwin":
12051205
switch runtime.GOARCH {
12061206
case "arm", "arm64":
1207+
dirs = nil
12071208
for _, d := range []string{"d1", "d2"} {
12081209
dir, err := ioutil.TempDir("", d)
12091210
if err != nil {

src/time/zoneinfo_ios.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,31 @@ import (
1313
)
1414

1515
var zoneSources = []string{
16-
getZipParent() + "/zoneinfo.zip",
17-
runtime.GOROOT() + "/lib/time/zoneinfo.zip",
16+
getZoneRoot() + "/zoneinfo.zip",
1817
}
1918

20-
func getZipParent() string {
21-
wd, err := syscall.Getwd()
22-
if err != nil {
23-
return "/XXXNOEXIST"
24-
}
25-
19+
func getZoneRoot() string {
2620
// The working directory at initialization is the root of the
2721
// app bundle: "/private/.../bundlename.app". That's where we
28-
// keep zoneinfo.zip.
29-
return wd
22+
// keep zoneinfo.zip for tethered iOS builds.
23+
// For self-hosted iOS builds, the zoneinfo.zip is in GOROOT.
24+
roots := []string{runtime.GOROOT() + "/lib/time"}
25+
wd, err := syscall.Getwd()
26+
if err == nil {
27+
roots = append(roots, wd)
28+
}
29+
for _, r := range roots {
30+
var st syscall.Stat_t
31+
fd, err := syscall.Open(r, syscall.O_RDONLY, 0)
32+
if err != nil {
33+
continue
34+
}
35+
defer syscall.Close(fd)
36+
if err := syscall.Fstat(fd, &st); err == nil {
37+
return r
38+
}
39+
}
40+
return "/XXXNOEXIST"
3041
}
3142

3243
func initLocal() {

0 commit comments

Comments
 (0)