Skip to content

Commit

Permalink
time/tzdata: generate zip constant during cmd/dist
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Heschi Kreinick <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Auto-Submit: Russ Cox <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
rsc authored and gopherbot committed Jan 17, 2023
1 parent 6bb003d commit 627765a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6,725 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ _testmain.go
/src/internal/buildcfg/zbootstrap.go
/src/runtime/internal/sys/zversion.go
/src/unicode/maketables
/src/time/tzdata/zzipdata.go
/test.out
/test/garbage/*.out
/test/pass.out
Expand Down
3 changes: 1 addition & 2 deletions lib/time/update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ fi
cd zoneinfo
../mkzip ../../zoneinfo.zip
cd ../..
go generate time/tzdata

files="update.bash zoneinfo.zip ../../src/time/tzdata/zipdata.go"
files="update.bash zoneinfo.zip"
modified=true
if git diff --quiet $files; then
modified=false
Expand Down
7 changes: 6 additions & 1 deletion src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ var deptab = []struct {
{"go/build", []string{
"zcgo.go",
}},
{"time/tzdata", []string{
"zzipdata.go",
}},
}

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

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

timelog("build", "go_bootstrap")
xprintf("Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.\n")
install("runtime") // dependency not visible in sources; also sets up textflag.h
install("runtime") // dependency not visible in sources; also sets up textflag.h
install("time/tzdata") // no dependency in sources; creates generated file
install("cmd/go")
if vflag > 0 {
xprintf("\n")
Expand Down
17 changes: 17 additions & 0 deletions src/cmd/dist/buildgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,20 @@ func mkzcgo(dir, file string) {

writefile(buf.String(), file, writeSkipSame)
}

// mktzdata src/time/tzdata/zzipdata.go:
//
// package tzdata
// const zipdata = "PK..."
func mktzdata(dir, file string) {
zip := readfile(filepath.Join(dir, "../../../lib/time/zoneinfo.zip"))

var buf strings.Builder
fmt.Fprintf(&buf, "// Code generated by go tool dist; DO NOT EDIT.\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "package tzdata\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "const zipdata = %q\n", zip)

writefile(buf.String(), file, writeSkipSame)
}
77 changes: 0 additions & 77 deletions src/time/tzdata/generate_zipdata.go

This file was deleted.

4 changes: 2 additions & 2 deletions src/time/tzdata/tzdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:generate go run generate_zipdata.go

// Package tzdata provides an embedded copy of the timezone database.
// If this package is imported anywhere in the program, then if
// the time package cannot find tzdata files on the system,
Expand Down Expand Up @@ -67,6 +65,8 @@ func loadFromEmbeddedTZData(name string) (string, error) {
zheader = 0x04034b50
)

// zipdata is provided by zzipdata.go,
// which is generated by cmd/dist during make.bash.
z := zipdata

idx := len(z) - ztailsize
Expand Down
Loading

0 comments on commit 627765a

Please sign in to comment.