$NetBSD$

--- ../FreeBSD/lib/tc_command.pl	2011-11-20 13:05:28.355724000 +0000
+++ lib/tc_command.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/pkg/bin/perl
 #-
 # Copyright (c) 2004-2008 FreeBSD GNOME Team <freebsd-gnome@FreeBSD.org>
 # All rights reserved.
@@ -188,15 +188,15 @@ my $ds = new Tinderbox::TinderboxDS();
                 help =>
                     "Add a jail to the datastore (do NOT call this directly; use createJail instead)",
                 usage =>
-                    "-j <jail name> -u CSUP|CVSUP|LFTP|SVN|USER|NONE -t <jail tag> [-d <jail description>] [-m <src mount source>] [-a <arch>]",
+                    "-j <jail name> -u GIT|RELEASE|SNAPSHOT|USER|NONE -t <jail tag> [-d <jail description>] [-m <src mount source>] [-a <arch>]",
                 optstr => 'm:j:t:u:d:a:',
         },
         "addPortsTree" => {
                 func => \&addPortsTree,
                 help => "Add a portstree to the datastore",
                 usage =>
-                    "-p <portstree name> -u CSUP|CVSUP|SVN|USER|NONE [-d <portstree description>] [-m <ports mount source>] [-w <CVSweb URL>]",
-                optstr => 'm:p:u:d:w:',
+                    "-p <portstree name> [-t <cvs tag>] [-d <portstree description>] [-m <ports mount source>] [-w <CVSweb URL>]",
+                optstr => 'm:p:u:t:d:w:',
         },
         "addPort" => {
                 help => "Add a port to the datastore",
@@ -240,9 +240,16 @@ my $ds = new Tinderbox::TinderboxDS();
                 func => \&getDependenciesForPort,
                 help => "Get stored dependencies for a given port and build",
                 usage =>
-                    "-b <build name> -d <port directory> [-t EXTRACT_DEPENDS|PATCH_DEPENDS|FETCH_DEPENDS|BUILD_DEPENDS|LIB_DEPENDS|RUN_DEPENDS|TEST_DEPENDS]",
+                    "-b <build name> -d <port directory> [-t EXTRACT_DEPENDS|PATCH_DEPENDS|FETCH_DEPENDS|BUILD_DEPENDS|LIB_DEPENDS|RUN_DEPENDS|TEST_DEPENDS|DEPENDS]",
                 optstr => 'b:d:t:',
         },
+        "getDependencyCascades" => {
+                func => \&getDependencyCascades,
+                help => "Get unique dependencies of port's dependencies, recursively",
+                usage =>
+                    "-b <build name> -d <port directory>",
+                optstr => 'b:d:',
+        },
         "listHooks" => {
                 func => \&listHooks,
                 help =>
@@ -560,15 +567,15 @@ my $ds = new Tinderbox::TinderboxDS();
         "createJail" => {
                 help => "Create a new jail",
                 usage =>
-                    "-j <jailname> -u CSUP|CVSUP|LFTP|SVN|USER|NONE [-t <tag>] [-d <description>] [-C] [-P <protocol>] [-H <updatehost>] [-D <updatehostdirectory>] [-m <mountsrc>] [-I] [-a <arch>]",
-                optstr => 'j:t:d:CP:H:D:m:u:Ia:',
+                    "-j <jailname> -u GIT|RELEASE|SNAPSHOT|USER|NONE -t <tag> [-d <description>] [-H <updatehost>] [-m <mountsrc>] [-I]",
+                optstr => 'j:t:d:H:m:u:I:',
         },
 
         "createPortsTree" => {
                 help => "Create a new portstree",
                 usage =>
-                    "-p <portstreename> -u CSUP|CVSUP|SVN|USER|NONE [-d <description>] [-C] [-P <protocol>] [-H <updatehost>] [-D <updatehostdirectory>] [-m <mountsrc>] [-w <cvsweburl>] [-I]",
-                optstr => 'p:d:CP:H:Im:u:w:',
+                    "-p <portstreename> [-t <cvs tag>] [-d <description>] [-C] [-H <updatehost>] [-m <mountsrc>] [-w <cvsweburl>] [-I]",
+                optstr => 'p:t:d:CH:Im:u:w:',
         },
 
         "createBuild" => {
@@ -592,21 +599,21 @@ my $ds = new Tinderbox::TinderboxDS();
 
         "resetBuild" => {
                 help   => "Cleanup and reset a Build environment",
-                usage  => "-b <buildname> [-n]",
-                optstr => 'b:n',
+                usage  => "-b <buildname>",
+                optstr => 'b:',
         },
 
         "tinderbuild" => {
                 help => "Generate packages from an installed Build",
                 usage =>
-                    "-b <build name> [-init] [-cleanpackages] [-updateports] [-skipmake] [-noclean] [-noduds] [-plistcheck] [-nullfs] [-cleandistfiles] [-fetch-original] [-onceonly] [portdir/portname [...]]",
+                    "-b <build name> [-init] [-cleanpackages] [-updateports] [-skipmake] [-noclean] [-noduds] [-plistcheck] [-cleandistfiles] [-fetch-original] [-onceonly] [portdir/portname [...]]",
                 optstr => 'b:',
         },
 
         "updatePortsTree" => {
                 help   => "Update an existing ports tree",
                 usage  => "-p <portstreename>",
-                optstr => 'p',
+                optstr => 'p:',
         },
 
         "copyBuild" => {
@@ -1489,8 +1496,18 @@ sub addPortsTree {
 sub addPortToOneBuild {
         my $build = $ds->getBuildByName($opts->{'b'});
         my $makecache =
-            new Tinderbox::MakeCache($ENV{'PORTSDIR'}, $ENV{'PKGSUFFIX'});
+            new Tinderbox::MakeCache($ENV{'PORTSDIR'}, $ENV{'OPTNFILE'});
         my @bports = ();
+        my %oper_hash = (
+            EXTRACT_DEPENDS => 'ExtractDepends',
+            PATCH_DEPENDS   => 'PatchDepends',
+            FETCH_DEPENDS   => 'FetchDepends',
+            BUILD_DEPENDS   => 'BuildDepends',
+            LIB_DEPENDS     => 'LibDepends',
+            RUN_DEPENDS     => 'RunDepends',
+            TEST_DEPENDS    => 'TestDepends',
+            DEPENDS         => 'Buildlink3Depends',
+        );
 
         if (!$opts->{'d'}) {
                 foreach my $port ($ds->getPortsForBuild($build)) {
@@ -1502,7 +1519,25 @@ sub addPortToOneBuild {
 
         if ($opts->{'R'}) {
                 foreach my $pdir (@bports) {
-                        addPorts($pdir, $build, $makecache, undef);
+                        my $pCls = addPorts($pdir, $build, $makecache, undef);
+                        $ds->clearDependenciesForPort($pCls, $build, undef);
+                        foreach my $deptype (keys %oper_hash) {
+                                my $oper = $oper_hash{$deptype};
+                                foreach my $dn ($makecache->$oper($pdir)) {
+                                        my $dep = $ds->getPortByDirectory($dn);
+                                        next if (!defined($dep));
+                                        if (
+                                                !$ds->addDependencyForPort(
+                                                        $pCls,    $build,
+                                                        $deptype, $dep
+                                                )
+                                            )
+                                        {
+                                                warn "WARN: Failed to add $deptype entry for $pdir: "
+                                                    . $ds->getError() . "\n";
+                                        }
+                                }
+                        }
                 }
         } else {
                 my @deps = @bports;
@@ -1516,15 +1551,6 @@ sub addPortToOneBuild {
                 }
                 foreach my $port (keys %seen) {
                         my $pCls      = $seen{$port};
-                        my %oper_hash = (
-                                EXTRACT_DEPENDS => 'ExtractDepends',
-                                PATCH_DEPENDS   => 'PatchDepends',
-                                FETCH_DEPENDS   => 'FetchDepends',
-                                BUILD_DEPENDS   => 'BuildDepends',
-                                LIB_DEPENDS     => 'LibDepends',
-                                RUN_DEPENDS     => 'RunDepends',
-                                TEST_DEPENDS    => 'TestDepends',
-                        );
 
                         $ds->clearDependenciesForPort($pCls, $build, undef);
 
@@ -1548,7 +1574,6 @@ sub addPortToOneBuild {
                                 }
                         }
                 }
-
         }
 }
 
@@ -1600,7 +1625,7 @@ sub addBuildPortsQueueEntry {
                     $ds->addBuildPortsQueueEntry($build, $portdir, $priority,
                         $user_id);
                 if (!$rc) {
-                        warn(         "Failed to add port " 
+                        warn(         "Failed to add port "
                                     . $portdir
                                     . " to the datastore: "
                                     . $ds->getError()
@@ -1720,6 +1745,7 @@ sub getDependenciesForPort {
                 LIB_DEPENDS     => 4,
                 RUN_DEPENDS     => 5,
                 TEST_DEPEND     => 6,
+                DEPENDS         => 7,
         );
 
         if (!$opts->{'b'} || !$opts->{'d'}) {
@@ -1773,6 +1799,50 @@ sub getDependenciesForPort {
                 );
         }
 }
+
+sub getDependencyCascades {
+        if (!$opts->{'b'} || !$opts->{'d'}) {
+                usage("getDependencyCascades");
+        }
+
+        my $port = $ds->getPortByDirectory($opts->{'d'});
+        if (!defined($port)) {
+                cleanup($ds, 1,
+                              "Port, "
+                            . $opts->{'d'}
+                            . " is not in the datastore.\n");
+        }
+
+        if (!$ds->isValidBuild($opts->{'b'})) {
+                cleanup($ds, 1, "Unknown build, " . $opts->{'b'} . "\n");
+        }
+
+        my $build = $ds->getBuildByName($opts->{'b'});
+
+        if (!$ds->isPortForBuild($port, $build)) {
+                cleanup($ds, 1,
+                              "Port, "
+                            . $opts->{'d'}
+                            . " is not a valid port for build, "
+                            . $opts->{'b'}
+                            . "\n");
+        }
+
+        my @deps = $ds->getDependencyCascades($port, $build);
+
+        if (@deps) {
+                map { print $_->getDirectory() . "\n" } @deps;
+        } elsif (defined($ds->getError())) {
+                cleanup($ds, 1,
+                        "Failed to get cascading dependencies for this port from the datastore: "
+                            . $ds->getError()
+                            . "\n");
+        } else {
+                cleanup($ds, 0,
+                        "There are no cascading dependencies for this port in the datastore.\n"
+                );
+        }
+}
 
 sub listBuildPortsQueue {
         my $build_filter;
