@@ -22,6 +22,7 @@ import (
22
22
"io"
23
23
"path/filepath"
24
24
"sort"
25
+ "strconv"
25
26
"strings"
26
27
27
28
"github.com/arduino/arduino-cli/arduino/cores"
@@ -33,26 +34,48 @@ import (
33
34
"github.com/arduino/arduino-cli/legacy/builder/i18n"
34
35
"github.com/arduino/arduino-cli/legacy/builder/types"
35
36
rpc "github.com/arduino/arduino-cli/rpc/commands"
37
+ "github.com/arduino/arduino-cli/telemetry"
36
38
paths "github.com/arduino/go-paths-helper"
37
39
properties "github.com/arduino/go-properties-orderedmap"
40
+ "github.com/segmentio/stats/v4"
38
41
"github.com/sirupsen/logrus"
39
42
"github.com/spf13/viper"
40
43
)
41
44
42
45
// Compile FIXMEDOC
43
46
func Compile (ctx context.Context , req * rpc.CompileReq , outStream , errStream io.Writer , debug bool ) (* rpc.CompileResp , error ) {
47
+
48
+ tags := map [string ]string {
49
+ "fqbn" : req .Fqbn ,
50
+ "sketchPath" : req .SketchPath ,
51
+ "showProperties" : strconv .FormatBool (req .ShowProperties ),
52
+ "preprocess" : strconv .FormatBool (req .Preprocess ),
53
+ "buildProperties" : strings .Join (req .BuildProperties , "," ),
54
+ "warnings" : req .Warnings ,
55
+ "verbose" : strconv .FormatBool (req .Verbose ),
56
+ "quiet" : strconv .FormatBool (req .Quiet ),
57
+ "vidPid" : req .VidPid ,
58
+ "exportFile" : req .ExportFile ,
59
+ "jobs" : strconv .FormatInt (int64 (req .Jobs ), 10 ),
60
+ "libraries" : strings .Join (req .Libraries , "," ),
61
+ "success" : "false" ,
62
+ }
63
+
44
64
pm := commands .GetPackageManager (req .GetInstance ().GetId ())
45
65
if pm == nil {
66
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
46
67
return nil , errors .New ("invalid instance" )
47
68
}
48
69
49
70
logrus .Tracef ("Compile %s for %s started" , req .GetSketchPath (), req .GetFqbn ())
50
71
if req .GetSketchPath () == "" {
72
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
51
73
return nil , fmt .Errorf ("missing sketchPath" )
52
74
}
53
75
sketchPath := paths .New (req .GetSketchPath ())
54
76
sketch , err := sketches .NewSketchFromPath (sketchPath )
55
77
if err != nil {
78
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
56
79
return nil , fmt .Errorf ("opening sketch: %s" , err )
57
80
}
58
81
@@ -61,10 +84,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
61
84
fqbnIn = sketch .Metadata .CPU .Fqbn
62
85
}
63
86
if fqbnIn == "" {
87
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
64
88
return nil , fmt .Errorf ("no FQBN provided" )
65
89
}
66
90
fqbn , err := cores .ParseFQBN (fqbnIn )
67
91
if err != nil {
92
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
68
93
return nil , fmt .Errorf ("incorrect FQBN: %s" , err )
69
94
}
70
95
@@ -78,6 +103,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
78
103
// "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
79
104
// version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
80
105
// feedback.Error(errorMessage)
106
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
81
107
return nil , fmt .Errorf ("platform not installed" )
82
108
}
83
109
@@ -97,6 +123,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
97
123
builderCtx .BuildPath = paths .New (req .GetBuildPath ())
98
124
err = builderCtx .BuildPath .MkdirAll ()
99
125
if err != nil {
126
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
100
127
return nil , fmt .Errorf ("cannot create build directory: %s" , err )
101
128
}
102
129
}
@@ -125,6 +152,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
125
152
builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
126
153
err = builderCtx .BuildCachePath .MkdirAll ()
127
154
if err != nil {
155
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
128
156
return nil , fmt .Errorf ("cannot create build cache directory: %s" , err )
129
157
}
130
158
}
@@ -157,13 +185,18 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
157
185
158
186
// if --preprocess or --show-properties were passed, we can stop here
159
187
if req .GetShowProperties () {
188
+ tags ["success" ] = "true"
189
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
160
190
return & rpc.CompileResp {}, builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
161
191
} else if req .GetPreprocess () {
192
+ tags ["success" ] = "true"
193
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
162
194
return & rpc.CompileResp {}, builder .RunPreprocess (builderCtx )
163
195
}
164
196
165
197
// if it's a regular build, go on...
166
198
if err := builder .RunBuilder (builderCtx ); err != nil {
199
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
167
200
return nil , err
168
201
}
169
202
@@ -199,6 +232,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
199
232
// Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
200
233
srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
201
234
if err != nil {
235
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
202
236
return nil , fmt .Errorf ("reading build directory: %s" , err )
203
237
}
204
238
srcDir .FilterPrefix (base + "." )
@@ -209,6 +243,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
209
243
dstOutput := exportPath .Join (exportFile + srcFilename )
210
244
logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
211
245
if err = srcOutput .CopyTo (dstOutput ); err != nil {
246
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
212
247
return nil , fmt .Errorf ("copying output file: %s" , err )
213
248
}
214
249
}
@@ -219,11 +254,13 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
219
254
dstElf := exportPath .Join (exportFile + ".elf" )
220
255
logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
221
256
if err = srcElf .CopyTo (dstElf ); err != nil {
257
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
222
258
return nil , fmt .Errorf ("copying elf file: %s" , err )
223
259
}
224
260
}
225
261
226
262
logrus .Tracef ("Compile %s for %s successful" , sketch .Name , fqbnIn )
227
-
263
+ tags ["success" ] = "true"
264
+ telemetry .Engine .Incr ("compile" , stats .M (tags )... )
228
265
return & rpc.CompileResp {}, nil
229
266
}
0 commit comments