about summary refs log tree commit diff
path: root/corepkgs
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-12-04T13·45+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-12-04T13·45+0100
commit56d29dcd62ff5ff65b24da335a5119179c191806 (patch)
treeb1a87b530a41fe877ea2a39dab19bcfd385263ea /corepkgs
parent2d5e8e267b58f531f00b043c9e3dbaefad62a4a1 (diff)
buildenv.pl: Create symlinks in priority order
This reduces unnecessary symlink/unlink steps.
Diffstat (limited to 'corepkgs')
-rw-r--r--corepkgs/buildenv.pl21
1 files changed, 12 insertions, 9 deletions
diff --git a/corepkgs/buildenv.pl b/corepkgs/buildenv.pl
index ea517687bd..fd564e0275 100644
--- a/corepkgs/buildenv.pl
+++ b/corepkgs/buildenv.pl
@@ -78,10 +78,10 @@ sub createLinks {
             if (-l $dstFile) {
                 my $target = readlink $dstFile;
                 my $prevPriority = $priorities{$dstFile};
-                die ( "Collission between `$srcFile' and `$target'. "
-                    . "Suggested solution: use `nix-env --set-flag "
+                die ( "collission between `$srcFile' and `$target'; "
+                    . "use `nix-env --set-flag "
                     . "priority NUMBER PKGNAME' to change the priority of "
-                    . "one of the conflicting packages.\n" )
+                    . "one of the conflicting packages\n" )
                     if $prevPriority == $priority;
                 next if $prevPriority < $priority;
                 unlink $dstFile or die;
@@ -125,7 +125,7 @@ sub addPkg {
 
 # Convert the stuff we get from the environment back into a coherent
 # data type.
-my %pkgs;
+my @pkgs;
 my @derivations = split ' ', $ENV{"derivations"};
 while (scalar @derivations) {
     my $active = shift @derivations;
@@ -133,18 +133,21 @@ while (scalar @derivations) {
     my $outputs = shift @derivations;
     for (my $n = 0; $n < $outputs; $n++) {
         my $path = shift @derivations;
-        $pkgs{$path} =
-            { active => $active ne "false"
+        push @pkgs,
+            { path => $path
+            , active => $active ne "false"
             , priority => int($priority) };
     }
 }
 
 
 # Symlink to the packages that have been installed explicitly by the
-# user.
-foreach my $pkg (sort (keys %pkgs)) {
+# user.  Process in priority order to reduce unnecessary
+# symlink/unlink steps.
+@pkgs = sort { $a->{priority} <=> $b->{priority} || $a->{path} cmp $b->{path} } @pkgs;
+foreach my $pkg (@pkgs) {
     #print $pkg, " ", $pkgs{$pkg}->{priority}, "\n";
-    addPkg($pkg, $pkgs{$pkg}->{priority}) if $pkgs{$pkg}->{active};
+    addPkg($pkg->{path}, $pkg->{priority}) if $pkg->{active};
 }