Add optional dependency descriptions

This commit is contained in:
2026-01-26 13:25:25 +02:00
parent 0a06808303
commit b3dc6e3e34
4 changed files with 43 additions and 11 deletions
+15 -3
View File
@@ -297,7 +297,9 @@ func (entry *BPMDatabaseEntry) GetEntryOptionalDependants() (dependants []string
dependantsMap := make(map[string][]string)
for _, db := range BPMDatabases {
for _, e := range db.Entries {
if slices.Contains(e.Info.OptionalDepends, entry.Info.Name) {
if slices.ContainsFunc(e.Info.OptionalDepends, func(n string) bool {
return strings.SplitN(n, ":", 2)[0] == entry.Info.Name
}) {
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], e.Database.Name)
}
}
@@ -358,10 +360,20 @@ func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, humanReadableS
builder.WriteString("Type: " + entry.Info.Type + "\n")
builderWriteArray("Dependencies", entry.Info.Depends, true)
if entry.Info.Type == "source" {
builderWriteArray("Make Dependencies", entry.Info.MakeDepends, true)
builderWriteArray("Make dependencies", entry.Info.MakeDepends, true)
}
builderWriteArray("Runtime dependencies", entry.Info.RuntimeDepends, true)
builderWriteArray("Optional dependencies", entry.Info.OptionalDepends, true)
if len(entry.Info.OptionalDepends) > 0 {
builder.WriteString("Optional dependencies:\n")
for _, depend := range entry.Info.OptionalDepends {
dependSplit := strings.SplitN(depend, ":", 2)
if len(dependSplit) == 2 {
builder.WriteString(fmt.Sprintf(" - %s (%s)\n", dependSplit[0], dependSplit[1]))
} else {
builder.WriteString(" - " + dependSplit[0] + "\n")
}
}
}
dependants := entry.GetEntryDependants()
if len(dependants) > 0 {
builderWriteArray("Dependant packages", dependants, false)
+4 -2
View File
@@ -3,6 +3,7 @@ package bpmlib
import (
"fmt"
"slices"
"strings"
)
type pkgInstallationReason struct {
@@ -25,6 +26,7 @@ func (pkgInfo *PackageInfo) GetDependencies(includeMakeDepends, includeRuntimeDe
}
if includeOptionalDepends {
for _, depend := range pkgInfo.OptionalDepends {
depend = strings.SplitN(depend, ":", 2)[0]
if !slices.ContainsFunc(allDepends, func(p pkgInstallationReason) bool {
return p.PkgName == depend
}) {
@@ -283,7 +285,7 @@ func (pkgInfo *PackageInfo) GetPackageOptionalDependants(rootDir string) (depend
// Add installed package to list if its optional dependencies include pkgName
if slices.ContainsFunc(installedPkg.OptionalDepends, func(n string) bool {
return n == pkgInfo.Name
return strings.SplitN(n, ":", 2)[0] == pkgInfo.Name
}) {
dependants = append(dependants, installedPkg.Name)
continue
@@ -293,7 +295,7 @@ func (pkgInfo *PackageInfo) GetPackageOptionalDependants(rootDir string) (depend
for _, vpkg := range pkgInfo.Provides {
// Add installed package to list if its optional dependencies contain a provided virtual package
if slices.ContainsFunc(installedPkg.OptionalDepends, func(n string) bool {
return n == vpkg
return strings.SplitN(n, ":", 2)[0] == vpkg
}) {
dependants = append(dependants, installedPkg.Name)
break
+11 -3
View File
@@ -485,17 +485,25 @@ func (operation *BPMOperation) GetOptionalDependencies() (optionalDepends map[st
}
for _, depend := range pkgInfo.OptionalDepends {
dependSplit := strings.SplitN(depend, ":", 2)
// Skip if dependency is already installed
if IsPackageInstalled(depend, operation.RootDir) {
if IsPackageInstalled(dependSplit[0], operation.RootDir) {
continue
}
// Skip if not a new dependency of the package
if installedPkg := GetPackage(pkgInfo.Name, operation.RootDir); installedPkg != nil && slices.Contains(installedPkg.PkgInfo.OptionalDepends, depend) {
if installedPkg := GetPackage(pkgInfo.Name, operation.RootDir); installedPkg != nil && slices.ContainsFunc(installedPkg.PkgInfo.OptionalDepends, func(n string) bool {
return strings.SplitN(n, ":", 2)[0] == dependSplit[0]
}) {
continue
}
optionalDepends[pkgInfo.Name] = append(optionalDepends[pkgInfo.Name], depend)
if len(dependSplit) == 2 {
optionalDepends[pkgInfo.Name] = append(optionalDepends[pkgInfo.Name], fmt.Sprintf("%s (%s)", dependSplit[0], dependSplit[1]))
} else {
optionalDepends[pkgInfo.Name] = append(optionalDepends[pkgInfo.Name], dependSplit[0])
}
}
}
+13 -3
View File
@@ -574,11 +574,21 @@ func (pkgInfo *PackageInfo) CreateReadableInfo(rootDir string) string {
builder.WriteString("Type: " + pkgInfo.Type + "\n")
builderWriteArray("Dependencies", pkgInfo.Depends, true)
if pkgInfo.Type == "source" {
builderWriteArray("Runtime Dependencies", pkgInfo.RuntimeDepends, true)
builderWriteArray("Make Dependencies", pkgInfo.MakeDepends, true)
builderWriteArray("Runtime dependencies", pkgInfo.RuntimeDepends, true)
builderWriteArray("Make dependencies", pkgInfo.MakeDepends, true)
}
builderWriteArray("Runtime dependencies", pkgInfo.RuntimeDepends, true)
builderWriteArray("Optional dependencies", pkgInfo.OptionalDepends, true)
if len(pkgInfo.OptionalDepends) > 0 {
builder.WriteString("Optional dependencies:\n")
for _, depend := range pkgInfo.OptionalDepends {
dependSplit := strings.SplitN(depend, ":", 2)
if len(dependSplit) == 2 {
builder.WriteString(fmt.Sprintf(" - %s (%s)\n", dependSplit[0], dependSplit[1]))
} else {
builder.WriteString(" - " + dependSplit[0] + "\n")
}
}
}
dependants := pkgInfo.GetPackageDependants(rootDir)
if len(dependants) > 0 {
builderWriteArray("Dependant packages", dependants, true)