Skip to content

Commit 627765a

Browse files
rscgopherbot
authored andcommitted
time/tzdata: generate zip constant during cmd/dist
We have a make.bash-time generation capability, so use it to generate the embedded zip file for time/tzdata. This is one less file to try to review in CLs like CL 455356. For #22487. Fixes #43350. Change-Id: I2fcd0665fa0b1c830baec5fb4cd714483fea25a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/455357 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 6bb003d commit 627765a

File tree

7 files changed

+27
-6725
lines changed

7 files changed

+27
-6725
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ _testmain.go
4040
/src/internal/buildcfg/zbootstrap.go
4141
/src/runtime/internal/sys/zversion.go
4242
/src/unicode/maketables
43+
/src/time/tzdata/zzipdata.go
4344
/test.out
4445
/test/garbage/*.out
4546
/test/pass.out

lib/time/update.bash

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ fi
4848
cd zoneinfo
4949
../mkzip ../../zoneinfo.zip
5050
cd ../..
51-
go generate time/tzdata
5251

53-
files="update.bash zoneinfo.zip ../../src/time/tzdata/zipdata.go"
52+
files="update.bash zoneinfo.zip"
5453
modified=true
5554
if git diff --quiet $files; then
5655
modified=false

src/cmd/dist/build.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ var deptab = []struct {
558558
{"go/build", []string{
559559
"zcgo.go",
560560
}},
561+
{"time/tzdata", []string{
562+
"zzipdata.go",
563+
}},
561564
}
562565

563566
// depsuffix records the allowed suffixes for source files.
@@ -575,6 +578,7 @@ var gentab = []struct {
575578
{"zosarch.go", mkzosarch},
576579
{"zversion.go", mkzversion},
577580
{"zcgo.go", mkzcgo},
581+
{"zzipdata.go", mktzdata},
578582

579583
// not generated anymore, but delete the file if we see it
580584
{"enam.c", nil},
@@ -1346,7 +1350,8 @@ func cmdbootstrap() {
13461350

13471351
timelog("build", "go_bootstrap")
13481352
xprintf("Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.\n")
1349-
install("runtime") // dependency not visible in sources; also sets up textflag.h
1353+
install("runtime") // dependency not visible in sources; also sets up textflag.h
1354+
install("time/tzdata") // no dependency in sources; creates generated file
13501355
install("cmd/go")
13511356
if vflag > 0 {
13521357
xprintf("\n")

src/cmd/dist/buildgo.go

+17
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,20 @@ func mkzcgo(dir, file string) {
124124

125125
writefile(buf.String(), file, writeSkipSame)
126126
}
127+
128+
// mktzdata src/time/tzdata/zzipdata.go:
129+
//
130+
// package tzdata
131+
// const zipdata = "PK..."
132+
func mktzdata(dir, file string) {
133+
zip := readfile(filepath.Join(dir, "../../../lib/time/zoneinfo.zip"))
134+
135+
var buf strings.Builder
136+
fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
137+
fmt.Fprintln(&buf)
138+
fmt.Fprintf(&buf, "package tzdata\n")
139+
fmt.Fprintln(&buf)
140+
fmt.Fprintf(&buf, "const zipdata = %q\n", zip)
141+
142+
writefile(buf.String(), file, writeSkipSame)
143+
}

src/time/tzdata/generate_zipdata.go

-77
This file was deleted.

src/time/tzdata/tzdata.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:generate go run generate_zipdata.go
6-
75
// Package tzdata provides an embedded copy of the timezone database.
86
// If this package is imported anywhere in the program, then if
97
// the time package cannot find tzdata files on the system,
@@ -67,6 +65,8 @@ func loadFromEmbeddedTZData(name string) (string, error) {
6765
zheader = 0x04034b50
6866
)
6967

68+
// zipdata is provided by zzipdata.go,
69+
// which is generated by cmd/dist during make.bash.
7070
z := zipdata
7171

7272
idx := len(z) - ztailsize

0 commit comments

Comments
 (0)