@@ -58,24 +58,24 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
5858 "exportFile" : req .ExportFile ,
5959 "jobs" : strconv .FormatInt (int64 (req .Jobs ), 10 ),
6060 "libraries" : strings .Join (req .Libraries , "," ),
61- "success" : "false" ,
6261 }
6362
63+ defer stats .Incr ("compile" , stats .M (tags )... )
64+
6465 pm := commands .GetPackageManager (req .GetInstance ().GetId ())
6566 if pm == nil {
66- stats .Incr ("compile" , stats .M (tags )... )
6767 return nil , errors .New ("invalid instance" )
6868 }
6969
7070 logrus .Tracef ("Compile %s for %s started" , req .GetSketchPath (), req .GetFqbn ())
7171 if req .GetSketchPath () == "" {
72- stats . Incr ( "compile" , stats . M ( tags ) ... )
72+ tags [ "success" ] = "false"
7373 return nil , fmt .Errorf ("missing sketchPath" )
7474 }
7575 sketchPath := paths .New (req .GetSketchPath ())
7676 sketch , err := sketches .NewSketchFromPath (sketchPath )
7777 if err != nil {
78- stats . Incr ( "compile" , stats . M ( tags ) ... )
78+ tags [ "success" ] = "false"
7979 return nil , fmt .Errorf ("opening sketch: %s" , err )
8080 }
8181
@@ -84,12 +84,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
8484 fqbnIn = sketch .Metadata .CPU .Fqbn
8585 }
8686 if fqbnIn == "" {
87- stats . Incr ( "compile" , stats . M ( tags ) ... )
87+ tags [ "success" ] = "false"
8888 return nil , fmt .Errorf ("no FQBN provided" )
8989 }
9090 fqbn , err := cores .ParseFQBN (fqbnIn )
9191 if err != nil {
92- stats . Incr ( "compile" , stats . M ( tags ) ... )
92+ tags [ "success" ] = "false"
9393 return nil , fmt .Errorf ("incorrect FQBN: %s" , err )
9494 }
9595
@@ -103,7 +103,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
103103 // "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
104104 // version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
105105 // feedback.Error(errorMessage)
106- stats . Incr ( "compile" , stats . M ( tags ) ... )
106+ tags [ "success" ] = "false"
107107 return nil , fmt .Errorf ("platform not installed" )
108108 }
109109
@@ -123,7 +123,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
123123 builderCtx .BuildPath = paths .New (req .GetBuildPath ())
124124 err = builderCtx .BuildPath .MkdirAll ()
125125 if err != nil {
126- stats . Incr ( "compile" , stats . M ( tags ) ... )
126+ tags [ "success" ] = "false"
127127 return nil , fmt .Errorf ("cannot create build directory: %s" , err )
128128 }
129129 }
@@ -152,7 +152,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
152152 builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
153153 err = builderCtx .BuildCachePath .MkdirAll ()
154154 if err != nil {
155- stats . Incr ( "compile" , stats . M ( tags ) ... )
155+ tags [ "success" ] = "false"
156156 return nil , fmt .Errorf ("cannot create build cache directory: %s" , err )
157157 }
158158 }
@@ -186,17 +186,15 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
186186 // if --preprocess or --show-properties were passed, we can stop here
187187 if req .GetShowProperties () {
188188 tags ["success" ] = "true"
189- stats .Incr ("compile" , stats .M (tags )... )
190189 return & rpc.CompileResp {}, builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
191190 } else if req .GetPreprocess () {
192191 tags ["success" ] = "true"
193- stats .Incr ("compile" , stats .M (tags )... )
194192 return & rpc.CompileResp {}, builder .RunPreprocess (builderCtx )
195193 }
196194
197195 // if it's a regular build, go on...
198196 if err := builder .RunBuilder (builderCtx ); err != nil {
199- stats . Incr ( "compile" , stats . M ( tags ) ... )
197+ tags [ "success" ] = "false"
200198 return nil , err
201199 }
202200
@@ -232,7 +230,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
232230 // Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
233231 srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
234232 if err != nil {
235- stats . Incr ( "compile" , stats . M ( tags ) ... )
233+ tags [ "success" ] = "false"
236234 return nil , fmt .Errorf ("reading build directory: %s" , err )
237235 }
238236 srcDir .FilterPrefix (base + "." )
@@ -243,7 +241,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
243241 dstOutput := exportPath .Join (exportFile + srcFilename )
244242 logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
245243 if err = srcOutput .CopyTo (dstOutput ); err != nil {
246- stats . Incr ( "compile" , stats . M ( tags ) ... )
244+ tags [ "success" ] = "false"
247245 return nil , fmt .Errorf ("copying output file: %s" , err )
248246 }
249247 }
@@ -254,13 +252,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
254252 dstElf := exportPath .Join (exportFile + ".elf" )
255253 logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
256254 if err = srcElf .CopyTo (dstElf ); err != nil {
257- stats . Incr ( "compile" , stats . M ( tags ) ... )
255+ tags [ "success" ] = "false"
258256 return nil , fmt .Errorf ("copying elf file: %s" , err )
259257 }
260258 }
261259
262260 logrus .Tracef ("Compile %s for %s successful" , sketch .Name , fqbnIn )
263261 tags ["success" ] = "true"
264- stats .Incr ("compile" , stats .M (tags )... )
265262 return & rpc.CompileResp {}, nil
266263}
0 commit comments