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