@@ -28,6 +28,7 @@ import (
28
28
"github.com/arduino/arduino-cli/internal/i18n"
29
29
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
30
30
"github.com/arduino/go-paths-helper"
31
+ "go.bug.st/f"
31
32
semver "go.bug.st/relaxed-semver"
32
33
"gopkg.in/yaml.v3"
33
34
)
@@ -271,12 +272,26 @@ func (p *ProfilePlatformReference) UnmarshalYAML(unmarshal func(interface{}) err
271
272
272
273
// ProfileLibraryReference is a reference to a library
273
274
type ProfileLibraryReference struct {
274
- Library string
275
- Version * semver.Version
275
+ Library string
276
+ InstallDir * paths.Path
277
+ Version * semver.Version
276
278
}
277
279
278
280
// UnmarshalYAML decodes a ProfileLibraryReference from YAML source.
279
281
func (l * ProfileLibraryReference ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
282
+ var dataMap map [string ]any
283
+ if err := unmarshal (& dataMap ); err == nil {
284
+ if installDir , ok := dataMap ["dir" ]; ! ok {
285
+ return errors .New (i18n .Tr ("invalid library reference: %s" , dataMap ))
286
+ } else if installDir , ok := installDir .(string ); ! ok {
287
+ return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference: %s" ), dataMap )
288
+ } else {
289
+ l .InstallDir = paths .New (installDir )
290
+ l .Library = l .InstallDir .Base ()
291
+ return nil
292
+ }
293
+ }
294
+
280
295
var data string
281
296
if err := unmarshal (& data ); err != nil {
282
297
return err
@@ -294,16 +309,23 @@ func (l *ProfileLibraryReference) UnmarshalYAML(unmarshal func(interface{}) erro
294
309
295
310
// AsYaml outputs the required library as Yaml
296
311
func (l * ProfileLibraryReference ) AsYaml () string {
297
- res := fmt .Sprintf (" - %s (%s)\n " , l .Library , l .Version )
298
- return res
312
+ if l .InstallDir != nil {
313
+ return fmt .Sprintf (" - dir: %s\n " , l .InstallDir )
314
+ }
315
+ return fmt .Sprintf (" - %s (%s)\n " , l .Library , l .Version )
299
316
}
300
317
301
318
func (l * ProfileLibraryReference ) String () string {
319
+ if l .InstallDir != nil {
320
+ return fmt .Sprintf ("%s@dir:%s" , l .Library , l .InstallDir )
321
+ }
302
322
return fmt .Sprintf ("%s@%s" , l .Library , l .Version )
303
323
}
304
324
305
325
// InternalUniqueIdentifier returns the unique identifier for this object
306
326
func (l * ProfileLibraryReference ) InternalUniqueIdentifier () string {
327
+ f .Assert (l .InstallDir == nil ,
328
+ "InternalUniqueIdentifier should not be called for library references with an install directory" )
307
329
id := l .String ()
308
330
h := sha256 .Sum256 ([]byte (id ))
309
331
res := fmt .Sprintf ("%s_%s" , id , hex .EncodeToString (h [:])[:16 ])
0 commit comments