@@ -349,16 +349,17 @@ func (p *ProfilePlatformReference) UnmarshalYAML(unmarshal func(interface{}) err
349349
350350// ProfileLibraryReference is a reference to a library
351351type ProfileLibraryReference struct {
352- Library string
353- Version * semver.Version
354- InstallDir * paths.Path
355- GitURL * url.URL
352+ Library string
353+ Version * semver.Version
354+ IsDependency bool
355+ InstallDir * paths.Path
356+ GitURL * url.URL
356357}
357358
358359// UnmarshalYAML decodes a ProfileLibraryReference from YAML source.
359360func (l * ProfileLibraryReference ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
360361 var dataMap map [string ]any
361- var data string
362+ var libReference string
362363 if err := unmarshal (& dataMap ); err == nil {
363364 if installDir , ok := dataMap ["dir" ]; ok {
364365 if installDir , ok := installDir .(string ); ! ok {
@@ -381,15 +382,24 @@ func (l *ProfileLibraryReference) UnmarshalYAML(unmarshal func(interface{}) erro
381382 l .Library = strings .TrimSuffix (l .Library , ".git" )
382383 return nil
383384 }
385+ } else if depLib , ok := dataMap ["dependency" ]; ok {
386+ if libReference , ok = depLib .(string ); ! ok {
387+ return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), dataMap )
388+ }
389+ l .IsDependency = true
390+ // Fallback
384391 } else {
385392 return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), dataMap )
386393 }
387- } else if err := unmarshal (& data ); err != nil {
394+ } else if err := unmarshal (& libReference ); err != nil {
388395 return err
396+ } else {
397+ l .IsDependency = false
389398 }
390399
391- if libName , libVersion , ok := parseNameAndVersion (data ); ! ok {
392- return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), data )
400+ // Parse reference in the format "LIBRARY_NAME (VERSION)"
401+ if libName , libVersion , ok := parseNameAndVersion (libReference ); ! ok {
402+ return fmt .Errorf ("%s: %s" , i18n .Tr ("invalid library reference" ), libReference )
393403 } else if v , err := semver .Parse (libVersion ); err != nil {
394404 return fmt .Errorf ("%s: %w" , i18n .Tr ("invalid version" ), err )
395405 } else {
@@ -407,7 +417,11 @@ func (l *ProfileLibraryReference) AsYaml() string {
407417 if l .GitURL != nil {
408418 return fmt .Sprintf (" - git: %s\n " , l .GitURL )
409419 }
410- return fmt .Sprintf (" - %s (%s)\n " , l .Library , l .Version )
420+ dep := ""
421+ if l .IsDependency {
422+ dep = "dependency: "
423+ }
424+ return fmt .Sprintf (" - %s%s (%s)\n " , dep , l .Library , l .Version )
411425}
412426
413427func (l * ProfileLibraryReference ) String () string {
@@ -417,10 +431,14 @@ func (l *ProfileLibraryReference) String() string {
417431 if l .GitURL != nil {
418432 return "@git:" + l .GitURL .String ()
419433 }
434+ dep := ""
435+ if l .IsDependency {
436+ dep = " (dep)"
437+ }
420438 if l .Version == nil {
421- return l .Library
439+ return l .Library + dep
422440 }
423- return fmt .Sprintf ("%s@%s" , l .Library , l .Version )
441+ return fmt .Sprintf ("%s@%s%s " , l .Library , l .Version , dep )
424442}
425443
426444// Match checks if this library reference matches another one.
@@ -467,8 +485,9 @@ func (l *ProfileLibraryReference) ToRpc() *rpc.ProfileLibraryReference {
467485 return & rpc.ProfileLibraryReference {
468486 Library : & rpc.ProfileLibraryReference_IndexLibrary_ {
469487 IndexLibrary : & rpc.ProfileLibraryReference_IndexLibrary {
470- Name : l .Library ,
471- Version : l .Version .String (),
488+ Name : l .Library ,
489+ Version : l .Version .String (),
490+ IsDependency : l .IsDependency ,
472491 },
473492 },
474493 }
@@ -499,7 +518,11 @@ func FromRpcProfileLibraryReference(l *rpc.ProfileLibraryReference) (*ProfileLib
499518 }
500519 version = v
501520 }
502- return & ProfileLibraryReference {Library : indexLib .GetName (), Version : version }, nil
521+ return & ProfileLibraryReference {
522+ Library : indexLib .GetName (),
523+ Version : version ,
524+ IsDependency : indexLib .GetIsDependency (),
525+ }, nil
503526 }
504527 return nil , & cmderrors.InvalidArgumentError {Message : "library not specified" }
505528}
@@ -518,7 +541,7 @@ func (l *ProfileLibraryReference) InternalUniqueIdentifier() string {
518541 return id + "-" + hex .EncodeToString (h [:])[:8 ]
519542 }
520543
521- id := l .String ()
544+ id := l .Library + "@" + l . Version . String ()
522545 h := sha256 .Sum256 ([]byte (id ))
523546 res := fmt .Sprintf ("%s_%s" , id , hex .EncodeToString (h [:])[:16 ])
524547 return utils .SanitizeName (res )
0 commit comments