@@ -28,6 +28,7 @@ import (
2828 "github.com/arduino/arduino-cli/internal/i18n"
2929 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3030 "github.com/arduino/go-paths-helper"
31+ "go.bug.st/f"
3132 semver "go.bug.st/relaxed-semver"
3233 "gopkg.in/yaml.v3"
3334)
@@ -271,12 +272,26 @@ func (p *ProfilePlatformReference) UnmarshalYAML(unmarshal func(interface{}) err
271272
272273// ProfileLibraryReference is a reference to a library
273274type ProfileLibraryReference struct {
274- Library string
275- Version * semver.Version
275+ Library string
276+ InstallDir * paths.Path
277+ Version * semver.Version
276278}
277279
278280// UnmarshalYAML decodes a ProfileLibraryReference from YAML source.
279281func (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+
280295 var data string
281296 if err := unmarshal (& data ); err != nil {
282297 return err
@@ -294,16 +309,23 @@ func (l *ProfileLibraryReference) UnmarshalYAML(unmarshal func(interface{}) erro
294309
295310// AsYaml outputs the required library as Yaml
296311func (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 )
299316}
300317
301318func (l * ProfileLibraryReference ) String () string {
319+ if l .InstallDir != nil {
320+ return fmt .Sprintf ("%s@dir:%s" , l .Library , l .InstallDir )
321+ }
302322 return fmt .Sprintf ("%s@%s" , l .Library , l .Version )
303323}
304324
305325// InternalUniqueIdentifier returns the unique identifier for this object
306326func (l * ProfileLibraryReference ) InternalUniqueIdentifier () string {
327+ f .Assert (l .InstallDir == nil ,
328+ "InternalUniqueIdentifier should not be called for library references with an install directory" )
307329 id := l .String ()
308330 h := sha256 .Sum256 ([]byte (id ))
309331 res := fmt .Sprintf ("%s_%s" , id , hex .EncodeToString (h [:])[:16 ])
0 commit comments