Skip to contentSkip to conversation

show and delete recursive list of reverse dependencies

PATCH In review Dave Lerner 3 participants 6 messages Mar 22, 2016 – Mar 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 show and delete recursive list of reverse dependencies

Target Branch: toaster-next master
Contrib Branch: poky-contrib/dlerner/9121-delete-dependent-package-tree
Defect: 9121
Summary: show and delete recursive list of reverse dependencies

Comment
-------
Version 3: Shorter sanity tests run here. This version 3 is only a rebase against toaster-next. No patches were changed.

Commit
------
aa742e6 toaster: get all dependents for pkg for removal 1c86b2b toaster: new customise package-remove modal dlg 6cff5de toaster: show full list of dependents to remove

 .../toaster/toastergui/static/js/customrecipe.js   | 72 +++++++++++++++--
 .../toaster/toastergui/templates/customrecipe.html |  5 +-
 bitbake/lib/toaster/toastergui/views.py            | 91 +++++++++++++++++++---
 3 files changed, 148 insertions(+), 20 deletions(-)

SETUP:
-----
Start toaster with empty build directory, sstate-cache Create a new project, 'myproject'
Build core-image-sato

CASE Remove reverse dependency package that was part of original base image
------------------------------------------------------------------
Create new custom image on core-image-sato, named mysato
Remove libcrypto
Verify that "39 packages will be removed" are reported and that the
packages are unique and in alpha order
[V3] Verify that the notification shows
"You have removed libcrypto and its 39 reverse dependencies: gst-player-bin, gstreamer1.0-plugins-bad-dtls, gstreamer1.0-plugins-bad-meta, gstreamer1.0-plugins-bad-opengl, libegl-mesa and 34 more"

CASE Test no interference removing from a 2nd custom image in project
----------------------------------------------------------------------
New custom-image based on core-image-sato 'myminimal'
Build it
Add atk which is dependant on glib-2.0, libffi, libpcre (bash appears but this
is busybox system, so don't think that dependency will apply - maybe bug unrelated to this work). Build myminimal again.
Verify that atk, libffi, libpcre, glib-2.0 have files in the file system
For custom image myminimal, enter libpcre, remove package
Verify modal dlg notes libpcre atk and glib-2.0 will be removed Remove
Verify that banner shows
"You have removed 3 packages form myminimal: <strong> libpcre </strong> and its 2 reverse depenencies: atk, glib-2.0" Build
Verify atk, glib2.0 and libpcre are removed.

#1 lore raw

PATCH v3 1/3 toaster: show full list of dependents to remove

When a package is to be removed, show the full list of packages that are dependent on that package, telling user that these packages will also be removed.

[YOCTO #9121]

---
 .../toaster/toastergui/static/js/customrecipe.js   | 72 ++++++++++++++++++++--
 1 file changed, 66 insertions(+), 6 deletions(-)
bitbake/lib/toaster/toastergui/static/js/customrecipe.js +66 -6
index 3c57899..f1b8afb 100644
@@ -89,7 +89,21 @@ function customRecipePageInit(ctx) {
     var depsList = modal.find("#package-reverse-dep-list");
     var deps = pkgData.reverse_dependencies;
 
+    var depsCount = deps.length;
+    var vDepends = "depends";
+    var vPackage = "package";
+    var vThis = "this";
+    if (depsCount > 1) {
+      vDepends = "depend";
+      vPackage = "packages";
+      vThis = "these";
+    }
     modal.find(".package-to-rm-name").text(targetPkg.name);
+    modal.find(".reverse-deps-count").text(depsCount);
+    modal.find(".reverse-deps-count-plus1").text((depsCount+1) + " packages");
+    modal.find(".reverse-deps-depends").text(vDepends);
+    modal.find(".reverse-deps-package").text(vPackage);
+    modal.find(".reverse-deps-this").text(vThis);
 
     depsList.text("");
 
@@ -103,6 +117,8 @@ function customRecipePageInit(ctx) {
     modal.find("#package-reverse-deps-total-size").text(
       pkgData.reverse_dependencies_size_formatted);
 
+    targetPkg.depsRemoved = deps;
+
     rmdPkgReverseDepsModalBtn.data(targetPkg);
     modal.modal('show');
   }
@@ -121,6 +137,10 @@ function customRecipePageInit(ctx) {
     var btnCell = $("#package-btn-cell-" + targetPkg.id);
     var inlineNotify = btnCell.children(".inline-notification");
 
+    var i;
+    var dep;
+    var depBtnCell;
+
     if (targetPkg.directive === 'add') {
       method = 'PUT';
       /* If the package had dependencies also notify that they were added */
@@ -132,15 +152,15 @@ function customRecipePageInit(ctx) {
         msg += " packages to " + ctx.recipe.name + ": ";
         msg += "<strong>" + targetPkg.name + "</strong> and its dependencies";
 
-        for (var i in targetPkg.depsAdded){
-          var dep = targetPkg.depsAdded[i];
+        for (i in targetPkg.depsAdded){
+          dep = targetPkg.depsAdded[i];
 
           msg += " <strong>" + dep.name + "</strong>";
 
           /* Add any cells currently in view to the list of cells which get
            * an inline notification inside them and which change add/rm state
            */
-          var depBtnCell = $("#package-btn-cell-" + dep.pk);
+          depBtnCell = $("#package-btn-cell-" + dep.pk);
           btnCell = btnCell.add(depBtnCell);
 
           inlineNotify = inlineNotify.add(
@@ -159,9 +179,49 @@ function customRecipePageInit(ctx) {
 
     } else if (targetPkg.directive === 'remove') {
       method = 'DELETE';
-      msg += "removed 1 package from "+ctx.recipe.name+":";
-      msg += ' <strong>' + targetPkg.name + '<strong>';
-      inlineNotify.text("1 package removed");
+      var numPackageString = "1 package ";
+      var revDepList = "";
+      if (targetPkg.hasOwnProperty('depsRemoved') &&
+              targetPkg.depsRemoved.length > 0) {
+        var depsRemovedLength = targetPkg.depsRemoved.length;
+        var ending = "y: ";
+        var maxRevDepsDisplayed  = 5;
+        var d = 0;
+        if (depsRemovedLength > 1) {
+            ending = "ies: ";
+        }
+        numPackageString = (depsRemovedLength + 1) + " packages";
+        revDepList = " and its " + depsRemovedLength + " reverse dependenc" + ending;
+        for (i in targetPkg.depsRemoved){
+          /* include up to maxRevDepsDisplayed rev deps on the page notification */
+          var notShownCount = depsRemovedLength - maxRevDepsDisplayed;
+          dep = targetPkg.depsRemoved[i];
+          if (d < maxRevDepsDisplayed) {
+            if (d > 0) {
+                revDepList += ", ";
+            }
+            revDepList += dep.name;
+            d++;
+            if ((d === maxRevDepsDisplayed) && (notShownCount > 0)) {
+                revDepList += " and " + notShownCount + " more";
+            }
+          }
+
+          /* Add any cells currently in view to the list of cells which get
+           * an inline notification inside them and which change add/rm state
+           */
+          depBtnCell = $("#package-btn-cell-" + dep.pk);
+          btnCell = btnCell.add(depBtnCell);
+
+          inlineNotify = inlineNotify.add(
+            depBtnCell.children(".inline-notification"));
+        }
+      }
+      msg+= "removed " + numPackageString + " from " + ctx.recipe.name + ":";
+      msg += " <strong>" + targetPkg.name + "</strong>";
+      msg += revDepList;
+
+      inlineNotify.text(numPackageString + " removed");
     } else {
       throw("Unknown package directive: should be add or remove");
     }
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 2/3 toaster: new customise package-remove modal dlg

In reply to Dave Lerner

For customised image package removal, show a different modal dialog that lists ALL of the packages dependent on this package, with a Remove All button - implying that all of the dependents will be removed.

[YOCTO #9121]

---
 bitbake/lib/toaster/toastergui/templates/customrecipe.html | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
bitbake/lib/toaster/toastergui/templates/customrecipe.html +3 -2
index 8cce919..4b58992 100644
@@ -66,13 +66,14 @@
     <h3><span class="package-to-rm-name"></span> reverse dependencies</h3>
   </div>
   <div class="modal-body">
-    <p>Based on information from a previous build it is likely that <strong class="package-to-rm-name"></strong> may be added again as the following packages directly depend on it for your custom image:</p>
+    <p> <strong class="reverse-deps-count"></strong> <span class="reverse-deps-package"></span> in your image <span class="reverse-deps-depends"></span> on <strong class="package-to-rm-name"></strong>:</p>
     <ul id="package-reverse-dep-list">
     </ul>
+    <p>In order to remove <strong class="package-to-rm-name"></strong>, you must remove <span class="reverse-deps-this"></span> <strong class="reverse-deps-count"></strong> <span class="reverse-deps-package"></span> as well.</p>
   </div>
   <div class="modal-footer">
     <p class="help-block text-left">Total package size: <strong id="package-reverse-deps-total-size"></strong></p>
-    <button id="rm-package-reverse-deps-modal-btn" type="submit" class="btn btn-primary" data-dismiss="modal">Remove package</button>
+    <button id="rm-package-reverse-deps-modal-btn" type="submit" class="btn btn-primary" data-dismiss="modal">Remove all <span class="reverse-deps-count-plus1"></button>
     <button class="btn" data-dismiss="modal">Cancel</button>
   </div>
 </div>
Signature · 1 line
1.9.1
#3 lore raw

PATCH v3 3/3 toaster: get all dependents for pkg for removal

In reply to Dave Lerner

For customised image package removal change behavior.
From:
Only display the immediate dependents of the requested package to remove, not the full dependent list, that is dependents of dependents ...
Do not remove the displayed dependents, just notify the user of the list.
To:
Display the complete dependent tree, traversing all reverse dependencies starting from the package to be removed and then it's dependents.
Change the modal dialog to note that all of these dependents will be removed automatically.

[YOCTO #9121]

---
 bitbake/lib/toaster/toastergui/views.py | 91 ++++++++++++++++++++++++++++-----
 1 file changed, 79 insertions(+), 12 deletions(-)
bitbake/lib/toaster/toastergui/views.py +79 -12
index 85ca9be..9944c8d 100755
@@ -2538,6 +2538,60 @@ if True:
 
         return response
 
+    def _traverse_dependents(next_package_id, rev_deps, all_current_packages, tree_level=0):
+        """
+        Recurse through reverse dependency tree for next_package_id.
+        Limit the reverse dependency search to packages not already scanned,
+        that is, not already in rev_deps.
+        Limit the scan to a depth (tree_level) not exceeding the count of
+        all packages in the custom image, and if that depth is exceeded
+        return False, pop out of the recursion, and write a warning
+        to the log, but this is unlikely, suggesting a dependency loop
+        not caught by bitbake.
+        On return, the input/output arg rev_deps is appended with queryset
+        dictionary elements, annotated for use in the customimage template.
+        The list has unsorted, but unique elements.
+        """
+        max_dependency_tree_depth = all_current_packages.count()
+        if tree_level >= max_dependency_tree_depth:
+            logger.warning(
+                "The number of reverse dependencies " 
+                "for this package exceeds " + max_dependency_tree_depth +
+                " and the remaining reverse dependencies will not be removed")
+            return True
+
+        package = CustomImagePackage.objects.get(id=next_package_id)
+        dependents = \
+            package.package_dependencies_target.annotate(
+                name=F('package__name'),
+                pk=F('package__pk'),
+                size=F('package__size'),
+            ).values("name", "pk", "size").exclude(
+                ~Q(pk__in=all_current_packages)
+            )
+
+        for pkg in dependents:
+            if pkg in rev_deps:
+                # already seen, skip dependent search
+                continue
+
+            rev_deps.append(pkg)
+            if (_traverse_dependents(
+                pkg["pk"], rev_deps, all_current_packages, tree_level+1)):
+                return True
+
+        return False
+
+    def _get_all_dependents(package_id, all_current_packages):
+        """
+        Returns sorted list of recursive reverse dependencies for package_id,
+        as a list of dictionary items, by recursing through dependency
+        relationships.
+        """
+        rev_deps = []
+        _traverse_dependents(package_id, rev_deps, all_current_packages)
+        rev_deps = sorted(rev_deps, key=lambda x: x["name"])
+        return rev_deps
 
     @xhr_response
     def xhr_customrecipe_packages(request, recipe_id, package_id):
@@ -2606,15 +2660,9 @@ if True:
                 )
 
                 # Reverse dependencies which are needed by packages that are
-                # in the image
-                reverse_deps = package.package_dependencies_target.annotate(
-                    name=F('package__name'),
-                    pk=F('package__pk'),
-                    size=F('package__size'),
-                ).values("name", "pk", "size").exclude(
-                    ~Q(pk__in=all_current_packages)
-                )
-
+                # in the image. Recursive search providing all dependents,
+                # not just immediate dependents.
+                reverse_deps = _get_all_dependents(package_id, all_current_packages)
                 total_size_deps = 0
                 total_size_reverse_deps = 0
 
@@ -2658,6 +2706,11 @@ if True:
 
             else:
                 recipe.appends_set.add(package)
+                # Make sure that package is not in the excludes set
+                try:
+                    recipe.excludes_set.remove(package)
+                except:
+                    pass
                 # Add the dependencies we think will be added to the recipe
                 # as a result of appending this package.
                 # TODO this should recurse down the entire deps tree
@@ -2668,11 +2721,12 @@ if True:
 
                         recipe.includes_set.add(cust_package)
                         try:
-                            # when adding the pre-requisite package make sure it's not in the
-                            #   excluded list from a prior removal.
+                            # When adding the pre-requisite package, make
+                            # sure it's not in the excluded list from a
+                            # prior removal.
                             recipe.excludes_set.remove(cust_package)
                         except Package.DoesNotExist:
-                            #   Don't care if the package had never been excluded
+                            # Don't care if the package had never been excluded
                             pass
                     except:
                         logger.warning("Could not add package's suggested"
@@ -2688,6 +2742,19 @@ if True:
                     recipe.excludes_set.add(package)
                 else:
                     recipe.appends_set.remove(package)
+                all_current_packages = recipe.get_all_packages()
+                reverse_deps_dictlist = _get_all_dependents(package.pk, all_current_packages)
+                ids = [entry['pk'] for entry in reverse_deps_dictlist]
+                reverse_deps = CustomImagePackage.objects.filter(id__in=ids)
+                for r in reverse_deps:
+                    try:
+                        if r.id in included_packages:
+                            recipe.excludes_set.add(r)
+                        else:
+                            recipe.appends_set.remove(r)
+                    except:
+                        pass
+
                 return {"error": "ok"}
             except CustomImageRecipe.DoesNotExist:
                 return {"error": "Tried to remove package that wasn't present"}
Signature · 1 line
1.9.1
#4 lore raw
In reply to Dave Lerner
Quoted 4 lines · On 22/03/2016 15:56, "[email protected] on behalf of Dave…

Target Branch: toaster-next master
Contrib Branch: poky-contrib/dlerner/9121-delete-dependent-package-tree
Defect: 9121

This seems to work like a charm. Thanks!

Belén

Quoted 63 lines

Summary: show and delete recursive list of reverse dependencies

Comment
-------
Version 3: Shorter sanity tests run here. This version 3 is only a rebase against toaster-next. No patches were changed.

Commit
------
aa742e6 toaster: get all dependents for pkg for removal 1c86b2b toaster: new customise package-remove modal dlg 6cff5de toaster: show full list of dependents to remove

.../toaster/toastergui/static/js/customrecipe.js   | 72 +++++++++++++++--
.../toaster/toastergui/templates/customrecipe.html |  5 +-
bitbake/lib/toaster/toastergui/views.py            | 91
+++++++++++++++++++---
3 files changed, 148 insertions(+), 20 deletions(-)

SETUP:
-----
Start toaster with empty build directory, sstate-cache Create a new project, 'myproject'
Build core-image-sato

CASE Remove reverse dependency package that was part of original base image
------------------------------------------------------------------
Create new custom image on core-image-sato, named mysato Remove libcrypto
Verify that "39 packages will be removed" are reported and that the packages are unique and in alpha order
[V3] Verify that the notification shows
"You have removed libcrypto and its 39 reverse dependencies:
gst-player-bin, gstreamer1.0-plugins-bad-dtls, gstreamer1.0-plugins-bad-meta, gstreamer1.0-plugins-bad-opengl, libegl-mesa and 34 more"

CASE Test no interference removing from a 2nd custom image in project
----------------------------------------------------------------------
New custom-image based on core-image-sato 'myminimal'
Build it
Add atk which is dependant on glib-2.0, libffi, libpcre (bash appears but this
is busybox system, so don't think that dependency will apply - maybe bug unrelated to this work).
Build myminimal again.
Verify that atk, libffi, libpcre, glib-2.0 have files in the file system For custom image myminimal, enter libpcre, remove package
Verify modal dlg notes libpcre atk and glib-2.0 will be removed Remove Verify that banner shows
"You have removed 3 packages form myminimal: <strong> libpcre </strong> and its 2 reverse depenencies: atk, glib-2.0"
Build
Verify atk, glib2.0 and libpcre are removed.

Signature · 4 lines
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster
#5 lore raw

I also tested this, and it looked good.

Added to toaster-next and upstreamed to bitbake-devel.

Elliot

Quoted 80 lines · Belen
Quoted 4 lines · On 22/03/2016 15:56, "[email protected] on behalf of Dave…

Target Branch: toaster-next master
Contrib Branch: poky-contrib/dlerner/9121-delete-dependent-package-tree
Defect: 9121

This seems to work like a charm. Thanks!

Belén

Quoted 63 lines

Summary: show and delete recursive list of reverse dependencies

Comment
-------
Version 3: Shorter sanity tests run here. This version 3 is only a rebase against toaster-next. No patches were changed.

Commit
------
aa742e6 toaster: get all dependents for pkg for removal 1c86b2b toaster: new customise package-remove modal dlg 6cff5de toaster: show full list of dependents to remove

.../toaster/toastergui/static/js/customrecipe.js   | 72 +++++++++++++++--
.../toaster/toastergui/templates/customrecipe.html |  5 +-
bitbake/lib/toaster/toastergui/views.py            | 91
+++++++++++++++++++---
3 files changed, 148 insertions(+), 20 deletions(-)

SETUP:
-----
Start toaster with empty build directory, sstate-cache Create a new project, 'myproject'
Build core-image-sato

CASE Remove reverse dependency package that was part of original base image
------------------------------------------------------------------
Create new custom image on core-image-sato, named mysato Remove libcrypto
Verify that "39 packages will be removed" are reported and that the packages are unique and in alpha order
[V3] Verify that the notification shows
"You have removed libcrypto and its 39 reverse dependencies:
gst-player-bin, gstreamer1.0-plugins-bad-dtls, gstreamer1.0-plugins-bad-meta, gstreamer1.0-plugins-bad-opengl, libegl-mesa and 34 more"

CASE Test no interference removing from a 2nd custom image in project
----------------------------------------------------------------------
New custom-image based on core-image-sato 'myminimal'
Build it
Add atk which is dependant on glib-2.0, libffi, libpcre (bash appears but this
is busybox system, so don't think that dependency will apply - maybe bug unrelated to this work).
Build myminimal again.
Verify that atk, libffi, libpcre, glib-2.0 have files in the file system For custom image myminimal, enter libpcre, remove package
Verify modal dlg notes libpcre atk and glib-2.0 will be removed Remove Verify that banner shows
"You have removed 3 packages form myminimal: <strong> libpcre </strong> and its 2 reverse depenencies: atk, glib-2.0"
Build
Verify atk, glib2.0 and libpcre are removed.
--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster

Signature · 3 lines
Elliot Smith
Software Engineer
Intel Open Source Technology Centre