From 44c2678ef9cd938097e8d6ffa84d5d8db7a8d96f Mon Sep 17 00:00:00 2001 From: EnumDev Date: Wed, 17 Dec 2025 15:36:08 +0200 Subject: [PATCH] Show optional dependencies after install or update operation --- src/bpm/main.go | 30 ++++++++++++++++++++++++++++++ src/bpmlib/operations.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/bpm/main.go b/src/bpm/main.go index 076a87a..ad55681 100644 --- a/src/bpm/main.go +++ b/src/bpm/main.go @@ -577,6 +577,9 @@ func installPackages() { } } + // Get optional dependencies + optionalDepends := operation.GetOptionalDependencies() + // Execute operation err = operation.Execute(verbose, force) if err != nil { @@ -593,6 +596,18 @@ func installPackages() { exitCode = 1 return } + + // Show optional dependencies + if !installOptional && len(optionalDepends) != 0 { + // List optional dependencies + fmt.Println("The following opitonal dependenices have been discovered:") + for dependant, depends := range optionalDepends { + fmt.Printf("%s: \n", dependant) + for _, depend := range depends { + fmt.Printf(" - %s\n", depend) + } + } + } } func removePackages() { @@ -942,6 +957,9 @@ func updatePackages() { } } + // Get optional dependencies + optionalDepends := operation.GetOptionalDependencies() + // Execute operation err = operation.Execute(verbose, force) if err != nil { @@ -958,6 +976,18 @@ func updatePackages() { exitCode = 1 return } + + // Show optional dependencies + if !installOptional && len(optionalDepends) != 0 { + // List optional dependencies + fmt.Println("The following opitonal dependenices have been discovered:") + for dependant, depends := range optionalDepends { + fmt.Printf("%s: \n", dependant) + for _, depend := range depends { + fmt.Printf(" - %s\n", depend) + } + } + } } func getFileOwner() { diff --git a/src/bpmlib/operations.go b/src/bpmlib/operations.go index ad87cc9..23d7c14 100644 --- a/src/bpmlib/operations.go +++ b/src/bpmlib/operations.go @@ -466,6 +466,40 @@ func (operation *BPMOperation) ShowSourcePackageContent() (sourcePackagesShown i return sourcePackagesShown, nil } +func (operation *BPMOperation) GetOptionalDependencies() (optionalDepends map[string][]string) { + optionalDepends = make(map[string][]string) + + // Find all optional dependencies + for _, value := range slices.Clone(operation.Actions) { + var pkgInfo *PackageInfo + if value.GetActionType() == "install" { + action := value.(*InstallPackageAction) + pkgInfo = action.BpmPackage.PkgInfo + } else if value.GetActionType() == "fetch" { + action := value.(*FetchPackageAction) + pkgInfo = action.DatabaseEntry.Info + } else { + continue + } + + for _, depend := range pkgInfo.OptionalDepends { + // Skip if dependency is already installed + if IsPackageInstalled(depend, 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) { + continue + } + + optionalDepends[pkgInfo.Name] = append(optionalDepends[pkgInfo.Name], depend) + } + } + + return +} + func (operation *BPMOperation) RunHooks(verbose bool) error { // Return if hooks directory does not exist if stat, err := os.Stat(path.Join(operation.RootDir, "var/lib/bpm/hooks")); err != nil || !stat.IsDir() {