@@ -348,15 +348,16 @@ func (p *ProfilePlatformReference) UnmarshalYAML(unmarshal func(interface{}) err
348348
349349// ProfileLibraryReference is a reference to a library
350350type ProfileLibraryReference struct {
351- Library string
352- InstallDir * paths.Path
353- Version * semver.Version
351+ Library string
352+ Version * semver.Version
353+ IsDependency bool
354+ InstallDir * paths.Path
354355}
355356
356357// UnmarshalYAML decodes a ProfileLibraryReference from YAML source.
357358func (l * ProfileLibraryReference ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
358359 var dataMap map [string ]any
359- var data string
360+ var libReference string
360361 if err := unmarshal (& dataMap ); err == nil {
361362 if installDir , ok := dataMap ["dir" ]; ok {
362363 if installDir , ok := installDir .(string ); ! ok {
@@ -366,15 +367,24 @@ func (l *ProfileLibraryReference) UnmarshalYAML(unmarshal func(interface{}) erro
366367 l .Library = l .InstallDir .Base ()
367368 return nil
368369 }
370+ } else if depLib , ok := dataMap ["dependency" ]; ok {
371+ if libReference , ok = depLib .(string ); ! ok {
372+ return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), dataMap )
373+ }
374+ l .IsDependency = true
375+ // Fallback
369376 } else {
370377 return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), dataMap )
371378 }
372- } else if err := unmarshal (& data ); err != nil {
379+ } else if err := unmarshal (& libReference ); err != nil {
373380 return err
381+ } else {
382+ l .IsDependency = false
374383 }
375384
376- if libName , libVersion , ok := parseNameAndVersion (data ); ! ok {
377- return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), data )
385+ // Parse reference in the format "LIBRARY_NAME (VERSION)"
386+ if libName , libVersion , ok := parseNameAndVersion (libReference ); ! ok {
387+ return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), libReference )
378388 } else if v , err := semver .Parse (libVersion ); err != nil {
379389 return fmt .Errorf ("%s: %w" , i18n .Tr ("invalid version" ), err )
380390 } else {
@@ -389,17 +399,25 @@ func (l *ProfileLibraryReference) AsYaml() string {
389399 if l .InstallDir != nil {
390400 return fmt .Sprintf (" - dir: %s\n " , l .InstallDir )
391401 }
392- return fmt .Sprintf (" - %s (%s)\n " , l .Library , l .Version )
402+ dep := ""
403+ if l .IsDependency {
404+ dep = "dependency: "
405+ }
406+ return fmt .Sprintf (" - %s%s (%s)\n " , dep , l .Library , l .Version )
393407}
394408
395409func (l * ProfileLibraryReference ) String () string {
396410 if l .InstallDir != nil {
397- return fmt .Sprintf ("%s@dir:%s" , l .Library , l .InstallDir )
411+ return "@dir:" + l .InstallDir .String ()
412+ }
413+ dep := ""
414+ if l .IsDependency {
415+ dep = " (dep)"
398416 }
399417 if l .Version == nil {
400- return l .Library
418+ return l .Library + dep
401419 }
402- return fmt .Sprintf ("%s@%s" , l .Library , l .Version )
420+ return fmt .Sprintf ("%s@%s%s " , l .Library , l .Version , dep )
403421}
404422
405423// Match checks if this library reference matches another one.
@@ -434,8 +452,9 @@ func (l *ProfileLibraryReference) ToRpc() *rpc.ProfileLibraryReference {
434452 return & rpc.ProfileLibraryReference {
435453 Library : & rpc.ProfileLibraryReference_IndexLibrary_ {
436454 IndexLibrary : & rpc.ProfileLibraryReference_IndexLibrary {
437- Name : l .Library ,
438- Version : l .Version .String (),
455+ Name : l .Library ,
456+ Version : l .Version .String (),
457+ IsDependency : l .IsDependency ,
439458 },
440459 },
441460 }
@@ -459,7 +478,11 @@ func FromRpcProfileLibraryReference(l *rpc.ProfileLibraryReference) (*ProfileLib
459478 }
460479 version = v
461480 }
462- return & ProfileLibraryReference {Library : indexLib .GetName (), Version : version }, nil
481+ return & ProfileLibraryReference {
482+ Library : indexLib .GetName (),
483+ Version : version ,
484+ IsDependency : indexLib .GetIsDependency (),
485+ }, nil
463486 }
464487 return nil , & cmderrors.InvalidArgumentError {Message : "library not specified" }
465488}
@@ -468,7 +491,8 @@ func FromRpcProfileLibraryReference(l *rpc.ProfileLibraryReference) (*ProfileLib
468491func (l * ProfileLibraryReference ) InternalUniqueIdentifier () string {
469492 f .Assert (l .InstallDir == nil ,
470493 "InternalUniqueIdentifier should not be called for library references with an install directory" )
471- id := l .String ()
494+
495+ id := l .Library + "@" + l .Version .String ()
472496 h := sha256 .Sum256 ([]byte (id ))
473497 res := fmt .Sprintf ("%s_%s" , id , hex .EncodeToString (h [:])[:16 ])
474498 return utils .SanitizeName (res )
0 commit comments