From a48664b28d38a5c6083b3becb3c6b8839dd8ccd2 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Fri, 19 Jul 2019 13:42:52 +0200 Subject: [PATCH] Use `BoardsManifest` if `Boards` is not applicable This patch falls back to the `BoardsManifest` when the `Boards` is not available. When the `Boards` are not installed, hence unavailable, the produced gRPC instance won't contain the `FQBN` but the `Name` only. Signed-off-by: Akos Kitta --- commands/core/core.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/commands/core/core.go b/commands/core/core.go index 77921555505..75ccc736f54 100644 --- a/commands/core/core.go +++ b/commands/core/core.go @@ -26,14 +26,30 @@ import ( // Note: this function does not touch the "Installed" field of rpc.Platform as it's not always clear that the // platformRelease we're currently converting is actually installed. func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform { - boards := make([]*rpc.Board, len(platformRelease.Boards)) - i := 0 - for _, b := range platformRelease.Boards { - boards[i] = &rpc.Board{ - Name: b.Name(), - Fqbn: b.FQBN(), + // If the boards are not installed yet, the `platformRelease.Boards` will be a zero length slice. + // In such case, we have to use the `platformRelease.BoardsManifest` instead. + // So that we can retrieve the name of the boards at least. + var boards []*rpc.Board + if len(platformRelease.Boards) > 0 { + boards = make([]*rpc.Board, len(platformRelease.Boards)) + i := 0 + for _, b := range platformRelease.Boards { + boards[i] = &rpc.Board{ + Name: b.Name(), + Fqbn: b.FQBN(), + } + i++ + } + } else { + boards = make([]*rpc.Board, len(platformRelease.BoardsManifest)) + i := 0 + for _, m := range platformRelease.BoardsManifest { + boards[i] = &rpc.Board{ + Name: m.Name, + // FQBN is not available. Boards have to be installed first (-> `boards.txt`). + } + i++ } - i++ } result := &rpc.Platform{