Skip to content

Commit d5df436

Browse files
authored
[breaking] Improved compile report / temporary support for profile creation (#1745)
* [breaking] report platforms installation dir in compile result * Added platforms and libraries used in the build report * Report used libraries even in case of unsuccessful build * Added 3rd party platform url in InstalledPlatofrm grpc response * Added temporary functionality to support profile creation It will be probably deprecated and removed once a better UX is implemented. * Updated documentation * Use the last part of the FQBN for suggested profile name * Move DefaultIndexURL under arduino/globals as it should be * Use global index url * Output an error if dump-profile is used with json output
1 parent aba6a78 commit d5df436

File tree

13 files changed

+258
-103
lines changed

13 files changed

+258
-103
lines changed

Diff for: arduino/cores/cores.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"net/url"
24+
"path/filepath"
2425
"sort"
2526
"strings"
2627

28+
"github.com/arduino/arduino-cli/arduino/globals"
2729
"github.com/arduino/arduino-cli/arduino/resources"
2830
"github.com/arduino/arduino-cli/arduino/utils"
2931
"github.com/arduino/arduino-cli/i18n"
@@ -359,10 +361,21 @@ func (release *PlatformRelease) String() string {
359361
}
360362

361363
// ToRPCPlatformReference creates a gRPC PlatformReference message out of this PlatformRelease
362-
func (release *PlatformRelease) ToRPCPlatformReference() *rpc.PlatformReference {
363-
return &rpc.PlatformReference{
364-
Id: release.Platform.String(),
365-
Version: release.Version.String(),
364+
func (release *PlatformRelease) ToRPCPlatformReference() *rpc.InstalledPlatformReference {
365+
defaultURLPrefix := globals.DefaultIndexURL
366+
// TODO: create a IndexURL object to factorize this
367+
defaultURLPrefix = strings.TrimSuffix(defaultURLPrefix, filepath.Ext(defaultURLPrefix))
368+
defaultURLPrefix = strings.TrimSuffix(defaultURLPrefix, filepath.Ext(defaultURLPrefix)) // removes .tar.bz2
369+
370+
url := release.Platform.Package.URL
371+
if strings.HasPrefix(url, defaultURLPrefix) {
372+
url = ""
373+
}
374+
return &rpc.InstalledPlatformReference{
375+
Id: release.Platform.String(),
376+
Version: release.Version.String(),
377+
InstallDir: release.InstallDir.String(),
378+
PackageUrl: url,
366379
}
367380
}
368381

Diff for: arduino/cores/packagemanager/profiles.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121

2222
"github.com/arduino/arduino-cli/arduino"
2323
"github.com/arduino/arduino-cli/arduino/cores"
24+
"github.com/arduino/arduino-cli/arduino/globals"
2425
"github.com/arduino/arduino-cli/arduino/resources"
2526
"github.com/arduino/arduino-cli/arduino/sketch"
26-
"github.com/arduino/arduino-cli/cli/globals"
2727
"github.com/arduino/arduino-cli/configuration"
2828
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2929
"github.com/arduino/go-paths-helper"

Diff for: arduino/globals/globals.go

+3
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ var (
5656
".hpp": empty,
5757
".hh": empty,
5858
}
59+
60+
// DefaultIndexURL is the default index url
61+
DefaultIndexURL = "https://downloads.arduino.cc/packages/package_index.tar.bz2"
5962
)

Diff for: cli/compile/compile.go

+97-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
"github.com/arduino/arduino-cli/commands"
3434
"github.com/arduino/arduino-cli/configuration"
3535
"github.com/arduino/arduino-cli/i18n"
36+
"github.com/arduino/arduino-cli/table"
37+
"github.com/fatih/color"
3638
"github.com/sirupsen/logrus"
3739

3840
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -68,6 +70,7 @@ var (
6870
clean bool // Cleanup the build folder and do not use any cached build
6971
compilationDatabaseOnly bool // Only create compilation database without actually compiling
7072
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
7174
// library and libraries sound similar but they're actually different.
7275
// library expects a path to the root folder of one single library.
7376
// 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 {
9396

9497
fqbnArg.AddToCommand(compileCommand)
9598
profileArg.AddToCommand(compileCommand)
99+
compileCommand.Flags().BoolVar(&dumpProfile, "dump-profile", false, tr("Create and print a profile configuration from the build."))
96100
compileCommand.Flags().BoolVar(&showProperties, "show-properties", false, tr("Show all build properties used instead of compiling."))
97101
compileCommand.Flags().BoolVar(&preprocess, "preprocess", false, tr("Print preprocessed code to stdout instead of compiling."))
98102
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 {
142146
func runCompileCommand(cmd *cobra.Command, args []string) {
143147
logrus.Info("Executing `arduino-cli compile`")
144148

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+
}
145153
if profileArg.Get() != "" {
146154
if len(libraries) > 0 {
147155
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) {
268276
}
269277
}
270278

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+
271327
feedback.PrintResult(&compileResult{
272328
CompileOut: compileStdOut.String(),
273329
CompileErr: compileStdErr.String(),
@@ -316,6 +372,45 @@ func (r *compileResult) Data() interface{} {
316372
}
317373

318374
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
321416
}

Diff for: cli/core/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/arduino/arduino-cli/arduino/globals"
2627
"github.com/arduino/arduino-cli/arduino/utils"
2728
"github.com/arduino/arduino-cli/cli/errorcodes"
2829
"github.com/arduino/arduino-cli/cli/feedback"
29-
"github.com/arduino/arduino-cli/cli/globals"
3030
"github.com/arduino/arduino-cli/cli/instance"
3131
"github.com/arduino/arduino-cli/cli/output"
3232
"github.com/arduino/arduino-cli/commands"

Diff for: cli/globals/globals.go

-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ import (
2525
var (
2626
// VersionInfo contains all info injected during build
2727
VersionInfo = version.NewInfo(filepath.Base(os.Args[0]))
28-
// DefaultIndexURL is the default index url
29-
DefaultIndexURL = "https://downloads.arduino.cc/packages/package_index.tar.bz2"
3028
)

Diff for: commands/compile/compile.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
219219
return r, compileErr
220220
}
221221

222+
defer func() {
223+
importedLibs := []*rpc.Library{}
224+
for _, lib := range builderCtx.ImportedLibraries {
225+
rpcLib, err := lib.ToRPCLibrary()
226+
if err != nil {
227+
msg := tr("Error getting information for library %s", lib.Name) + ": " + err.Error() + "\n"
228+
errStream.Write([]byte(msg))
229+
}
230+
importedLibs = append(importedLibs, rpcLib)
231+
}
232+
r.UsedLibraries = importedLibs
233+
}()
234+
222235
// if it's a regular build, go on...
223236
if err := builder.RunBuilder(builderCtx); err != nil {
224237
return r, &arduino.CompileFailedError{Message: err.Error()}
@@ -268,16 +281,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
268281
}
269282
}
270283

271-
importedLibs := []*rpc.Library{}
272-
for _, lib := range builderCtx.ImportedLibraries {
273-
rpcLib, err := lib.ToRPCLibrary()
274-
if err != nil {
275-
return r, &arduino.PermissionDeniedError{Message: tr("Error getting information for library %s", lib.Name), Cause: err}
276-
}
277-
importedLibs = append(importedLibs, rpcLib)
278-
}
279-
r.UsedLibraries = importedLibs
280-
281284
r.ExecutableSectionsSize = builderCtx.ExecutableSectionsSize.ToRPCExecutableSectionSizeArray()
282285

283286
logrus.Tracef("Compile %s for %s successful", sk.Name, fqbnIn)

Diff for: commands/instances.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ import (
2727
"github.com/arduino/arduino-cli/arduino/cores"
2828
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
2929
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
30+
"github.com/arduino/arduino-cli/arduino/globals"
3031
"github.com/arduino/arduino-cli/arduino/httpclient"
3132
"github.com/arduino/arduino-cli/arduino/libraries"
3233
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
3334
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
3435
"github.com/arduino/arduino-cli/arduino/resources"
3536
"github.com/arduino/arduino-cli/arduino/sketch"
3637
"github.com/arduino/arduino-cli/arduino/utils"
37-
"github.com/arduino/arduino-cli/cli/globals"
38+
cliglobals "github.com/arduino/arduino-cli/cli/globals"
3839
"github.com/arduino/arduino-cli/configuration"
3940
"github.com/arduino/arduino-cli/i18n"
4041
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -128,7 +129,7 @@ func Create(req *rpc.CreateRequest, extraUserAgent ...string) (*rpc.CreateRespon
128129
}
129130

130131
// Create package manager
131-
userAgent := "arduino-cli/" + globals.VersionInfo.VersionString
132+
userAgent := "arduino-cli/" + cliglobals.VersionInfo.VersionString
132133
for _, ua := range extraUserAgent {
133134
userAgent += " " + ua
134135
}

Diff for: docs/UPGRADING.md

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ but since it has been the default behaviour from a very long time we decided to
1313
If a compilation fail for a missing bundled library, you can fix it just by installing the missing library from the
1414
library manager as usual.
1515

16+
### gRPC: Changes in message `cc.arduino.cli.commands.v1.PlatformReference`
17+
18+
The gRPC message structure `cc.arduino.cli.commands.v1.PlatformReference` has been renamed to
19+
`cc.arduino.cli.commands.v1.InstalledPlatformReference`, and some new fields have been added:
20+
21+
- `install_dir` is the installation directory of the platform
22+
- `package_url` is the 3rd party platform URL of the platform
23+
24+
It is currently used only in `cc.arduino.cli.commands.v1.CompileResponse`, so the field type has been changed as well.
25+
Old gRPC clients must only update gRPC bindings. They can safely ignore the new fields if not needed.
26+
27+
### golang API: `github.com/arduino/arduino-cli/cli/globals.DefaultIndexURL` has been moved under `github.com/arduino/arduino-cli/arduino/globals`
28+
29+
Legacy code should just update the import.
30+
1631
### golang API: PackageManager.DownloadPlatformRelease no longer need `label` parameter
1732

1833
```go

0 commit comments

Comments
 (0)