@@ -33,6 +33,8 @@ import (
33
33
"github.com/arduino/arduino-cli/commands"
34
34
"github.com/arduino/arduino-cli/configuration"
35
35
"github.com/arduino/arduino-cli/i18n"
36
+ "github.com/arduino/arduino-cli/table"
37
+ "github.com/fatih/color"
36
38
"github.com/sirupsen/logrus"
37
39
38
40
"github.com/arduino/arduino-cli/cli/errorcodes"
68
70
clean bool // Cleanup the build folder and do not use any cached build
69
71
compilationDatabaseOnly bool // Only create compilation database without actually compiling
70
72
sourceOverrides string // Path to a .json file that contains a set of replacements of the sketch source code.
73
+ dumpProfile bool // Create and print a profile configuration from the build
71
74
// library and libraries sound similar but they're actually different.
72
75
// library expects a path to the root folder of one single library.
73
76
// libraries expects a path to a directory containing multiple libraries, similarly to the <directories.user>/libraries path.
@@ -93,6 +96,7 @@ func NewCommand() *cobra.Command {
93
96
94
97
fqbnArg .AddToCommand (compileCommand )
95
98
profileArg .AddToCommand (compileCommand )
99
+ compileCommand .Flags ().BoolVar (& dumpProfile , "dump-profile" , false , tr ("Create and print a profile configuration from the build." ))
96
100
compileCommand .Flags ().BoolVar (& showProperties , "show-properties" , false , tr ("Show all build properties used instead of compiling." ))
97
101
compileCommand .Flags ().BoolVar (& preprocess , "preprocess" , false , tr ("Print preprocessed code to stdout instead of compiling." ))
98
102
compileCommand .Flags ().StringVar (& buildCachePath , "build-cache-path" , "" , tr ("Builds of 'core.a' are saved into this path to be cached and reused." ))
@@ -142,6 +146,10 @@ func NewCommand() *cobra.Command {
142
146
func runCompileCommand (cmd * cobra.Command , args []string ) {
143
147
logrus .Info ("Executing `arduino-cli compile`" )
144
148
149
+ if dumpProfile && feedback .GetFormat () != feedback .Text {
150
+ feedback .Errorf (tr ("You cannot use the %[1]s flag together with %[2]s." , "--dump-profile" , "--format json" ))
151
+ os .Exit (errorcodes .ErrBadArgument )
152
+ }
145
153
if profileArg .Get () != "" {
146
154
if len (libraries ) > 0 {
147
155
feedback .Errorf (tr ("You cannot use the %s flag while compiling with a profile." , "--libraries" ))
@@ -268,6 +276,54 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
268
276
}
269
277
}
270
278
279
+ if dumpProfile {
280
+ libs := ""
281
+ hasVendoredLibs := false
282
+ for _ , lib := range compileRes .GetUsedLibraries () {
283
+ if lib .Location != rpc .LibraryLocation_LIBRARY_LOCATION_USER && lib .Location != rpc .LibraryLocation_LIBRARY_LOCATION_UNMANAGED {
284
+ continue
285
+ }
286
+ if lib .GetVersion () == "" {
287
+ hasVendoredLibs = true
288
+ continue
289
+ }
290
+ libs += fmt .Sprintln (" - " + lib .GetName () + " (" + lib .GetVersion () + ")" )
291
+ }
292
+ if hasVendoredLibs {
293
+ fmt .Println ()
294
+ fmt .Println (tr ("WARNING: The sketch is compiled using one or more custom libraries." ))
295
+ fmt .Println (tr ("Currently, Build Profiles only support libraries available through Arduino Library Manager." ))
296
+ }
297
+
298
+ newProfileName := "my_profile_name"
299
+ if split := strings .Split (compileRequest .GetFqbn (), ":" ); len (split ) > 2 {
300
+ newProfileName = split [2 ]
301
+ }
302
+ fmt .Println ()
303
+ fmt .Println ("profile:" )
304
+ fmt .Println (" " + newProfileName + ":" )
305
+ fmt .Println (" fqbn: " + compileRequest .GetFqbn ())
306
+ fmt .Println (" platforms:" )
307
+ boardPlatform := compileRes .GetBoardPlatform ()
308
+ fmt .Println (" - platform: " + boardPlatform .GetId () + " (" + boardPlatform .GetVersion () + ")" )
309
+ if url := boardPlatform .GetPackageUrl (); url != "" {
310
+ fmt .Println (" platform_index_url: " + url )
311
+ }
312
+
313
+ if buildPlatform := compileRes .GetBuildPlatform (); buildPlatform != nil &&
314
+ buildPlatform .Id != boardPlatform .Id &&
315
+ buildPlatform .Version != boardPlatform .Version {
316
+ fmt .Println (" - platform: " + buildPlatform .GetId () + " (" + buildPlatform .GetVersion () + ")" )
317
+ if url := buildPlatform .GetPackageUrl (); url != "" {
318
+ fmt .Println (" platform_index_url: " + url )
319
+ }
320
+ }
321
+ if len (libs ) > 0 {
322
+ fmt .Println (" libraries:" )
323
+ fmt .Print (libs )
324
+ }
325
+ }
326
+
271
327
feedback .PrintResult (& compileResult {
272
328
CompileOut : compileStdOut .String (),
273
329
CompileErr : compileStdErr .String (),
@@ -316,6 +372,45 @@ func (r *compileResult) Data() interface{} {
316
372
}
317
373
318
374
func (r * compileResult ) String () string {
319
- // The output is already printed via os.Stdout/os.Stdin
320
- return ""
375
+ titleColor := color .New (color .FgHiGreen )
376
+ nameColor := color .New (color .FgHiYellow )
377
+ pathColor := color .New (color .FgHiBlack )
378
+ build := r .BuilderResult
379
+
380
+ res := "\n "
381
+ libraries := table .New ()
382
+ if len (build .GetUsedLibraries ()) > 0 {
383
+ libraries .SetHeader (
384
+ table .NewCell (tr ("Used library" ), titleColor ),
385
+ table .NewCell (tr ("Version" ), titleColor ),
386
+ table .NewCell (tr ("Path" ), pathColor ))
387
+ for _ , l := range build .GetUsedLibraries () {
388
+ libraries .AddRow (
389
+ table .NewCell (l .GetName (), nameColor ),
390
+ l .GetVersion (),
391
+ table .NewCell (l .GetInstallDir (), pathColor ))
392
+ }
393
+ }
394
+ res += libraries .Render () + "\n "
395
+
396
+ platforms := table .New ()
397
+ platforms .SetHeader (
398
+ table .NewCell (tr ("Used platform" ), titleColor ),
399
+ table .NewCell (tr ("Version" ), titleColor ),
400
+ table .NewCell (tr ("Path" ), pathColor ))
401
+ boardPlatform := build .GetBoardPlatform ()
402
+ platforms .AddRow (
403
+ table .NewCell (boardPlatform .GetId (), nameColor ),
404
+ boardPlatform .GetVersion (),
405
+ table .NewCell (boardPlatform .GetInstallDir (), pathColor ))
406
+ if buildPlatform := build .GetBuildPlatform (); buildPlatform != nil &&
407
+ buildPlatform .Id != boardPlatform .Id &&
408
+ buildPlatform .Version != boardPlatform .Version {
409
+ platforms .AddRow (
410
+ table .NewCell (buildPlatform .GetId (), nameColor ),
411
+ buildPlatform .GetVersion (),
412
+ table .NewCell (buildPlatform .GetInstallDir (), pathColor ))
413
+ }
414
+ res += platforms .Render ()
415
+ return res
321
416
}
0 commit comments