@@ -23,8 +23,11 @@ import (
23
23
"sort"
24
24
"strings"
25
25
26
+ "github.com/arduino/arduino-cli/commands/cmderrors"
27
+ f "github.com/arduino/arduino-cli/internal/algorithms"
26
28
"github.com/arduino/arduino-cli/internal/arduino/globals"
27
29
"github.com/arduino/arduino-cli/internal/i18n"
30
+ rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28
31
"github.com/arduino/go-paths-helper"
29
32
)
30
33
@@ -180,15 +183,14 @@ func (s *Sketch) supportedFiles() (*paths.PathList, error) {
180
183
return & files , nil
181
184
}
182
185
183
- // GetProfile returns the requested profile or nil if the profile
184
- // is not found.
185
- func (s * Sketch ) GetProfile (profileName string ) * Profile {
186
+ // GetProfile returns the requested profile or an error if not found
187
+ func (s * Sketch ) GetProfile (profileName string ) (* Profile , error ) {
186
188
for _ , p := range s .Project .Profiles {
187
189
if p .Name == profileName {
188
- return p
190
+ return p , nil
189
191
}
190
192
}
191
- return nil
193
+ return nil , & cmderrors. UnknownProfileError { Profile : profileName }
192
194
}
193
195
194
196
// checkSketchCasing returns an error if the casing of the sketch folder and the main file are different.
@@ -278,23 +280,6 @@ func (e *InvalidSketchFolderNameError) Error() string {
278
280
return tr ("no valid sketch found in %[1]s: missing %[2]s" , e .SketchFolder , e .SketchFile )
279
281
}
280
282
281
- // CheckForPdeFiles returns all files ending with .pde extension
282
- // in sketch, this is mainly used to warn the user that these files
283
- // must be changed to .ino extension.
284
- // When .pde files won't be supported anymore this function must be removed.
285
- func CheckForPdeFiles (sketch * paths.Path ) []* paths.Path {
286
- if sketch .IsNotDir () {
287
- sketch = sketch .Parent ()
288
- }
289
-
290
- files , err := sketch .ReadDirRecursive ()
291
- if err != nil {
292
- return []* paths.Path {}
293
- }
294
- files .FilterSuffix (".pde" )
295
- return files
296
- }
297
-
298
283
// DefaultBuildPath generates the default build directory for a given sketch.
299
284
// The build path is in a temporary directory and is unique for each sketch.
300
285
func (s * Sketch ) DefaultBuildPath () * paths.Path {
@@ -307,3 +292,23 @@ func (s *Sketch) Hash() string {
307
292
md5SumBytes := md5 .Sum ([]byte (path ))
308
293
return strings .ToUpper (hex .EncodeToString (md5SumBytes [:]))
309
294
}
295
+
296
+ // ToRpc converts this Sketch into a rpc.LoadSketchResponse
297
+ func (s * Sketch ) ToRpc () * rpc.Sketch {
298
+ defaultPort , defaultProtocol := s .GetDefaultPortAddressAndProtocol ()
299
+ res := & rpc.Sketch {
300
+ MainFile : s .MainFile .String (),
301
+ LocationPath : s .FullPath .String (),
302
+ OtherSketchFiles : s .OtherSketchFiles .AsStrings (),
303
+ AdditionalFiles : s .AdditionalFiles .AsStrings (),
304
+ RootFolderFiles : s .RootFolderFiles .AsStrings (),
305
+ DefaultFqbn : s .GetDefaultFQBN (),
306
+ DefaultPort : defaultPort ,
307
+ DefaultProtocol : defaultProtocol ,
308
+ Profiles : f .Map (s .Project .Profiles , (* Profile ).ToRpc ),
309
+ }
310
+ if defaultProfile , err := s .GetProfile (s .Project .DefaultProfile ); err == nil {
311
+ res .DefaultProfile = defaultProfile .ToRpc ()
312
+ }
313
+ return res
314
+ }
0 commit comments