@@ -208,58 +208,25 @@ func doInstall(cmdline []string) {
208
208
cc = flag .String ("cc" , "" , "C compiler to cross build with" )
209
209
)
210
210
flag .CommandLine .Parse (cmdline )
211
- env := build .Env ()
212
211
213
- // Check local Go version. People regularly open issues about compilation
214
- // failure with outdated Go. This should save them the trouble.
215
- if ! strings .Contains (runtime .Version (), "devel" ) {
216
- // Figure out the minor version number since we can't textually compare (1.10 < 1.9)
217
- var minor int
218
- fmt .Sscanf (strings .TrimPrefix (runtime .Version (), "go1." ), "%d" , & minor )
219
- if minor < 13 {
220
- log .Println ("You have Go version" , runtime .Version ())
221
- log .Println ("go-ethereum requires at least Go version 1.13 and cannot" )
222
- log .Println ("be compiled with an earlier version. Please upgrade your Go installation." )
223
- os .Exit (1 )
224
- }
225
- }
226
-
227
- // Choose which go command we're going to use.
228
- var gobuild * exec.Cmd
229
- if ! * dlgo {
230
- // Default behavior: use the go version which runs ci.go right now.
231
- gobuild = goTool ("build" )
232
- } else {
233
- // Download of Go requested. This is for build environments where the
234
- // installed version is too old and cannot be upgraded easily.
235
- cachedir := filepath .Join ("build" , "cache" )
236
- goroot := downloadGo (runtime .GOARCH , runtime .GOOS , cachedir )
237
- gobuild = localGoTool (goroot , "build" )
212
+ // Configure the toolchain.
213
+ tc := build.GoToolchain {GOARCH : * arch , CC : * cc }
214
+ if * dlgo {
215
+ csdb := build .MustLoadChecksums ("build/checksums.txt" )
216
+ tc .Root = build .DownloadGo (csdb , dlgoVersion )
238
217
}
239
218
240
- // Configure environment for cross build.
241
- if * arch != "" || * arch != runtime .GOARCH {
242
- gobuild .Env = append (gobuild .Env , "CGO_ENABLED=1" )
243
- gobuild .Env = append (gobuild .Env , "GOARCH=" + * arch )
244
- }
245
-
246
- // Configure C compiler.
247
- if * cc != "" {
248
- gobuild .Env = append (gobuild .Env , "CC=" + * cc )
249
- } else if os .Getenv ("CC" ) != "" {
250
- gobuild .Env = append (gobuild .Env , "CC=" + os .Getenv ("CC" ))
251
- }
219
+ // Configure the build.
220
+ env := build .Env ()
221
+ gobuild := tc .Go ("build" , buildFlags (env )... )
252
222
253
223
// arm64 CI builders are memory-constrained and can't handle concurrent builds,
254
224
// better disable it. This check isn't the best, it should probably
255
225
// check for something in env instead.
256
- if runtime .GOARCH == "arm64" {
226
+ if env . CI && runtime .GOARCH == "arm64" {
257
227
gobuild .Args = append (gobuild .Args , "-p" , "1" )
258
228
}
259
229
260
- // Put the default settings in.
261
- gobuild .Args = append (gobuild .Args , buildFlags (env )... )
262
-
263
230
// We use -trimpath to avoid leaking local paths into the built executables.
264
231
gobuild .Args = append (gobuild .Args , "-trimpath" )
265
232
@@ -301,53 +268,30 @@ func buildFlags(env build.Environment) (flags []string) {
301
268
return flags
302
269
}
303
270
304
- // goTool returns the go tool. This uses the Go version which runs ci.go.
305
- func goTool (subcmd string , args ... string ) * exec.Cmd {
306
- cmd := build .GoTool (subcmd , args ... )
307
- goToolSetEnv (cmd )
308
- return cmd
309
- }
310
-
311
- // localGoTool returns the go tool from the given GOROOT.
312
- func localGoTool (goroot string , subcmd string , args ... string ) * exec.Cmd {
313
- gotool := filepath .Join (goroot , "bin" , "go" )
314
- cmd := exec .Command (gotool , subcmd )
315
- goToolSetEnv (cmd )
316
- cmd .Env = append (cmd .Env , "GOROOT=" + goroot )
317
- cmd .Args = append (cmd .Args , args ... )
318
- return cmd
319
- }
320
-
321
- // goToolSetEnv forwards the build environment to the go tool.
322
- func goToolSetEnv (cmd * exec.Cmd ) {
323
- cmd .Env = append (cmd .Env , "GOBIN=" + GOBIN )
324
- for _ , e := range os .Environ () {
325
- if strings .HasPrefix (e , "GOBIN=" ) || strings .HasPrefix (e , "CC=" ) {
326
- continue
327
- }
328
- cmd .Env = append (cmd .Env , e )
329
- }
330
- }
331
-
332
271
// Running The Tests
333
272
//
334
273
// "tests" also includes static analysis tools such as vet.
335
274
336
275
func doTest (cmdline []string ) {
337
- coverage := flag .Bool ("coverage" , false , "Whether to record code coverage" )
338
- verbose := flag .Bool ("v" , false , "Whether to log verbosely" )
276
+ var (
277
+ dlgo = flag .Bool ("dlgo" , false , "Download Go and build with it" )
278
+ arch = flag .String ("arch" , "" , "Run tests for given architecture" )
279
+ cc = flag .String ("cc" , "" , "Sets C compiler binary" )
280
+ coverage = flag .Bool ("coverage" , false , "Whether to record code coverage" )
281
+ verbose = flag .Bool ("v" , false , "Whether to log verbosely" )
282
+ )
339
283
flag .CommandLine .Parse (cmdline )
340
- env := build .Env ()
341
284
342
- packages := []string {"./..." }
343
- if len (flag .CommandLine .Args ()) > 0 {
344
- packages = flag .CommandLine .Args ()
285
+ // Configure the toolchain.
286
+ tc := build.GoToolchain {GOARCH : * arch , CC : * cc }
287
+ if * dlgo {
288
+ csdb := build .MustLoadChecksums ("build/checksums.txt" )
289
+ tc .Root = build .DownloadGo (csdb , dlgoVersion )
345
290
}
291
+ gotest := tc .Go ("test" )
346
292
347
- // Run the actual tests.
348
293
// Test a single package at a time. CI builders are slow
349
294
// and some tests run into timeouts under load.
350
- gotest := goTool ("test" , buildFlags (env )... )
351
295
gotest .Args = append (gotest .Args , "-p" , "1" )
352
296
if * coverage {
353
297
gotest .Args = append (gotest .Args , "-covermode=atomic" , "-cover" )
@@ -356,6 +300,10 @@ func doTest(cmdline []string) {
356
300
gotest .Args = append (gotest .Args , "-v" )
357
301
}
358
302
303
+ packages := []string {"./..." }
304
+ if len (flag .CommandLine .Args ()) > 0 {
305
+ packages = flag .CommandLine .Args ()
306
+ }
359
307
gotest .Args = append (gotest .Args , packages ... )
360
308
build .MustRun (gotest )
361
309
}
@@ -415,8 +363,7 @@ func doArchive(cmdline []string) {
415
363
}
416
364
417
365
var (
418
- env = build .Env ()
419
-
366
+ env = build .Env ()
420
367
basegeth = archiveBasename (* arch , params .ArchiveVersion (env .Commit ))
421
368
geth = "geth-" + basegeth + ext
422
369
alltools = "geth-alltools-" + basegeth + ext
@@ -492,15 +439,15 @@ func archiveUpload(archive string, blobstore string, signer string, signifyVar s
492
439
// skips archiving for some build configurations.
493
440
func maybeSkipArchive (env build.Environment ) {
494
441
if env .IsPullRequest {
495
- log .Printf ("skipping because this is a PR build" )
442
+ log .Printf ("skipping archive creation because this is a PR build" )
496
443
os .Exit (0 )
497
444
}
498
445
if env .IsCronJob {
499
- log .Printf ("skipping because this is a cron job" )
446
+ log .Printf ("skipping archive creation because this is a cron job" )
500
447
os .Exit (0 )
501
448
}
502
449
if env .Branch != "master" && ! strings .HasPrefix (env .Tag , "v1." ) {
503
- log .Printf ("skipping because branch %q, tag %q is not on the whitelist" , env .Branch , env .Tag )
450
+ log .Printf ("skipping archive creation because branch %q, tag %q is not on the whitelist" , env .Branch , env .Tag )
504
451
os .Exit (0 )
505
452
}
506
453
}
@@ -518,6 +465,7 @@ func doDebianSource(cmdline []string) {
518
465
flag .CommandLine .Parse (cmdline )
519
466
* workdir = makeWorkdir (* workdir )
520
467
env := build .Env ()
468
+ tc := new (build.GoToolchain )
521
469
maybeSkipArchive (env )
522
470
523
471
// Import the signing key.
@@ -531,12 +479,12 @@ func doDebianSource(cmdline []string) {
531
479
gobundle := downloadGoSources (* cachedir )
532
480
533
481
// Download all the dependencies needed to build the sources and run the ci script
534
- srcdepfetch := goTool ("mod" , "download" )
535
- srcdepfetch .Env = append (os . Environ () , "GOPATH=" + filepath .Join (* workdir , "modgopath" ))
482
+ srcdepfetch := tc . Go ("mod" , "download" )
483
+ srcdepfetch .Env = append (srcdepfetch . Env , "GOPATH=" + filepath .Join (* workdir , "modgopath" ))
536
484
build .MustRun (srcdepfetch )
537
485
538
- cidepfetch := goTool ("run" , "./build/ci.go" )
539
- cidepfetch .Env = append (os . Environ () , "GOPATH=" + filepath .Join (* workdir , "modgopath" ))
486
+ cidepfetch := tc . Go ("run" , "./build/ci.go" )
487
+ cidepfetch .Env = append (cidepfetch . Env , "GOPATH=" + filepath .Join (* workdir , "modgopath" ))
540
488
cidepfetch .Run () // Command fails, don't care, we only need the deps to start it
541
489
542
490
// Create Debian packages and upload them.
@@ -592,41 +540,6 @@ func downloadGoSources(cachedir string) string {
592
540
return dst
593
541
}
594
542
595
- // downloadGo downloads the Go binary distribution and unpacks it into a temporary
596
- // directory. It returns the GOROOT of the unpacked toolchain.
597
- func downloadGo (goarch , goos , cachedir string ) string {
598
- if goarch == "arm" {
599
- goarch = "armv6l"
600
- }
601
-
602
- csdb := build .MustLoadChecksums ("build/checksums.txt" )
603
- file := fmt .Sprintf ("go%s.%s-%s" , dlgoVersion , goos , goarch )
604
- if goos == "windows" {
605
- file += ".zip"
606
- } else {
607
- file += ".tar.gz"
608
- }
609
- url := "https://golang.org/dl/" + file
610
- dst := filepath .Join (cachedir , file )
611
- if err := csdb .DownloadFile (url , dst ); err != nil {
612
- log .Fatal (err )
613
- }
614
-
615
- ucache , err := os .UserCacheDir ()
616
- if err != nil {
617
- log .Fatal (err )
618
- }
619
- godir := filepath .Join (ucache , fmt .Sprintf ("geth-go-%s-%s-%s" , dlgoVersion , goos , goarch ))
620
- if err := build .ExtractArchive (dst , godir ); err != nil {
621
- log .Fatal (err )
622
- }
623
- goroot , err := filepath .Abs (filepath .Join (godir , "go" ))
624
- if err != nil {
625
- log .Fatal (err )
626
- }
627
- return goroot
628
- }
629
-
630
543
func ppaUpload (workdir , ppa , sshUser string , files []string ) {
631
544
p := strings .Split (ppa , "/" )
632
545
if len (p ) != 2 {
@@ -901,13 +814,23 @@ func doAndroidArchive(cmdline []string) {
901
814
)
902
815
flag .CommandLine .Parse (cmdline )
903
816
env := build .Env ()
817
+ tc := new (build.GoToolchain )
904
818
905
819
// Sanity check that the SDK and NDK are installed and set
906
820
if os .Getenv ("ANDROID_HOME" ) == "" {
907
821
log .Fatal ("Please ensure ANDROID_HOME points to your Android SDK" )
908
822
}
823
+
824
+ // Build gomobile.
825
+ install := tc .Install (GOBIN , "golang.org/x/mobile/cmd/gomobile@latest" , "golang.org/x/mobile/cmd/gobind@latest" )
826
+ install .Env = append (install .Env )
827
+ build .MustRun (install )
828
+
829
+ // Ensure all dependencies are available. This is required to make
830
+ // gomobile bind work because it expects go.sum to contain all checksums.
831
+ build .MustRun (tc .Go ("mod" , "download" ))
832
+
909
833
// Build the Android archive and Maven resources
910
- build .MustRun (goTool ("get" , "golang.org/x/mobile/cmd/gomobile" , "golang.org/x/mobile/cmd/gobind" ))
911
834
build .MustRun (gomobileTool ("bind" , "-ldflags" , "-s -w" , "--target" , "android" , "--javapkg" , "org.ethereum" , "-v" , "github.com/ethereum/go-ethereum/mobile" ))
912
835
913
836
if * local {
@@ -1027,10 +950,16 @@ func doXCodeFramework(cmdline []string) {
1027
950
)
1028
951
flag .CommandLine .Parse (cmdline )
1029
952
env := build .Env ()
953
+ tc := new (build.GoToolchain )
954
+
955
+ // Build gomobile.
956
+ build .MustRun (tc .Install (GOBIN , "golang.org/x/mobile/cmd/gomobile@latest" , "golang.org/x/mobile/cmd/gobind@latest" ))
957
+
958
+ // Ensure all dependencies are available. This is required to make
959
+ // gomobile bind work because it expects go.sum to contain all checksums.
960
+ build .MustRun (tc .Go ("mod" , "download" ))
1030
961
1031
962
// Build the iOS XCode framework
1032
- build .MustRun (goTool ("get" , "golang.org/x/mobile/cmd/gomobile" , "golang.org/x/mobile/cmd/gobind" ))
1033
- build .MustRun (gomobileTool ("init" ))
1034
963
bind := gomobileTool ("bind" , "-ldflags" , "-s -w" , "--target" , "ios" , "-v" , "github.com/ethereum/go-ethereum/mobile" )
1035
964
1036
965
if * local {
@@ -1039,17 +968,14 @@ func doXCodeFramework(cmdline []string) {
1039
968
build .MustRun (bind )
1040
969
return
1041
970
}
971
+
972
+ // Create the archive.
973
+ maybeSkipArchive (env )
1042
974
archive := "geth-" + archiveBasename ("ios" , params .ArchiveVersion (env .Commit ))
1043
- if err := os .Mkdir (archive , os .ModePerm ); err != nil {
1044
- log .Fatal (err )
1045
- }
1046
975
bind .Dir , _ = filepath .Abs (archive )
1047
976
build .MustRun (bind )
1048
977
build .MustRunCommand ("tar" , "-zcvf" , archive + ".tar.gz" , archive )
1049
978
1050
- // Skip CocoaPods deploy and Azure upload for PR builds
1051
- maybeSkipArchive (env )
1052
-
1053
979
// Sign and upload the framework to Azure
1054
980
if err := archiveUpload (archive + ".tar.gz" , * upload , * signer , * signify ); err != nil {
1055
981
log .Fatal (err )
@@ -1115,10 +1041,10 @@ func doXgo(cmdline []string) {
1115
1041
)
1116
1042
flag .CommandLine .Parse (cmdline )
1117
1043
env := build .Env ()
1044
+ var tc build.GoToolchain
1118
1045
1119
1046
// Make sure xgo is available for cross compilation
1120
- gogetxgo := goTool ("get" , "github.com/karalabe/xgo" )
1121
- build .MustRun (gogetxgo )
1047
+ build .MustRun (tc .Install (GOBIN , "github.com/karalabe/xgo@latest" ))
1122
1048
1123
1049
// If all tools building is requested, build everything the builder wants
1124
1050
args := append (buildFlags (env ), flag .Args ()... )
@@ -1129,27 +1055,23 @@ func doXgo(cmdline []string) {
1129
1055
if strings .HasPrefix (res , GOBIN ) {
1130
1056
// Binary tool found, cross build it explicitly
1131
1057
args = append (args , "./" + filepath .Join ("cmd" , filepath .Base (res )))
1132
- xgo := xgoTool (args )
1133
- build .MustRun (xgo )
1058
+ build .MustRun (xgoTool (args ))
1134
1059
args = args [:len (args )- 1 ]
1135
1060
}
1136
1061
}
1137
1062
return
1138
1063
}
1139
- // Otherwise xxecute the explicit cross compilation
1064
+
1065
+ // Otherwise execute the explicit cross compilation
1140
1066
path := args [len (args )- 1 ]
1141
1067
args = append (args [:len (args )- 1 ], []string {"--dest" , GOBIN , path }... )
1142
-
1143
- xgo := xgoTool (args )
1144
- build .MustRun (xgo )
1068
+ build .MustRun (xgoTool (args ))
1145
1069
}
1146
1070
1147
1071
func xgoTool (args []string ) * exec.Cmd {
1148
1072
cmd := exec .Command (filepath .Join (GOBIN , "xgo" ), args ... )
1149
1073
cmd .Env = os .Environ ()
1150
- cmd .Env = append (cmd .Env , []string {
1151
- "GOBIN=" + GOBIN ,
1152
- }... )
1074
+ cmd .Env = append (cmd .Env , []string {"GOBIN=" + GOBIN }... )
1153
1075
return cmd
1154
1076
}
1155
1077
0 commit comments