diff options
-rw-r--r-- | Debian/Debhelper/Dh_Lib.pm | 12 | ||||
-rw-r--r-- | doc/PROGRAMMING | 10 |
2 files changed, 16 insertions, 6 deletions
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index 6a5904fe..26a8341d 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -52,7 +52,7 @@ use vars qw(@EXPORT %dh); &restore_file_on_clean &restore_all_files &open_gz &reset_perm_and_owner &deprecated_functionality &log_installed_files &buildarch &rename_path - &on_pkgs_in_parallel + &on_pkgs_in_parallel &on_selected_pkgs_in_parallel ); # The Makefile changes this if debhelper is installed in a PREFIX. @@ -1608,9 +1608,15 @@ sub log_installed_files { return 1; } + sub on_pkgs_in_parallel(&) { - my ($code) = @_; - my @pkgs = @{$dh{DOPACKAGES}}; + unshift(@_, $dh{DOPACKAGES}); + goto \&on_selected_pkgs_in_parallel; +} + +sub on_selected_pkgs_in_parallel { + my ($pkgs_ref, $code) = @_; + my @pkgs = @{$pkgs_ref}; my %pids; my $parallel = $MAX_PROCS; my $count_per_proc = int(scalar(@pkgs) / $parallel); diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING index 1827811f..5d1b6220 100644 --- a/doc/PROGRAMMING +++ b/doc/PROGRAMMING @@ -358,20 +358,24 @@ log_installed_files($package, @paths) If a directory is listed, it and all paths recursively beneath is also considered installed. on_pkgs_in_parallel($code) - prototype: (&) - Splits all the packages in $dh{DOPACKAGES} into a number of groups + Short hand for on_selected_pkgs_in_parallel with $dh{DOPACKAGES} as + as list of packages. +on_selected_pkgs_in_parallel($pkg_list_ref, $code) + Splits all the packages in $pkg_list_ref into a number of groups based on the max parallel (as decided by DEB_BUILD_OPTIONS) A subprocess is forked for each group (minimum 1 process will be forked) and each subprocess will be added a group of packages to process. Each group is passed to the $code sub, which will then process it and return normally on success. Example: - on_pkgs_in_parallel { + my @all_packages = getpackages(); + on_selected_pkgs_in_parallel(\@all_packages, sub { for my $package (@_) { my $tmp=tmpdir($package); my $pkgfile = pkgfile($package, 'foo'); ...; } - } + }); Keep in mind that the sub will always be run in a subprocess, so it cannot update global state. |