Skip to content

Commit 086b77a

Browse files
[skip-changelog] Add profiles to LoadSketchResponse (#2264)
* Add informations regarding profiles to LoadSketchResponse * Load profiles when LoadSketch is called * Add test to verify that LoadSketchResponse contains the profiles
1 parent 38479dc commit 086b77a

File tree

6 files changed

+726
-534
lines changed

6 files changed

+726
-534
lines changed

commands/sketch/load.go

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
4848
}
4949

5050
defaultPort, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()
51+
52+
profiles := make([](*rpc.SketchProfile), len(sk.Project.Profiles))
53+
for i, profile := range sk.Project.Profiles {
54+
profiles[i] = &rpc.SketchProfile{
55+
Name: profile.Name,
56+
Fqbn: profile.FQBN,
57+
}
58+
}
59+
60+
defaultProfileResp := &rpc.SketchProfile{}
61+
defaultProfile := sk.GetProfile(sk.Project.DefaultProfile)
62+
if defaultProfile != nil {
63+
defaultProfileResp.Name = defaultProfile.Name
64+
defaultProfileResp.Fqbn = defaultProfile.FQBN
65+
}
66+
5167
return &rpc.LoadSketchResponse{
5268
MainFile: sk.MainFile.String(),
5369
LocationPath: sk.FullPath.String(),
@@ -57,5 +73,7 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
5773
DefaultFqbn: sk.GetDefaultFQBN(),
5874
DefaultPort: defaultPort,
5975
DefaultProtocol: defaultProtocol,
76+
Profiles: profiles,
77+
DefaultProfile: defaultProfileResp,
6078
}, nil
6179
}

commands/sketch/load_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package sketch
17+
18+
import (
19+
"context"
20+
"testing"
21+
22+
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
23+
"github.com/stretchr/testify/require"
24+
)
25+
26+
func TestLoadSketchProfiles(t *testing.T) {
27+
loadResp, err := LoadSketch(context.Background(), &commands.LoadSketchRequest{
28+
SketchPath: "./testdata/sketch_with_profile",
29+
})
30+
require.NoError(t, err)
31+
require.Len(t, loadResp.GetProfiles(), 2)
32+
require.Equal(t, loadResp.GetDefaultProfile().GetName(), "nanorp")
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
profiles:
2+
nanorp:
3+
fqbn: arduino:avr:uno
4+
platforms:
5+
- platform: arduino:mbed_nano (4.0.2)
6+
libraries:
7+
- ArduinoIoTCloud (1.0.2)
8+
- Arduino_ConnectionHandler (0.6.4)
9+
- TinyDHT sensor library (1.1.0)
10+
11+
another_profile_name:
12+
notes: testing the limit of the AVR platform, may be unstable
13+
fqbn: arduino:avr:uno
14+
platforms:
15+
- platform: arduino:avr (1.8.4)
16+
libraries:
17+
- VitconMQTT (1.0.1)
18+
- Arduino_ConnectionHandler (0.6.4)
19+
- TinyDHT sensor library (1.1.0)
20+
21+
default_profile: nanorp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
void setup() {
3+
}
4+
5+
void loop() {
6+
}

0 commit comments

Comments
 (0)