Compare commits

...

3 Commits

Author SHA1 Message Date
Ettore Di Giacinto 2c05cdce52 Merge pull request #6 from optiz0r/feature_package_deps_cache
Cache results of package_deps and re-enable virtual dep stripping
2016-03-20 21:01:57 +01:00
Ben Roberts a55856cb97 Revert to using locally defined uniq 2016-03-20 19:59:56 +00:00
Ben Roberts 967cd9708a Cache results of package_deps and re-enable virtual dep stripping
It's likely that some virtuals are dependencies of multiple package arguments
to builder and the depgraph would be queried multiple times. This commit
caches the results to avoid expensive duplicate shell execs and optimise for
speed.

Additionally, when calls to equery depgraph match multiple packages (e.g.
the query is for an unversioned atom, and multiple versions exist in the
portage tree), the results for all versions are returned, resulting in
duplicates. This change also strips out the duplicate entries so further
work need only be done once.

This uses perl 5.10's `state` variables, so adds the appropriate use. Since
Sabayon ships only perl 5.20, this should not be an issue.
2016-03-20 19:43:20 +00:00
+37 -16
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env perl #!/usr/bin/env perl
use Getopt::Long; use Getopt::Long;
use v5.10;
my $profile = $ENV{BUILDER_PROFILE} // 3; my $profile = $ENV{BUILDER_PROFILE} // 3;
my $jobs = $ENV{BUILDER_JOBS} // 1; my $jobs = $ENV{BUILDER_JOBS} // 1;
@@ -42,9 +43,30 @@ sub package_deps {
my $package = shift; my $package = shift;
my $depth = shift // 1; # defaults to 1 level of depthness of the tree my $depth = shift // 1; # defaults to 1 level of depthness of the tree
my $atom = shift // 0; my $atom = shift // 0;
return
map { $_ =~ s/\[.*\]|\s//g; &atom($_) if $atom; $_ } # Since we expect this sub to be called multiple times with the same arguments, cache the results
qx/equery -C -q g --depth=$depth $package/; #depth=0 it's all state %cache;
$cache_key = "${package}:${depth}:${atom}";
if ( ! exists $cache{$cache_key} ) {
@dependencies = qx/equery -C -q g --depth=$depth $package/; #depth=0 it's all
chomp @dependencies;
# If an unversioned atom is given, equery returns results for all versions in the portage tree
# leading to duplicates. The sanest thing to do is dedup the list. This gives the superset of all
# possible dependencies, which isn't perfectly accurate but should be good enough. For completely
# accurate results, pass in a versioned atom.
@dependencies =
uniq
sort
grep { $_ }
map { $_ =~ s/\[.*\]|\s//g; &atom($_) if $atom; $_ }
@dependencies;
$cache{$cache_key} = \@dependencies;
}
return @{ $cache{$cache_key} };
} }
#Input: nothing #Input: nothing
@@ -71,18 +93,17 @@ sub calculate_missing {
say "[$package] Getting the package dependencies and the installed packages"; say "[$package] Getting the package dependencies and the installed packages";
my @dependencies = package_deps( $package, $depth, 1 ); my @dependencies = package_deps( $package, $depth, 1 );
# XXX: Endless loop as for now. my %install_dependencies = map { $_ => 1 } @dependencies;
# my %install_dependencies = map { $_ => 1 } @dependencies; # Look for any virtuals and remove its immediate dependencies to avoid
# # Look for any virtuals and remove its immediate dependencies to avoid # installing multiple conflicting packages one by one
# # installing multiple conflicting packages one by one my @virtual_deps;
# my @virtual_deps; for my $dep (@dependencies) {
# for my $dep (@dependencies) { push(@virtual_deps, package_deps( $dep, 1, 1 )) if ( $dep =~ /^virtual\// );
# push(@virtual_deps, package_deps( $dep, 1, 1 )) if ( $dep =~ /^virtual\// ); }
# } for my $dep (@virtual_deps) {
# for my $dep (@virtual_deps) { $install_dependencies{$dep} = 0 if ( $dep !~ /^virtual\// );
# $install_dependencies{$dep} = 0 if ( $dep !~ /^virtual\// ); }
# } @dependencies = grep { $install_dependencies{$_} } @dependencies;
# @dependencies = grep { $install_dependencies{$_} } @dependencies;
#taking only the 4th column of output as key of the hashmap #taking only the 4th column of output as key of the hashmap
my %installed_packs = my %installed_packs =
@@ -93,7 +114,7 @@ sub calculate_missing {
my @to_install = grep( defined $available_packs{$_}, my @to_install = grep( defined $available_packs{$_},
uniq( grep( !defined $installed_packs{$_}, @dependencies ) ) ); uniq( grep( !defined $installed_packs{$_}, @dependencies ) ) );
@to_install=grep { length } @to_install; @to_install=grep { length } @to_install;
# say "[$package] packages that will be installed with equo: @to_install" if @to_install>0; say "[$package] packages that will be installed with equo: @to_install" if @to_install>0;
return @to_install; return @to_install;
} }