@@ -208,58 +208,25 @@ func doInstall(cmdline []string) {
208208 cc = flag .String ("cc" , "" , "C compiler to cross build with" )
209209 )
210210 flag .CommandLine .Parse (cmdline )
211- env := build .Env ()
212211
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 )
238217 }
239218
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 )... )
252222
253223 // arm64 CI builders are memory-constrained and can't handle concurrent builds,
254224 // better disable it. This check isn't the best, it should probably
255225 // check for something in env instead.
256- if runtime .GOARCH == "arm64" {
226+ if env . CI && runtime .GOARCH == "arm64" {
257227 gobuild .Args = append (gobuild .Args , "-p" , "1" )
258228 }
259229
260- // Put the default settings in.
261- gobuild .Args = append (gobuild .Args , buildFlags (env )... )
262-
263230 // We use -trimpath to avoid leaking local paths into the built executables.
264231 gobuild .Args = append (gobuild .Args , "-trimpath" )
265232
@@ -301,53 +268,30 @@ func buildFlags(env build.Environment) (flags []string) {
301268 return flags
302269}
303270
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-
332271// Running The Tests
333272//
334273// "tests" also includes static analysis tools such as vet.
335274
336275func 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+ )
339283 flag .CommandLine .Parse (cmdline )
340- env := build .Env ()
341284
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 )
345290 }
291+ gotest := tc .Go ("test" )
346292
347- // Run the actual tests.
348293 // Test a single package at a time. CI builders are slow
349294 // and some tests run into timeouts under load.
350- gotest := goTool ("test" , buildFlags (env )... )
351295 gotest .Args = append (gotest .Args , "-p" , "1" )
352296 if * coverage {
353297 gotest .Args = append (gotest .Args , "-covermode=atomic" , "-cover" )
@@ -356,6 +300,10 @@ func doTest(cmdline []string) {
356300 gotest .Args = append (gotest .Args , "-v" )
357301 }
358302
303+ packages := []string {"./..." }
304+ if len (flag .CommandLine .Args ()) > 0 {
305+ packages = flag .CommandLine .Args ()
306+ }
359307 gotest .Args = append (gotest .Args , packages ... )
360308 build .MustRun (gotest )
361309}
@@ -415,8 +363,7 @@ func doArchive(cmdline []string) {
415363 }
416364
417365 var (
418- env = build .Env ()
419-
366+ env = build .Env ()
420367 basegeth = archiveBasename (* arch , params .ArchiveVersion (env .Commit ))
421368 geth = "geth-" + basegeth + ext
422369 alltools = "geth-alltools-" + basegeth + ext
@@ -492,15 +439,15 @@ func archiveUpload(archive string, blobstore string, signer string, signifyVar s
492439// skips archiving for some build configurations.
493440func maybeSkipArchive (env build.Environment ) {
494441 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" )
496443 os .Exit (0 )
497444 }
498445 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" )
500447 os .Exit (0 )
501448 }
502449 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 )
504451 os .Exit (0 )
505452 }
506453}
@@ -518,6 +465,7 @@ func doDebianSource(cmdline []string) {
518465 flag .CommandLine .Parse (cmdline )
519466 * workdir = makeWorkdir (* workdir )
520467 env := build .Env ()
468+ tc := new (build.GoToolchain )
521469 maybeSkipArchive (env )
522470
523471 // Import the signing key.
@@ -531,12 +479,12 @@ func doDebianSource(cmdline []string) {
531479 gobundle := downloadGoSources (* cachedir )
532480
533481 // 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" ))
536484 build .MustRun (srcdepfetch )
537485
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" ))
540488 cidepfetch .Run () // Command fails, don't care, we only need the deps to start it
541489
542490 // Create Debian packages and upload them.
@@ -592,41 +540,6 @@ func downloadGoSources(cachedir string) string {
592540 return dst
593541}
594542
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-
630543func ppaUpload (workdir , ppa , sshUser string , files []string ) {
631544 p := strings .Split (ppa , "/" )
632545 if len (p ) != 2 {
@@ -901,13 +814,23 @@ func doAndroidArchive(cmdline []string) {
901814 )
902815 flag .CommandLine .Parse (cmdline )
903816 env := build .Env ()
817+ tc := new (build.GoToolchain )
904818
905819 // Sanity check that the SDK and NDK are installed and set
906820 if os .Getenv ("ANDROID_HOME" ) == "" {
907821 log .Fatal ("Please ensure ANDROID_HOME points to your Android SDK" )
908822 }
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+
909833 // Build the Android archive and Maven resources
910- build .MustRun (goTool ("get" , "golang.org/x/mobile/cmd/gomobile" , "golang.org/x/mobile/cmd/gobind" ))
911834 build .MustRun (gomobileTool ("bind" , "-ldflags" , "-s -w" , "--target" , "android" , "--javapkg" , "org.ethereum" , "-v" , "github.com/ethereum/go-ethereum/mobile" ))
912835
913836 if * local {
@@ -1027,10 +950,16 @@ func doXCodeFramework(cmdline []string) {
1027950 )
1028951 flag .CommandLine .Parse (cmdline )
1029952 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" ))
1030961
1031962 // 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" ))
1034963 bind := gomobileTool ("bind" , "-ldflags" , "-s -w" , "--target" , "ios" , "-v" , "github.com/ethereum/go-ethereum/mobile" )
1035964
1036965 if * local {
@@ -1039,17 +968,14 @@ func doXCodeFramework(cmdline []string) {
1039968 build .MustRun (bind )
1040969 return
1041970 }
971+
972+ // Create the archive.
973+ maybeSkipArchive (env )
1042974 archive := "geth-" + archiveBasename ("ios" , params .ArchiveVersion (env .Commit ))
1043- if err := os .Mkdir (archive , os .ModePerm ); err != nil {
1044- log .Fatal (err )
1045- }
1046975 bind .Dir , _ = filepath .Abs (archive )
1047976 build .MustRun (bind )
1048977 build .MustRunCommand ("tar" , "-zcvf" , archive + ".tar.gz" , archive )
1049978
1050- // Skip CocoaPods deploy and Azure upload for PR builds
1051- maybeSkipArchive (env )
1052-
1053979 // Sign and upload the framework to Azure
1054980 if err := archiveUpload (archive + ".tar.gz" , * upload , * signer , * signify ); err != nil {
1055981 log .Fatal (err )
@@ -1115,10 +1041,10 @@ func doXgo(cmdline []string) {
11151041 )
11161042 flag .CommandLine .Parse (cmdline )
11171043 env := build .Env ()
1044+ var tc build.GoToolchain
11181045
11191046 // 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" ))
11221048
11231049 // If all tools building is requested, build everything the builder wants
11241050 args := append (buildFlags (env ), flag .Args ()... )
@@ -1129,27 +1055,23 @@ func doXgo(cmdline []string) {
11291055 if strings .HasPrefix (res , GOBIN ) {
11301056 // Binary tool found, cross build it explicitly
11311057 args = append (args , "./" + filepath .Join ("cmd" , filepath .Base (res )))
1132- xgo := xgoTool (args )
1133- build .MustRun (xgo )
1058+ build .MustRun (xgoTool (args ))
11341059 args = args [:len (args )- 1 ]
11351060 }
11361061 }
11371062 return
11381063 }
1139- // Otherwise xxecute the explicit cross compilation
1064+
1065+ // Otherwise execute the explicit cross compilation
11401066 path := args [len (args )- 1 ]
11411067 args = append (args [:len (args )- 1 ], []string {"--dest" , GOBIN , path }... )
1142-
1143- xgo := xgoTool (args )
1144- build .MustRun (xgo )
1068+ build .MustRun (xgoTool (args ))
11451069}
11461070
11471071func xgoTool (args []string ) * exec.Cmd {
11481072 cmd := exec .Command (filepath .Join (GOBIN , "xgo" ), args ... )
11491073 cmd .Env = os .Environ ()
1150- cmd .Env = append (cmd .Env , []string {
1151- "GOBIN=" + GOBIN ,
1152- }... )
1074+ cmd .Env = append (cmd .Env , []string {"GOBIN=" + GOBIN }... )
11531075 return cmd
11541076}
11551077
0 commit comments