Skip to content

[skip-changelog] Add profiles to LoadSketchResponse #2264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions commands/sketch/load.go
Original file line number Diff line number Diff line change
@@ -48,6 +48,22 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
}

defaultPort, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()

profiles := make([](*rpc.SketchProfile), len(sk.Project.Profiles))
for i, profile := range sk.Project.Profiles {
profiles[i] = &rpc.SketchProfile{
Name: profile.Name,
Fqbn: profile.FQBN,
}
}

defaultProfileResp := &rpc.SketchProfile{}
defaultProfile := sk.GetProfile(sk.Project.DefaultProfile)
if defaultProfile != nil {
defaultProfileResp.Name = defaultProfile.Name
defaultProfileResp.Fqbn = defaultProfile.FQBN
}

return &rpc.LoadSketchResponse{
MainFile: sk.MainFile.String(),
LocationPath: sk.FullPath.String(),
@@ -57,5 +73,7 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
DefaultFqbn: sk.GetDefaultFQBN(),
DefaultPort: defaultPort,
DefaultProtocol: defaultProtocol,
Profiles: profiles,
DefaultProfile: defaultProfileResp,
}, nil
}
33 changes: 33 additions & 0 deletions commands/sketch/load_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of arduino-cli.
//
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].

package sketch

import (
"context"
"testing"

"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/stretchr/testify/require"
)

func TestLoadSketchProfiles(t *testing.T) {
loadResp, err := LoadSketch(context.Background(), &commands.LoadSketchRequest{
SketchPath: "./testdata/sketch_with_profile",
})
require.NoError(t, err)
require.Len(t, loadResp.GetProfiles(), 2)
require.Equal(t, loadResp.GetDefaultProfile().GetName(), "nanorp")
}
21 changes: 21 additions & 0 deletions commands/sketch/testdata/sketch_with_profile/sketch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
profiles:
nanorp:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:mbed_nano (4.0.2)
libraries:
- ArduinoIoTCloud (1.0.2)
- Arduino_ConnectionHandler (0.6.4)
- TinyDHT sensor library (1.1.0)

another_profile_name:
notes: testing the limit of the AVR platform, may be unstable
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.4)
libraries:
- VitconMQTT (1.0.1)
- Arduino_ConnectionHandler (0.6.4)
- TinyDHT sensor library (1.1.0)

default_profile: nanorp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

void setup() {
}

void loop() {
}
1,171 changes: 637 additions & 534 deletions rpc/cc/arduino/cli/commands/v1/commands.pb.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions rpc/cc/arduino/cli/commands/v1/commands.proto
Original file line number Diff line number Diff line change
@@ -297,6 +297,13 @@ message LoadSketchRequest {
reserved 1;
}

message SketchProfile {
// Name of the profile
string name = 1;
// FQBN used by the profile
string fqbn = 2;
}

message LoadSketchResponse {
// Absolute path to a main sketch files
string main_file = 1;
@@ -315,6 +322,10 @@ message LoadSketchResponse {
string default_port = 7;
// Default Protocol set in project file (sketch.yaml)
string default_protocol = 8;
// List of profiles present in the project file (sketch.yaml)
repeated SketchProfile profiles = 9;
// Default profile set in the project file (sketch.yaml)
SketchProfile default_profile = 10;
}

message ArchiveSketchRequest {