r15287: Simplify dependency detection code
authorJelmer Vernooij <jelmer@samba.org>
Wed, 26 Apr 2006 16:31:40 +0000 (16:31 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:05:02 +0000 (14:05 -0500)
source/build/smb_build/dot.pl
source/build/smb_build/input.pm
source/build/smb_build/output.pm

index 6abb5bdb43961ffda31efe6b7e8f2368752f532c..898d2cd0ffb26a9c96881bd5c7a3b843ffa454fc 100755 (executable)
@@ -13,7 +13,8 @@ sub generate($)
        my $res = "digraph samba4 {\n";
 
        foreach my $part (values %{$depend}) {
-               foreach my $elem (@{$part->{REQUIRED_SUBSYSTEMS}}) {
+               foreach my $elem (@{$part->{PUBLIC_DEPENDENCIES}},
+                                 @{$part->{PRIVATE_DEPENDENCIES}}) {
                        $res .= "\t\"$part->{NAME}\" -> \"$elem\";\n";
                }
        }
index bb664f863545c5454ff5b87eac6a916b2cf37f8a..a4640df9622ae3833d0af6ccdf33c2809a45de29 100644 (file)
@@ -118,29 +118,35 @@ sub check_binary($$)
        $bin->{OUTPUT_TYPE} = "BINARY";
 }
 
-my $level = "";
-
-sub calc_unique_deps($$$$)
+sub calc_unique_deps($$$$$$)
 {
-       sub calc_unique_deps($$$$);
-       my ($name, $deps, $udeps, $withlibs) = @_;
-
-       print "$level-> $name\n" if ($ENV{SMB_BUILD_VERBOSE});
-       $level.=" ";
+       sub calc_unique_deps($$$$$$);
+       my ($name, $INPUT, $deps, $udeps, $withlibs, $busy) = @_;
 
-       foreach my $dep (@{$deps}) {
-               next if defined($udeps->{$$dep->{NAME}});
-
-               if (defined ($$dep->{OUTPUT_TYPE}) && 
-                       ($withlibs or ($$dep->{OUTPUT_TYPE} eq "OBJ_LIST") or ($$dep->{OUTPUT_TYPE} eq "MERGEDOBJ") or ($$dep->{OUTPUT_TYPE} eq "STATIC_LIBRARY"))) {
-                               $udeps->{$$dep->{NAME}} = "BUSY";
-                               calc_unique_deps($$dep->{NAME}, $$dep->{DEPENDENCIES}, $udeps, $withlibs);
+       foreach my $n (@$deps) {
+               if (grep (/^$n$/, @$busy)) {
+                       print "($name) BUSY: $n, list: " . join(',', @$busy) . "\n";
+               #       die("Recursive dependency for $dep->{NAME}");
+                       next;
+               }
+               next if (grep /^$n$/, @$udeps);
+               my $dep = $INPUT->{$n};
+
+               if (defined ($dep->{OUTPUT_TYPE}) && 
+                       ($withlibs or 
+                       ($dep->{OUTPUT_TYPE} eq "OBJ_LIST") or 
+                       ($dep->{OUTPUT_TYPE} eq "MERGEDOBJ") or 
+                       ($dep->{OUTPUT_TYPE} eq "STATIC_LIBRARY"))) {
+                               push (@$busy, $dep->{NAME});
+                               calc_unique_deps($dep->{NAME}, $INPUT, $dep->{PUBLIC_DEPENDENCIES}, $udeps, $withlibs, $busy);
+                               calc_unique_deps($dep->{NAME}, $INPUT, $dep->{PRIVATE_DEPENDENCIES}, $udeps, $withlibs, $busy);
+                               pop (@$busy);
                }
 
-               $udeps->{$$dep->{NAME}} = $$dep;
+               # FIXME: Insert at the right position
+               push (@{$udeps}, $dep->{NAME});
+
        }
-       
-       $level = substr($level, 1);
 }
 
 sub check($$$$$)
@@ -191,31 +197,19 @@ sub check($$$$$)
                check_binary($INPUT, $part) if ($part->{TYPE} eq "BINARY");
        }
 
-       my %depend = %$INPUT;
-
-       foreach my $part (values %depend) {
-               
-               # Generate list of dependencies
-               $part->{DEPENDENCIES} = [];
-
-               foreach my $key (@{$part->{PUBLIC_DEPENDENCIES}},
-                                @{$part->{PRIVATE_DEPENDENCIES}}) {
-                       die("$part->{NAME} has undefined dependency $key\n") if not defined($depend{$key});
-                       push (@{$part->{DEPENDENCIES}}, \$depend{$key});
-               }
-       }
-
-       foreach my $part (values %depend) {
-               $part->{UNIQUE_DEPENDENCIES} = {};
-               calc_unique_deps($part->{NAME}, $part->{DEPENDENCIES}, $part->{UNIQUE_DEPENDENCIES}, 0);
+       foreach my $part (values %$INPUT) {
+               $part->{UNIQUE_DEPENDENCIES} = [];
+               calc_unique_deps($part->{NAME}, $INPUT, $part->{PUBLIC_DEPENDENCIES}, $part->{UNIQUE_DEPENDENCIES}, 0, []);
+               calc_unique_deps($part->{NAME}, $INPUT, $part->{PRIVATE_DEPENDENCIES}, $part->{UNIQUE_DEPENDENCIES}, 0, []);
        }
 
-       foreach my $part (values %depend) {
-               $part->{UNIQUE_DEPENDENCIES_ALL} = {};
-               calc_unique_deps($part->{NAME}, $part->{DEPENDENCIES}, $part->{UNIQUE_DEPENDENCIES_ALL}, 1);
+       foreach my $part (values %$INPUT) {
+               $part->{UNIQUE_DEPENDENCIES_ALL} = [];
+               calc_unique_deps($part->{NAME}, $INPUT, $part->{PUBLIC_DEPENDENCIES}, $part->{UNIQUE_DEPENDENCIES_ALL}, 1, []);
+               calc_unique_deps($part->{NAME}, $INPUT, $part->{PRIVATE_DEPENDENCIES}, $part->{UNIQUE_DEPENDENCIES_ALL}, 1, []);
        }
 
-       return \%depend;
+       return $INPUT;
 }
 
 1;
index a53a9263f9772c4724b53e667f1d1b886d90649e..de122ee9a08142a08020d3e8b9d16e7d56068234 100644 (file)
@@ -147,7 +147,8 @@ sub create_output($$)
        foreach $part (values %{$depend}) {
                next if not defined($part->{OUTPUT_TYPE});
 
-               foreach my $elem (values %{$part->{UNIQUE_DEPENDENCIES_ALL}}) {
+               foreach (@{$part->{UNIQUE_DEPENDENCIES_ALL}}) {
+                       my $elem = $depend->{$_};
                        next if $elem == $part;
 
                        push(@{$part->{PUBLIC_CFLAGS}}, @{$elem->{CPPFLAGS}}) if defined(@{$elem->{CPPFLAGS}});
@@ -156,7 +157,8 @@ sub create_output($$)
 
 
                # Always import the CFLAGS and CPPFLAGS of the unique dependencies
-               foreach my $elem (values %{$part->{UNIQUE_DEPENDENCIES}}) {
+               foreach (@{$part->{UNIQUE_DEPENDENCIES}}) {
+                       my $elem = $depend->{$_};
                        next if $elem == $part;
 
                        push(@{$part->{LINK_LIST}}, $elem->{OUTPUT}) if defined($elem->{OUTPUT});