@@ -105,18 +105,21 @@ func main() {
105
105
continue
106
106
}
107
107
fmt .Println ("Generating documentation for:" , target )
108
- updateDocumentation (target , path , docPath )
108
+ if err := updateDocumentation (target , path , docPath ); err != nil {
109
+ fmt .Fprintln (os .Stderr , err )
110
+ os .Exit (1 )
111
+ }
109
112
}
110
113
}
111
114
112
- func updateDocumentation (target , path , docPath string ) {
115
+ func updateDocumentation (target , path , docPath string ) error {
113
116
// Get the important information from the compiler.
114
117
cmd := exec .Command ("tinygo" , "info" , target )
115
118
outBytes , err := cmd .Output ()
116
119
if err != nil {
117
- fmt .Fprintln (os .Stderr , "could not run tinygo:" , err )
118
- os .Exit (1 )
120
+ return fmt .Errorf ("could not run tinygo: %v" , err )
119
121
}
122
+
120
123
var buildTags []string
121
124
var goos , goarch , goroot string
122
125
for _ , line := range strings .Split (string (outBytes ), "\n " ) {
@@ -138,8 +141,7 @@ func updateDocumentation(target, path, docPath string) {
138
141
}
139
142
}
140
143
if len (buildTags ) == 0 || goos == "" || goarch == "" || goroot == "" {
141
- fmt .Fprintln (os .Stderr , "could not find all needed properties (build tags, GOOS, GOARCH, GOROOT)" )
142
- os .Exit (1 )
144
+ return fmt .Errorf ("could not find all needed properties (build tags, GOOS, GOARCH, GOROOT)" )
143
145
}
144
146
145
147
// Get the list of files that would be compiled for this package.
@@ -154,24 +156,26 @@ func updateDocumentation(target, path, docPath string) {
154
156
155
157
// Do some sanity checking.
156
158
if len (pkgs [0 ].Errors ) != 0 {
159
+ fmt .Fprintf (os .Stderr , " sanity check failed with %d error(s)\n " , len (pkgs [0 ].Errors ))
157
160
for _ , err := range pkgs [0 ].Errors {
158
- fmt .Fprintln (os .Stderr , err )
161
+ fmt .Fprintf (os .Stderr , " * %v \n " , err )
159
162
}
160
- os .Exit (1 )
163
+ return nil
164
+ //os.Exit(1)
161
165
}
162
166
pkg := pkgs [0 ]
163
167
164
168
err = writeMachinePackageDoc (path , target , pkg )
165
169
if err != nil {
166
- fmt .Fprintln (os .Stderr , "error:" , err )
167
- os .Exit (1 )
170
+ return fmt .Errorf ("error on write machine package doc: %v" , err )
168
171
}
169
172
170
173
err = updateBoardDocumentation (docPath , pkg , buildTags )
171
174
if err != nil {
172
- fmt .Fprintln (os .Stderr , "error:" , err )
173
- os .Exit (1 )
175
+ return fmt .Errorf ("error on update board documentation: %v" , err )
174
176
}
177
+
178
+ return nil
175
179
}
176
180
177
181
func writeMachinePackageDoc (path , target string , pkg * packages.Package ) error {
0 commit comments