This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
154 lines (131 loc) · 3.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"gopkg.in/yaml.v2"
)
const (
// underscore prefix so go tool excludes corpus directory.
corpusFolderName = "_corpus"
dirMode = 0777
host = "github.com"
hostURL = "https://" + host
)
func main() {
configYaml := flag.String("config", "repos.yaml", "yaml of repositories to run")
compiler := flag.String("compiler", "tinygo", "use this go compiler")
runPattern := flag.String("run", "", "compiler will run on all repo names matching this pattern (regexp)")
parallelism := flag.Int("parallel", 2, "max number of goroutines running compiler at any time")
wasi := flag.Bool("wasi", false, "run tests on wasi")
keepGoing := flag.Bool("k", false, "keep going after a failed test, logging all failures at the end")
flag.Parse()
repos, err := loadRepos(*configYaml)
if err != nil {
log.Fatalf("unable to load repo configuration: %v", err)
}
var countSubdir, countRepo int
defer func() {
log.Printf("Finished!\n%d/%d repos tested\n%d passed subdir tests\n", countRepo, len(repos), countSubdir)
}()
// Which repos to run.
re, err := regexp.Compile(*runPattern)
if err != nil {
log.Fatal("compiling run regexp:", err)
}
if *runPattern != "" {
// pre-filter the repos list so the progress indicator is correct
var filtered []T
for _, repo := range repos {
if !re.MatchString(repo.Repo) {
continue
}
filtered = append(filtered, repo)
}
repos = filtered
}
var target string
if *wasi {
target = "wasi"
os.Setenv("WASMTIME_BACKTRACE_DETAILS", "1")
}
// Workspace setup and cleanup.
goos := newCommander(*parallelism)
goos.Run(*compiler, "clean")
goos.Mkdir(corpusFolderName, dirMode) // force directory creation if not exist.
_, err = goos.Stat(corpusFolderName)
if err != nil {
log.Fatal("reading corpus directory: ", err)
}
goos.Chdir(corpusFolderName)
corpusDir := goos.path
// Commence testing logic.
for _, repo := range repos {
if *wasi && repo.SkipWASI {
log.Printf("skipping non-wasi package %v", repo.Repo)
continue
}
goos.Chdir(corpusDir)
goos.cloneOrUpdateRepo(repo.Repo)
repoBase := filepath.Join(corpusDir, repo.Repo)
goos.Chdir(repoBase)
if _, err := goos.Stat("go.mod"); err != nil {
log.Printf("creating %s/go.mod: running `go mod init`\n", repoBase)
goos.Run("go", "mod", "init", fmt.Sprintf("%s/%s", host, repo.Repo))
goos.Run("go", "get", "-t", ".")
}
tags := ""
if repo.Tags != "" {
tags = repo.Tags
}
dirs := []Subdir{Subdir{Pkg: repo.Repo}}
if len(repo.Subdirs) > 0 {
dirs = repo.Subdirs
}
for _, subdir := range dirs {
if *wasi && subdir.SkipWASI {
log.Printf("skipping non-wasi package %v/%v", repo.Repo, subdir.Pkg)
continue
}
if subdir.Pkg != repo.Repo {
goos.Chdir(subdir.Pkg)
}
cmd := []string{"test", "-v", "-target=" + target, "-tags=" + tags}
if *keepGoing {
goos.StartNonFatal(*compiler, cmd...)
} else {
goos.Start(*compiler, cmd...)
}
countSubdir++
goos.Chdir(repoBase)
}
countRepo++
log.Printf("finished module %d/%d %s", countRepo, len(repos), repo.Repo)
}
goos.Wait()
}
type T struct {
Repo string
Tags string
Subdirs []Subdir
SkipWASI bool
}
type Subdir struct {
Pkg string
SkipWASI bool
}
func loadRepos(f string) ([]T, error) {
yf, err := os.ReadFile(f)
if err != nil {
return nil, err
}
var repos []T
err = yaml.Unmarshal(yf, &repos)
if err != nil {
return nil, err
}
return repos, nil
}