@@ -64,6 +64,11 @@ import (
6464)
6565
6666var (
67+ goModules = []string {
68+ "." ,
69+ "./cmd/keeper" ,
70+ }
71+
6772 // Files that end up in the geth*.zip archive.
6873 gethArchiveFiles = []string {
6974 "COPYING" ,
@@ -295,6 +300,7 @@ func doTest(cmdline []string) {
295300 if * dlgo {
296301 tc .Root = build .DownloadGo (csdb )
297302 }
303+
298304 gotest := tc .Go ("test" )
299305
300306 // CI needs a bit more time for the statetests (default 45m).
@@ -323,11 +329,19 @@ func doTest(cmdline []string) {
323329 }
324330
325331 packages := flag .CommandLine .Args ()
326- if len (packages ) == 0 {
327- packages = workspacePackagePatterns ()
332+ if len (packages ) > 0 {
333+ gotest .Args = append (gotest .Args , packages ... )
334+ build .MustRun (gotest )
335+ return
336+ }
337+
338+ // No packages specified, run all tests for all modules.
339+ gotest .Args = append (gotest .Args , "./..." )
340+ for _ , mod := range goModules {
341+ test := * gotest
342+ test .Dir = mod
343+ build .MustRun (& test )
328344 }
329- gotest .Args = append (gotest .Args , packages ... )
330- build .MustRun (gotest )
331345}
332346
333347// downloadSpecTestFixtures downloads and extracts the execution-spec-tests fixtures.
@@ -351,40 +365,46 @@ func doCheckGenerate() {
351365 cachedir = flag .String ("cachedir" , "./build/cache" , "directory for caching binaries." )
352366 tc = new (build.GoToolchain )
353367 )
354- // Compute the origin hashes of all the files
355- var hashes map [string ][32 ]byte
356368
357- var err error
358- hashes , err = build .HashFolder ("." , []string {"tests/testdata" , "build/cache" , ".git" })
359- if err != nil {
360- log .Fatal ("Error computing hashes" , "err" , err )
361- }
362369 // Run any go generate steps we might be missing
363370 var (
364371 protocPath = downloadProtoc (* cachedir )
365372 protocGenGoPath = downloadProtocGenGo (* cachedir )
366373 )
367- c := tc .Go ("generate" , workspacePackagePatterns ()... )
368374 pathList := []string {filepath .Join (protocPath , "bin" ), protocGenGoPath , os .Getenv ("PATH" )}
369- c .Env = append (c .Env , "PATH=" + strings .Join (pathList , string (os .PathListSeparator )))
370- build .MustRun (c )
371375
372- // Check if generate file hashes have changed
373- generated , err := build .HashFolder ("." , []string {"tests/testdata" , "build/cache" , ".git" })
374- if err != nil {
375- log .Fatalf ("Error re-computing hashes: %v" , err )
376- }
377- updates := build .DiffHashes (hashes , generated )
378- for _ , file := range updates {
379- log .Printf ("File changed: %s" , file )
380- }
381- if len (updates ) != 0 {
382- log .Fatal ("One or more generated files were updated by running 'go generate ./...'" )
376+ for _ , mod := range goModules {
377+ // Compute the origin hashes of all the files
378+ hashes , err := build .HashFolder (mod , []string {"tests/testdata" , "build/cache" , ".git" })
379+ if err != nil {
380+ log .Fatal ("Error computing hashes" , "err" , err )
381+ }
382+
383+ c := tc .Go ("generate" , "./..." )
384+ c .Env = append (c .Env , "PATH=" + strings .Join (pathList , string (os .PathListSeparator )))
385+ c .Dir = mod
386+ build .MustRun (c )
387+ // Check if generate file hashes have changed
388+ generated , err := build .HashFolder (mod , []string {"tests/testdata" , "build/cache" , ".git" })
389+ if err != nil {
390+ log .Fatalf ("Error re-computing hashes: %v" , err )
391+ }
392+ updates := build .DiffHashes (hashes , generated )
393+ for _ , file := range updates {
394+ log .Printf ("File changed: %s" , file )
395+ }
396+ if len (updates ) != 0 {
397+ log .Fatal ("One or more generated files were updated by running 'go generate ./...'" )
398+ }
383399 }
384400 fmt .Println ("No stale files detected." )
385401
386402 // Run go mod tidy check.
387- build .MustRun (tc .Go ("mod" , "tidy" , "-diff" ))
403+ for _ , mod := range goModules {
404+ tidy := tc .Go ("mod" , "tidy" , "-diff" )
405+ tidy .Dir = mod
406+ build .MustRun (tidy )
407+ }
388408 fmt .Println ("No untidy module files detected." )
389409}
390410
@@ -425,20 +445,29 @@ func doLint(cmdline []string) {
425445 )
426446 flag .CommandLine .Parse (cmdline )
427447
448+ linter := downloadLinter (* cachedir )
449+ linter , err := filepath .Abs (linter )
450+ if err != nil {
451+ log .Fatal (err )
452+ }
453+ config , err := filepath .Abs (".golangci.yml" )
454+ if err != nil {
455+ log .Fatal (err )
456+ }
457+
458+ lflags := []string {"run" , "--config" , config }
428459 packages := flag .CommandLine .Args ()
429- if len (packages ) == 0 {
430- // Get module directories in workspace.
431- packages = []string {"./..." }
432- modules := workspaceModules ()
433- for _ , m := range modules [1 :] {
434- dir := strings .TrimPrefix (m , modules [0 ])
435- packages = append (packages , "." + dir + "/..." )
460+ if len (packages ) > 0 {
461+ build .MustRunCommandWithOutput (linter , append (lflags , packages ... )... )
462+ } else {
463+ // Run for all modules in workspace.
464+ for _ , mod := range goModules {
465+ args := append (lflags , "./..." )
466+ lintcmd := exec .Command (linter , args ... )
467+ lintcmd .Dir = mod
468+ build .MustRunWithOutput (lintcmd )
436469 }
437470 }
438-
439- linter := downloadLinter (* cachedir )
440- lflags := []string {"run" , "--config" , ".golangci.yml" }
441- build .MustRunCommandWithOutput (linter , append (lflags , packages ... )... )
442471 fmt .Println ("You have achieved perfection." )
443472}
444473
@@ -1176,31 +1205,3 @@ func doSanityCheck() {
11761205 csdb := download .MustLoadChecksums ("build/checksums.txt" )
11771206 csdb .DownloadAndVerifyAll ()
11781207}
1179-
1180- // workspaceModules lists the module paths in the current work.
1181- func workspaceModules () []string {
1182- listing , err := new (build.GoToolchain ).Go ("list" , "-m" ).Output ()
1183- if err != nil {
1184- log .Fatalf ("go list failed:" , err )
1185- }
1186- var modules []string
1187- for _ , m := range bytes .Split (listing , []byte ("\n " )) {
1188- m = bytes .TrimSpace (m )
1189- if len (m ) > 0 {
1190- modules = append (modules , string (m ))
1191- }
1192- }
1193- if len (modules ) == 0 {
1194- panic ("no modules found" )
1195- }
1196- return modules
1197- }
1198-
1199- func workspacePackagePatterns () []string {
1200- modules := workspaceModules ()
1201- patterns := make ([]string , len (modules ))
1202- for i , m := range modules {
1203- patterns [i ] = m + "/..."
1204- }
1205- return patterns
1206- }
0 commit comments