summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-01-25 22:39:23 +0000
committerdavidovski <david@davidovski.xyz>2022-01-25 22:39:23 +0000
commitbbbade2eb54330c43d2ec938c4fc3ace660851ee (patch)
tree7c714831963bfcfffc0b41afed3fa08b844ba8e1
parent13e29297924facf15bedc440b20d174ab9b9f96c (diff)
added tsorting to find the most important packages
-rwxr-xr-xsrc/xib.pl56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/xib.pl b/src/xib.pl
index 7a677c6..e59a591 100755
--- a/src/xib.pl
+++ b/src/xib.pl
@@ -25,6 +25,7 @@ use strict;
use warnings;
use Getopt::Long "HelpMessage";
use File::Basename;
+use Sort::TSort "tsort";
our $BUILDFILES_REPO = "https://xi.davidovski.xyz/git/buildfiles.git";
@@ -74,7 +75,7 @@ sub list_buildfiles{
return @files;
}
-sub determine_build_order{
+sub get_packages{
my %pkgs = ();
my @files = list_buildfiles();
@@ -83,15 +84,60 @@ sub determine_build_order{
my $pkg_file = $_;
my $pkg_name = basename($pkg_file, ".xibuild");
- my @deps = list_dependencies($pkg_file)
- $pkgs{"$pkg_file"} = @deps;
+ my @deps = list_dependencies($pkg_file);
+ $pkgs{$pkg_name} = \@deps;
+ }
+
+ return %pkgs;
+}
+
+sub get_depended_on{
+ my (%pkgs) = @_;
+ my %depended = ();
+
+ foreach (keys(%pkgs)) {
+ my @empty = ();
+ $depended{$_} = \@empty;
}
- for (keys %pkgs) {
- print("$_ has the deps: $pkgs{$_}\n")
+ foreach (keys(%pkgs)) {
+ my $apkg = $_;
+ foreach (keys(%pkgs)) {
+ my $bpkg = $_;
+ my @deps = @{$pkgs{$_}};
+ if (grep(/^$apkg$/, @deps)) {
+ push(@{$depended{$apkg}}, $bpkg);
+ }
+ }
+ }
+
+ return %depended;
+}
+
+sub determine_build_order{
+ my %pkgs = get_packages();
+
+ my @edges = ();
+ foreach (keys(%pkgs)) {
+ my $pkg = $_;
+ my @deps = @{$pkgs{$_}};
+ foreach (@deps) {
+ my $dep = $_;
+
+ my @edge = ($pkg, $dep);
+ push @edges, [ @edge ];
+
+ }
+ }
+
+ my $sorted = tsort(\@edges);
+
+ foreach(@{$sorted}) {
+ print("$_\n");
}
}
+
unless (caller) {
prepare_xib_environment();
determine_build_order();