[Midnightbsd-cvs] mports: Utils.pm: recurse_ports used to take around 4m40s to run.
ctriv at midnightbsd.org
ctriv at midnightbsd.org
Sat Sep 8 22:20:48 EDT 2007
Log Message:
-----------
recurse_ports used to take around 4m40s to run. This optimization is a
little hacky, but I got the time down to around 5s.
Modified Files:
--------------
mports/Tools/lib/Mport:
Utils.pm (r1.2 -> r1.3)
-------------- next part --------------
Index: Utils.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Mport/Utils.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -LTools/lib/Mport/Utils.pm -LTools/lib/Mport/Utils.pm -u -r1.2 -r1.3
--- Tools/lib/Mport/Utils.pm
+++ Tools/lib/Mport/Utils.pm
@@ -39,15 +39,33 @@
chdir($cwd);
- my @dirs = make_var('SUBDIR');
+ # Calling make is expensive. Only do so if we need to.
+ if (-e 'pkg-descr' || -e 'pkg-plist') {
+ return $code->($cwd);
+ }
- if (@dirs) {
- foreach my $dir (@dirs) {
- _do_recurse($code, "$cwd/$dir");
+ # it is actually much faster to check if it is a dir makefile than to call
+ # make and ask.
+ open(my $make, '<', "Makefile") || die "Couldn't open $cwd/Makefile: $!\n";
+ while (<$make>) {
+ if (m/bsd.port.subdir.mk/) {
+ my @dirs = make_var('SUBDIR');
+ # close the filehandle before we recurse.
+ close($make);
+ if (@dirs) {
+ foreach my $dir (@dirs) {
+ _do_recurse($code, "$cwd/$dir");
+ }
+ }
+
+ # we're done with this makefile.
+ return;
}
- } else {
- $code->($cwd);
}
+
+ # must be a real port!
+ close($make);
+ $code->($cwd);
}
1;
More information about the Midnightbsd-cvs
mailing list