@@ -58,24 +58,24 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
58
58
"exportFile" : req .ExportFile ,
59
59
"jobs" : strconv .FormatInt (int64 (req .Jobs ), 10 ),
60
60
"libraries" : strings .Join (req .Libraries , "," ),
61
- "success" : "false" ,
62
61
}
63
62
63
+ defer stats .Incr ("compile" , stats .M (tags )... )
64
+
64
65
pm := commands .GetPackageManager (req .GetInstance ().GetId ())
65
66
if pm == nil {
66
- stats .Incr ("compile" , stats .M (tags )... )
67
67
return nil , errors .New ("invalid instance" )
68
68
}
69
69
70
70
logrus .Tracef ("Compile %s for %s started" , req .GetSketchPath (), req .GetFqbn ())
71
71
if req .GetSketchPath () == "" {
72
- stats . Incr ( "compile" , stats . M ( tags ) ... )
72
+ tags [ "success" ] = "false"
73
73
return nil , fmt .Errorf ("missing sketchPath" )
74
74
}
75
75
sketchPath := paths .New (req .GetSketchPath ())
76
76
sketch , err := sketches .NewSketchFromPath (sketchPath )
77
77
if err != nil {
78
- stats . Incr ( "compile" , stats . M ( tags ) ... )
78
+ tags [ "success" ] = "false"
79
79
return nil , fmt .Errorf ("opening sketch: %s" , err )
80
80
}
81
81
@@ -84,12 +84,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
84
84
fqbnIn = sketch .Metadata .CPU .Fqbn
85
85
}
86
86
if fqbnIn == "" {
87
- stats . Incr ( "compile" , stats . M ( tags ) ... )
87
+ tags [ "success" ] = "false"
88
88
return nil , fmt .Errorf ("no FQBN provided" )
89
89
}
90
90
fqbn , err := cores .ParseFQBN (fqbnIn )
91
91
if err != nil {
92
- stats . Incr ( "compile" , stats . M ( tags ) ... )
92
+ tags [ "success" ] = "false"
93
93
return nil , fmt .Errorf ("incorrect FQBN: %s" , err )
94
94
}
95
95
@@ -103,7 +103,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
103
103
// "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
104
104
// version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
105
105
// feedback.Error(errorMessage)
106
- stats . Incr ( "compile" , stats . M ( tags ) ... )
106
+ tags [ "success" ] = "false"
107
107
return nil , fmt .Errorf ("platform not installed" )
108
108
}
109
109
@@ -123,7 +123,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
123
123
builderCtx .BuildPath = paths .New (req .GetBuildPath ())
124
124
err = builderCtx .BuildPath .MkdirAll ()
125
125
if err != nil {
126
- stats . Incr ( "compile" , stats . M ( tags ) ... )
126
+ tags [ "success" ] = "false"
127
127
return nil , fmt .Errorf ("cannot create build directory: %s" , err )
128
128
}
129
129
}
@@ -152,7 +152,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
152
152
builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
153
153
err = builderCtx .BuildCachePath .MkdirAll ()
154
154
if err != nil {
155
- stats . Incr ( "compile" , stats . M ( tags ) ... )
155
+ tags [ "success" ] = "false"
156
156
return nil , fmt .Errorf ("cannot create build cache directory: %s" , err )
157
157
}
158
158
}
@@ -186,17 +186,15 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
186
186
// if --preprocess or --show-properties were passed, we can stop here
187
187
if req .GetShowProperties () {
188
188
tags ["success" ] = "true"
189
- stats .Incr ("compile" , stats .M (tags )... )
190
189
return & rpc.CompileResp {}, builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
191
190
} else if req .GetPreprocess () {
192
191
tags ["success" ] = "true"
193
- stats .Incr ("compile" , stats .M (tags )... )
194
192
return & rpc.CompileResp {}, builder .RunPreprocess (builderCtx )
195
193
}
196
194
197
195
// if it's a regular build, go on...
198
196
if err := builder .RunBuilder (builderCtx ); err != nil {
199
- stats . Incr ( "compile" , stats . M ( tags ) ... )
197
+ tags [ "success" ] = "false"
200
198
return nil , err
201
199
}
202
200
@@ -232,7 +230,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
232
230
// Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
233
231
srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
234
232
if err != nil {
235
- stats . Incr ( "compile" , stats . M ( tags ) ... )
233
+ tags [ "success" ] = "false"
236
234
return nil , fmt .Errorf ("reading build directory: %s" , err )
237
235
}
238
236
srcDir .FilterPrefix (base + "." )
@@ -243,7 +241,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
243
241
dstOutput := exportPath .Join (exportFile + srcFilename )
244
242
logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
245
243
if err = srcOutput .CopyTo (dstOutput ); err != nil {
246
- stats . Incr ( "compile" , stats . M ( tags ) ... )
244
+ tags [ "success" ] = "false"
247
245
return nil , fmt .Errorf ("copying output file: %s" , err )
248
246
}
249
247
}
@@ -254,13 +252,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
254
252
dstElf := exportPath .Join (exportFile + ".elf" )
255
253
logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
256
254
if err = srcElf .CopyTo (dstElf ); err != nil {
257
- stats . Incr ( "compile" , stats . M ( tags ) ... )
255
+ tags [ "success" ] = "false"
258
256
return nil , fmt .Errorf ("copying elf file: %s" , err )
259
257
}
260
258
}
261
259
262
260
logrus .Tracef ("Compile %s for %s successful" , sketch .Name , fqbnIn )
263
261
tags ["success" ] = "true"
264
- stats .Incr ("compile" , stats .M (tags )... )
265
262
return & rpc.CompileResp {}, nil
266
263
}
0 commit comments