Skip to content

Commit ed5da55

Browse files
authored
build: move version-info into checksum file (#28324)
* build: upgrade to golang 1.21.2 * build: verify checksums via tool * deps: upgrade go to 1.21.3 * build: move more build metadata into checksum file * build: move gobootsrc to checksums
1 parent 660cbe4 commit ed5da55

File tree

3 files changed

+106
-38
lines changed

3 files changed

+106
-38
lines changed

build/checksums.txt

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
# This file contains sha256 checksums of optional build dependencies.
22

3+
# version:spec-tests 1.0.2
34
# https://github.com/ethereum/execution-spec-tests/releases
5+
# https://github.com/ethereum/execution-spec-tests/releases/download/v1.0.2/
46
24bac679f3a2d8240d8e08e7f6a70b70c2dabf673317d924cf1d1887b9fe1f81 fixtures.tar.gz
57

8+
# version:golang 1.21.3
69
# https://go.dev/dl/
7-
bfa36bf75e9a1e9cbbdb9abcf9d1707e479bd3a07880a8ae3564caee5711cb99 go1.21.1.src.tar.gz
8-
809f5b0ef4f7dcdd5f51e9630a5b2e5a1006f22a047126d61560cdc365678a19 go1.21.1.darwin-amd64.tar.gz
9-
ffd40391a1e995855488b008ad9326ff8c2e81803a6e80894401003bae47fcf1 go1.21.1.darwin-arm64.tar.gz
10-
9919a9a4dc82371aba3da5b7c830bcb6249fc1502cd26d959eb340a60e41ee01 go1.21.1.freebsd-386.tar.gz
11-
2571f10f6047e04d87c1f5986a05e5e8f7b511faf98803ef12b66d563845d2a1 go1.21.1.freebsd-amd64.tar.gz
12-
b93850666cdadbd696a986cf7b03111fe99db8c34a9aaa113d7c96d0081e1901 go1.21.1.linux-386.tar.gz
13-
b3075ae1ce5dab85f89bc7905d1632de23ca196bd8336afd93fa97434cfa55ae go1.21.1.linux-amd64.tar.gz
14-
7da1a3936a928fd0b2602ed4f3ef535b8cd1990f1503b8d3e1acc0fa0759c967 go1.21.1.linux-arm64.tar.gz
15-
f3716a43f59ae69999841d6007b42c9e286e8d8ce470656fb3e70d7be2d7ca85 go1.21.1.linux-armv6l.tar.gz
16-
eddf018206f8a5589bda75252b72716d26611efebabdca5d0083ec15e9e41ab7 go1.21.1.linux-ppc64le.tar.gz
17-
a83b3e8eb4dbf76294e773055eb51397510ff4d612a247bad9903560267bba6d go1.21.1.linux-s390x.tar.gz
18-
170256c820f466f29d64876f25f4dfa4029ed9902a0a9095d8bd603aecf4d83b go1.21.1.windows-386.zip
19-
10a4f5b63215d11d1770453733dbcbf024f3f74872f84e28d7ea59f0250316c6 go1.21.1.windows-amd64.zip
20-
41135ce6e0ced4bc1e459cb96bd4090c9dc2062e24179c3f337d855af9b560ef go1.21.1.windows-arm64.zip
10+
186f2b6f8c8b704e696821b09ab2041a5c1ee13dcbc3156a13adcf75931ee488 go1.21.3.src.tar.gz
11+
27014fc69e301d7588a169ca239b3cc609f0aa1abf38528bf0d20d3b259211eb go1.21.3.darwin-amd64.tar.gz
12+
65302a7a9f7a4834932b3a7a14cb8be51beddda757b567a2f9e0cbd0d7b5a6ab go1.21.3.darwin-arm64.tar.gz
13+
8e0cd2f66cf1bde9d07b4aee01e3d7c3cfdd14e20650488e1683da4b8492594a go1.21.3.freebsd-386.tar.gz
14+
6e74f65f586e93d1f3947894766f69e9b2ebda488592a09df61f36f06bfe58a8 go1.21.3.freebsd-amd64.tar.gz
15+
fb209fd070db500a84291c5a95251cceeb1723e8f6142de9baca5af70a927c0e go1.21.3.linux-386.tar.gz
16+
1241381b2843fae5a9707eec1f8fb2ef94d827990582c7c7c32f5bdfbfd420c8 go1.21.3.linux-amd64.tar.gz
17+
fc90fa48ae97ba6368eecb914343590bbb61b388089510d0c56c2dde52987ef3 go1.21.3.linux-arm64.tar.gz
18+
a1ddcaaf0821a12a800884c14cb4268ce1c1f5a0301e9060646f1e15e611c6c7 go1.21.3.linux-armv6l.tar.gz
19+
3b0e10a3704f164a6e85e0377728ec5fd21524fabe4c925610e34076586d5826 go1.21.3.linux-ppc64le.tar.gz
20+
4c78e2e6f4c684a3d5a9bdc97202729053f44eb7be188206f0627ef3e18716b6 go1.21.3.linux-s390x.tar.gz
21+
e36737f4f2fadb4d2f919ec4ce517133a56e06064cca6e82fc883bb000c4d56c go1.21.3.windows-386.zip
22+
27c8daf157493f288d42a6f38debc6a2cb391f6543139eba9152fceca0be2a10 go1.21.3.windows-amd64.zip
23+
bfb7a5c56f9ded07d8ae0e0b3702ac07b65e68fa8f33da24ed6df4ce01fe2c5c go1.21.3.windows-arm64.zip
2124

22-
# https://github.com/golangci/golangci-lint/releases
25+
# version:golangci 1.51.1
26+
# https://github.com/golangci/golangci-lint/releases/
27+
# https://github.com/golangci/golangci-lint/releases/download/v1.51.1/
2328
fba08acc4027f69f07cef48fbff70b8a7ecdfaa1c2aba9ad3fb31d60d9f5d4bc golangci-lint-1.51.1-darwin-amd64.tar.gz
2429
75b8f0ff3a4e68147156be4161a49d4576f1be37a0b506473f8c482140c1e7f2 golangci-lint-1.51.1-darwin-arm64.tar.gz
2530
e06b3459aaed356e1667580be00b05f41f3b2e29685d12cdee571c23e1edb414 golangci-lint-1.51.1-freebsd-386.tar.gz
@@ -48,4 +53,12 @@ bce02f7232723cb727755ee11f168a700a00896a25d37f87c4b173bce55596b4 golangci-lint-
4853
cf6403f84707ce8c98664736772271bc8874f2e760c2fd0f00cf3e85963507e9 golangci-lint-1.51.1-windows-armv7.zip
4954

5055
# This is the builder on PPA that will build Go itself (inception-y), don't modify!
56+
#
57+
# This version is fine to be old and full of security holes, we just use it
58+
# to build the latest Go. Don't change it. If it ever becomes insufficient,
59+
# we need to switch over to a recursive builder to jump across supported
60+
# versions.
61+
#
62+
# version:ppa-builder 1.19.6
63+
# https://go.dev/dl/
5164
d7f0013f82e6d7f862cc6cb5c8cdb48eef5f2e239b35baa97e2f1a7466043767 go1.19.6.src.tar.gz

build/ci.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,6 @@ var (
136136
"golang-go": "/usr/lib/go",
137137
}
138138

139-
// This is the version of Go that will be downloaded by
140-
//
141-
// go run ci.go install -dlgo
142-
dlgoVersion = "1.21.1"
143-
144-
// This is the version of Go that will be used to bootstrap the PPA builder.
145-
//
146-
// This version is fine to be old and full of security holes, we just use it
147-
// to build the latest Go. Don't change it. If it ever becomes insufficient,
148-
// we need to switch over to a recursive builder to jumpt across supported
149-
// versions.
150-
gobootVersion = "1.19.6"
151-
152-
// This is the version of execution-spec-tests that we are using.
153-
// When updating, you must also update build/checksums.txt.
154-
executionSpecTestsVersion = "1.0.2"
155-
156139
// This is where the tests should be unpacked.
157140
executionSpecTestsDir = "tests/spec-tests"
158141
)
@@ -192,6 +175,8 @@ func main() {
192175
doWindowsInstaller(os.Args[2:])
193176
case "purge":
194177
doPurge(os.Args[2:])
178+
case "sanitycheck":
179+
doSanityCheck()
195180
default:
196181
log.Fatal("unknown command ", os.Args[1])
197182
}
@@ -213,9 +198,8 @@ func doInstall(cmdline []string) {
213198
tc := build.GoToolchain{GOARCH: *arch, CC: *cc}
214199
if *dlgo {
215200
csdb := build.MustLoadChecksums("build/checksums.txt")
216-
tc.Root = build.DownloadGo(csdb, dlgoVersion)
201+
tc.Root = build.DownloadGo(csdb)
217202
}
218-
219203
// Disable CLI markdown doc generation in release builds.
220204
buildTags := []string{"urfave_cli_no_docs"}
221205

@@ -312,7 +296,7 @@ func doTest(cmdline []string) {
312296
// Configure the toolchain.
313297
tc := build.GoToolchain{GOARCH: *arch, CC: *cc}
314298
if *dlgo {
315-
tc.Root = build.DownloadGo(csdb, dlgoVersion)
299+
tc.Root = build.DownloadGo(csdb)
316300
}
317301
gotest := tc.Go("test")
318302

@@ -345,6 +329,10 @@ func doTest(cmdline []string) {
345329

346330
// downloadSpecTestFixtures downloads and extracts the execution-spec-tests fixtures.
347331
func downloadSpecTestFixtures(csdb *build.ChecksumDB, cachedir string) string {
332+
executionSpecTestsVersion, err := build.Version(csdb, "spec-tests")
333+
if err != nil {
334+
log.Fatal(err)
335+
}
348336
ext := ".tar.gz"
349337
base := "fixtures" // TODO(MariusVanDerWijden) rename once the version becomes part of the filename
350338
url := fmt.Sprintf("https://github.com/ethereum/execution-spec-tests/releases/download/v%s/%s%s", executionSpecTestsVersion, base, ext)
@@ -377,9 +365,11 @@ func doLint(cmdline []string) {
377365

378366
// downloadLinter downloads and unpacks golangci-lint.
379367
func downloadLinter(cachedir string) string {
380-
const version = "1.51.1"
381-
382368
csdb := build.MustLoadChecksums("build/checksums.txt")
369+
version, err := build.Version(csdb, "golangci")
370+
if err != nil {
371+
log.Fatal(err)
372+
}
383373
arch := runtime.GOARCH
384374
ext := ".tar.gz"
385375

@@ -761,6 +751,10 @@ func doDebianSource(cmdline []string) {
761751
// to bootstrap the builder Go.
762752
func downloadGoBootstrapSources(cachedir string) string {
763753
csdb := build.MustLoadChecksums("build/checksums.txt")
754+
gobootVersion, err := build.Version(csdb, "ppa-builder")
755+
if err != nil {
756+
log.Fatal(err)
757+
}
764758
file := fmt.Sprintf("go%s.src.tar.gz", gobootVersion)
765759
url := "https://dl.google.com/go/" + file
766760
dst := filepath.Join(cachedir, file)
@@ -773,6 +767,10 @@ func downloadGoBootstrapSources(cachedir string) string {
773767
// downloadGoSources downloads the Go source tarball.
774768
func downloadGoSources(cachedir string) string {
775769
csdb := build.MustLoadChecksums("build/checksums.txt")
770+
dlgoVersion, err := build.Version(csdb, "golang")
771+
if err != nil {
772+
log.Fatal(err)
773+
}
776774
file := fmt.Sprintf("go%s.src.tar.gz", dlgoVersion)
777775
url := "https://dl.google.com/go/" + file
778776
dst := filepath.Join(cachedir, file)
@@ -1099,3 +1097,7 @@ func doPurge(cmdline []string) {
10991097
log.Fatal(err)
11001098
}
11011099
}
1100+
1101+
func doSanityCheck() {
1102+
build.DownloadAndVerifyChecksums(build.MustLoadChecksums("build/checksums.txt"))
1103+
}

internal/build/gotool.go

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ func (g *GoToolchain) goTool(command string, args ...string) *exec.Cmd {
8484

8585
// DownloadGo downloads the Go binary distribution and unpacks it into a temporary
8686
// directory. It returns the GOROOT of the unpacked toolchain.
87-
func DownloadGo(csdb *ChecksumDB, version string) string {
87+
func DownloadGo(csdb *ChecksumDB) string {
88+
version, err := Version(csdb, "golang")
89+
if err != nil {
90+
log.Fatal(err)
91+
}
8892
// Shortcut: if the Go version that runs this script matches the
8993
// requested version exactly, there is no need to download anything.
9094
activeGo := strings.TrimPrefix(runtime.Version(), "go")
@@ -126,3 +130,52 @@ func DownloadGo(csdb *ChecksumDB, version string) string {
126130
}
127131
return goroot
128132
}
133+
134+
// Version returns the versions defined in the checksumdb.
135+
func Version(csdb *ChecksumDB, version string) (string, error) {
136+
for _, l := range csdb.allChecksums {
137+
if !strings.HasPrefix(l, "# version:") {
138+
continue
139+
}
140+
v := strings.Split(l, ":")[1]
141+
parts := strings.Split(v, " ")
142+
if len(parts) != 2 {
143+
log.Print("Erroneous version-string", "v", l)
144+
continue
145+
}
146+
if parts[0] == version {
147+
log.Printf("Found version %q", parts[1])
148+
return parts[1], nil
149+
}
150+
}
151+
return "", fmt.Errorf("no version found for '%v'", version)
152+
}
153+
154+
// DownloadAndVerifyChecksums downloads all files and checks that they match
155+
// the checksum given in checksums.txt.
156+
// This task can be used to sanity-check new checksums.
157+
func DownloadAndVerifyChecksums(csdb *ChecksumDB) {
158+
var (
159+
base = ""
160+
ucache = os.TempDir()
161+
)
162+
for _, l := range csdb.allChecksums {
163+
if strings.HasPrefix(l, "# https://") {
164+
base = l[2:]
165+
continue
166+
}
167+
if strings.HasPrefix(l, "#") {
168+
continue
169+
}
170+
hashFile := strings.Split(l, " ")
171+
if len(hashFile) != 2 {
172+
continue
173+
}
174+
file := hashFile[1]
175+
url := base + file
176+
dst := filepath.Join(ucache, file)
177+
if err := csdb.DownloadFile(url, dst); err != nil {
178+
log.Print(err)
179+
}
180+
}
181+
}

0 commit comments

Comments
 (0)