Skip to contentSkip to conversation

support/scripts/graph-depends cleanup done_deps global

PATCH In review Steve Hay via buildroot 2 participants 6 messages Jan 22, 2023 – Jan 23, 2023 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 support/scripts/graph-depends cleanup done_deps global

From: Steve <[email protected]>

---
 support/scripts/graph-depends | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
support/scripts/graph-depends +4 -5
index a66fb28f41..3e3373950f 100755
@@ -197,12 +197,11 @@ def print_attrs(outfile, pkg, pkg_type, pkg_version, depth, colors):
     outfile.write("%s [color=%s,style=filled]\n" % (name, color))
 
 
-done_deps = []
-
-
 # Print the dependency graph of a package
 def print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                   arrow_dir, draw_graph, depth, max_depth, pkg, colors):
+                   arrow_dir, draw_graph, depth, max_depth, pkg, colors, done_deps=None):
+    if done_deps is None:
+        done_deps = []
     if pkg in done_deps:
         return
     done_deps.append(pkg)
@@ -234,7 +233,7 @@ def print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exc
                 if draw_graph:
                     outfile.write("%s -> %s [dir=%s]\n" % (pkg_node_name(pkg), pkg_node_name(d), arrow_dir))
                 print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                               arrow_dir, draw_graph, depth + 1, max_depth, d, colors)
+                               arrow_dir, draw_graph, depth + 1, max_depth, d, colors, done_deps)
 
 
 def parse_args():
Signature · 6 lines
2.30.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 2/2 support/scripts/graph-depends allow for forward and reverse depends on same graph

---
 support/scripts/graph-depends | 55 +++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 16 deletions(-)
support/scripts/graph-depends +39 -16
index 3e3373950f..91aaf5d867 100755
@@ -159,11 +159,11 @@ def check_circular_deps(deps):
 
 # This functions trims down the dependency list of all packages.
 # It applies in sequence all the dependency-elimination methods.
-def remove_extra_deps(deps, rootpkg, transitive, arrow_dir):
+def remove_extra_deps(deps, rootpkg, transitive, direct):
     # For the direct dependencies, find and eliminate mandatory
     # deps, and add them to the root package. Don't do it for a
     # reverse graph, because mandatory deps are only direct deps.
-    if arrow_dir == "forward":
+    if direct:
         for pkg in list(deps.keys()):
             if not pkg == rootpkg:
                 for d in get_mandatory_deps(pkg, deps):
@@ -197,14 +197,16 @@ def print_attrs(outfile, pkg, pkg_type, pkg_version, depth, colors):
     outfile.write("%s [color=%s,style=filled]\n" % (name, color))
 
 
+
 # Print the dependency graph of a package
 def print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                   arrow_dir, draw_graph, depth, max_depth, pkg, colors, done_deps=None):
+                   direct, draw_graph, depth, max_depth, pkg, colors, done_deps=None):
     if done_deps is None:
         done_deps = []
     if pkg in done_deps:
         return
     done_deps.append(pkg)
+
     if draw_graph:
         print_attrs(outfile, pkg, dict_types[pkg], dict_versions[pkg], depth, colors)
     elif depth != 0:
@@ -231,9 +233,12 @@ def print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exc
                     break
             if add:
                 if draw_graph:
-                    outfile.write("%s -> %s [dir=%s]\n" % (pkg_node_name(pkg), pkg_node_name(d), arrow_dir))
+                    if direct:
+                        outfile.write("%s -> %s [dir=%s]\n" % (pkg_node_name(pkg), pkg_node_name(d), "forward"))
+                    else:
+                        outfile.write("%s -> %s [dir=%s]\n" % (pkg_node_name(d), pkg_node_name(pkg), "forward"))
                 print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                               arrow_dir, draw_graph, depth + 1, max_depth, d, colors, done_deps)
+                               direct, draw_graph, depth + 1, max_depth, d, colors, done_deps)
 
 
 def parse_args():
@@ -246,6 +251,8 @@ def parse_args():
                         help="Graph the dependencies of PACKAGE")
     parser.add_argument("--depth", '-d', metavar="DEPTH", dest="depth", type=int, default=0,
                         help="Limit the dependency graph to DEPTH levels; 0 means no limit.")
+    parser.add_argument("--rdepth", metavar="RDEPTH", dest="rdepth", type=int, default=0,
+                        help="Limit the dependency graph to DEPTH levels; 0 means no limit.")
     parser.add_argument("--stop-on", "-s", metavar="PACKAGE", dest="stop_list", action="append",
                         help="Do not graph past this package (can be given multiple times)." +
                         " Can be a package name or a glob, " +
@@ -267,7 +274,7 @@ def parse_args():
                         help="Draw (do not draw) transitive dependencies")
     parser.add_argument("--direct", dest="direct", action='store_true', default=True,
                         help="Draw direct dependencies (the default)")
-    parser.add_argument("--reverse", dest="direct", action='store_false',
+    parser.add_argument("--reverse", dest="reverse", action='store_true', default=False,
                         help="Draw reverse dependencies")
     parser.add_argument("--quiet", '-q', dest="quiet", action='store_true',
                         help="Quiet")
@@ -330,21 +337,37 @@ def main():
         logging.error("Error: incorrect color list '%s'" % args.colors)
         sys.exit(1)
 
-    deps, rdeps, dict_types, dict_versions = brpkgutil.get_dependency_tree()
-    dict_deps = deps if args.direct else rdeps
-
-    check_circular_deps(dict_deps)
-    if check_only:
-        sys.exit(0)
-
-    dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, arrow_dir)
 
     # Start printing the graph data
     if draw_graph:
         outfile.write("digraph G {\n")
 
-    print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                   arrow_dir, draw_graph, 0, args.depth, rootpkg, colors)
+
+    deps, rdeps, dict_types, dict_versions = brpkgutil.get_dependency_tree()
+
+    # forward
+    if args.direct:
+        dict_deps = deps
+        direct = True
+        #arrow_dir = "forward" # hack
+        check_circular_deps(dict_deps)
+        if check_only:
+            sys.exit(0)
+        dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, direct)
+        print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
+                       direct, draw_graph, 0, args.depth, rootpkg, colors)
+
+    # reverse
+    if args.reverse:
+        dict_deps = rdeps
+        direct = False
+        #arrow_dir = "back" # hack
+        check_circular_deps(dict_deps)
+        if check_only:
+            sys.exit(0)
+        dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, direct)
+        print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
+                       direct, draw_graph, 0, args.depth, rootpkg, colors)
 
     if draw_graph:
         outfile.write("}\n")
Signature · 6 lines
2.30.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 2/2] support/scripts/graph-depends allow for forward and reverse depends on same graph

Steve, All,

On 2023-01-23 00:43 +0100, Steve Hay via buildroot spake thusly:

Quoted 1 line

Please write a commit log that explains the change (don't describe it. explain it): as you could see from our discussion on IRC, the title of your commit is not enough to understand what you are trying to achieve.

Maybe explain that it tries to represent both forward and backward dependencies of a single package, with a little schema (here for pkg D):

    $ make pkg-d-graph-both-depends
    pkg A -.            .-> pkg E
            \          /
    pkg B ----> pkg D ----> pkg F
            /          \
    pkg C -'            '-> pkg G

Also, please insert this in the current package rules:

    $ make help
    [...]
    Package-specific:
      <pkg>                  - Build and install <pkg> and all its dependencies
      <pkg>-source           - Only download the source files for <pkg>
  [...]
      <pkg>-show-depends     - List packages on which <pkg> depends
      <pkg>-show-rdepends    - List packages which have <pkg> as a dependency
      <pkg>-show-recursive-depends
                             - Recursively list packages on which <pkg>
                               depends
      <pkg>-show-recursive-rdepends
                             - Recursively list packages which have <pkg> as
                               a dependency
      <pkg>-graph-depends    - Generate a graph of <pkg>'s dependencies
      <pkg>-graph-rdepends   - Generate a graph of <pkg>'s reverse dependencies
      <pkg>-graph-both-depends
                             - Generate a graph of both <pkg>'s forward and
                               reverse dependencies
      <pkg>-dirclean         - Remove <pkg> build directory
    [...]

support/scripts/graph-depends

Quoted 8 lines
---
 support/scripts/graph-depends | 55 +++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 16 deletions(-)
support/scripts/graph-depends +0 -0
index 3e3373950f..91aaf5d867 100755

[--SNIP--]

support/scripts/graph-depends def parse_args(): · line 255

Quoted 6 lines
support/scripts/graph-depends +2 -0
@@ -246,6 +251,8 @@ def parse_args():
                         help="Graph the dependencies of PACKAGE")
     parser.add_argument("--depth", '-d', metavar="DEPTH", dest="depth", type=int, default=0,
                         help="Limit the dependency graph to DEPTH levels; 0 means no limit.")
+    parser.add_argument("--rdepth", metavar="RDEPTH", dest="rdepth", type=int, default=0,
+                        help="Limit the dependency graph to DEPTH levels; 0 means no limit.")

Do we really need to have two different options for the direct and reverse depths?

If so, then be sure to modify the <pkg>-graph-rdepends accordingly (in package/pkg-generic).

[--SNIP--]

Quoted 20 lines
support/scripts/graph-depends +1 -10
@@ -330,21 +337,37 @@ def main():
         logging.error("Error: incorrect color list '%s'" % args.colors)
         sys.exit(1)
 
-    deps, rdeps, dict_types, dict_versions = brpkgutil.get_dependency_tree()
-    dict_deps = deps if args.direct else rdeps
-
-    check_circular_deps(dict_deps)
-    if check_only:
-        sys.exit(0)
-
-    dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, arrow_dir)
 
     # Start printing the graph data
     if draw_graph:
         outfile.write("digraph G {\n")
 
-    print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                   arrow_dir, draw_graph, 0, args.depth, rootpkg, colors)
+

support/scripts/graph-depends def main(): · line 355

Quoted 10 lines
support/scripts/graph-depends +10 -0
+    deps, rdeps, dict_types, dict_versions = brpkgutil.get_dependency_tree()
+
+    # forward
+    if args.direct:
+        dict_deps = deps
+        direct = True
+        #arrow_dir = "forward" # hack
+        check_circular_deps(dict_deps)
+        if check_only:
+            sys.exit(0)

I am not very fond of this: if one were to call:

    $ graph-depends --direct --reverse --check-only

then one would expect to have both checks be run, but here only the direct one will be.

I think we need to change check_circular_deps() to return False (no circular dependencies) or True (circular dependencies) (or it can raise an exception that we catch) and store that for later concumption.

    circ_deps = []

    if args.direct:
        if check_circular_deps(...):
            circ_deps.append('direct')
        if not args.checkonly:
            dict_deps = remove_extra_deps(...)
            print_pkg_deps(...)

    if args.reverse:
        if check_circular_deps(...):
            circ_deps.append('reverse')
        if not args.checkonly:
            dict_deps = remove_extra_deps(...)
            print_pkg_deps(...)

    if circ_deps:
        print(f"Bummer: circular {' and '.join(circ_deps)} dependencies detected")
        os.exit(1)

Something along those lines...

Regards,
Yann E. MORIN.

Quoted 25 lines
support/scripts/graph-depends +15 -0
+        dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, direct)
+        print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
+                       direct, draw_graph, 0, args.depth, rootpkg, colors)
+
+    # reverse
+    if args.reverse:
+        dict_deps = rdeps
+        direct = False
+        #arrow_dir = "back" # hack
+        check_circular_deps(dict_deps)
+        if check_only:
+            sys.exit(0)
+        dict_deps = remove_extra_deps(dict_deps, rootpkg, args.transitive, direct)
+        print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
+                       direct, draw_graph, 0, args.depth, rootpkg, colors)
 
     if draw_graph:
         outfile.write("}\n")
Signature · 6 lines
2.30.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

Re: [Buildroot] [PATCH 2/2] support/scripts/graph-depends allow for forward and reverse depends on same graph

Yann, All,

Quoted 5 lines · Yann E. MORIN

Do we really need to have two different options for the direct and reverse depths?

If so, then be sure to modify the <pkg>-graph-rdepends accordingly (in package/pkg-generic).

I think it is nice to have the "control knob" available for both, but the current API to this script uses default values of 0 (no limit) in all cases--so no change to <pkg>-graph-rdepends is needed. I've added the ability to specify depth to the makefile.

Quoted 9 lines

I am not very fond of this: if one were to call:

     $ graph-depends --direct --reverse --check-only

then one would expect to have both checks be run, but here only the direct one will be.

I think we need to change check_circular_deps() to return False (no circular dependencies) or True (circular dependencies) (or it can raise an exception that we catch) and store that for later concumption.

I agree that it should check both and have updated the script so that it does, but I'd rather the enhancements you're talking about be handled with a separate patch.

Revised patch forthcoming.

Steve

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw
In reply to Steve Hay via buildroot

Steve, All,

Thanks for this patch, here a quick review.

On 2023-01-23 00:43 +0100, Steve Hay via buildroot spake thusly:

Quoted 1 line

From: Steve <[email protected]>

Please use you full name as author (not just your first name).

Please provide a (potentially terse) explanation for the change.

Quoted 10 lines
---
 support/scripts/graph-depends | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
support/scripts/graph-depends +0 -0
index a66fb28f41..3e3373950f 100755

support/scripts/graph-depends def print_attrs(outfile, pkg, pkg_type, pkg_version, depth, colors): · line 202

Quoted 10 lines
support/scripts/graph-depends +1 -4
@@ -197,12 +197,11 @@ def print_attrs(outfile, pkg, pkg_type, pkg_version, depth, colors):
     outfile.write("%s [color=%s,style=filled]\n" % (name, color))
 
 
-done_deps = []
-
-
 # Print the dependency graph of a package
 def print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                   arrow_dir, draw_graph, depth, max_depth, pkg, colors):
+                   arrow_dir, draw_graph, depth, max_depth, pkg, colors, done_deps=None):

Make the default be the empty list: done_deps=[]

support/scripts/graph-depends def print_attrs(outfile, pkg, pkg_type, pkg_version, depth, colors): · line 204

Quoted 2 lines
support/scripts/graph-depends +2 -0
+    if done_deps is None:
+        done_deps = []

... which allows to drop this conditional.

I was wondering how that could work, as the list is now a parameter, but the list is not passed as a copy, it is passed as a "reference" in python... So yes, it works (the .dot are the same before/after).

Regards,
Yann E. MORIN.

Quoted 19 lines
support/scripts/graph-depends +1 -1
     if pkg in done_deps:
         return
     done_deps.append(pkg)
@@ -234,7 +233,7 @@ def print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exc
                 if draw_graph:
                     outfile.write("%s -> %s [dir=%s]\n" % (pkg_node_name(pkg), pkg_node_name(d), arrow_dir))
                 print_pkg_deps(outfile, dict_deps, dict_types, dict_versions, stop_list, exclude_list,
-                               arrow_dir, draw_graph, depth + 1, max_depth, d, colors)
+                               arrow_dir, draw_graph, depth + 1, max_depth, d, colors, done_deps)
 
 
 def parse_args():
Signature · 6 lines
2.30.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Yann, All,

Thank you.

Quoted 6 lines · Yann E. MORIN
Quoted 5 lines

On 2023-01-23 00:43 +0100, Steve Hay via buildroot spake thusly:

Quoted 1 line

From: Steve <[email protected]>

Please use you full name as author (not just your first name).

Please provide a (potentially terse) explanation for the change.

I don't know why the git client did that with my first name. I will try to fix it.

Quoted 1 line
Quoted 1 line

Make the default be the empty list: done_deps=[]

I don't think this works because it essentially moves the global list into the Python interpreter:

https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot