buildEnv: builder.pl: use signature and move the ignoreSingleFileOutputs parameter after the collision-related ones (#364203)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#! @perl@ -w
|
||||
|
||||
use strict;
|
||||
use feature 'signatures';
|
||||
use Cwd 'abs_path';
|
||||
use IO::Handle;
|
||||
use File::Path;
|
||||
@@ -18,8 +19,7 @@ my $extraPrefix = $ENV{"extraPrefix"};
|
||||
|
||||
my @pathsToLink = split ' ', $ENV{"pathsToLink"};
|
||||
|
||||
sub isInPathsToLink {
|
||||
my $path = shift;
|
||||
sub isInPathsToLink($path) {
|
||||
$path = "/" if $path eq "";
|
||||
foreach my $elem (@pathsToLink) {
|
||||
return 1 if
|
||||
@@ -32,8 +32,7 @@ sub isInPathsToLink {
|
||||
|
||||
# Returns whether a path in one of the linked packages may contain
|
||||
# files in one of the elements of pathsToLink.
|
||||
sub hasPathsToLink {
|
||||
my $path = shift;
|
||||
sub hasPathsToLink($path) {
|
||||
foreach my $elem (@pathsToLink) {
|
||||
return 1 if
|
||||
$path eq "" ||
|
||||
@@ -44,8 +43,7 @@ sub hasPathsToLink {
|
||||
}
|
||||
|
||||
# Similar to `lib.isStorePath`
|
||||
sub isStorePath {
|
||||
my $path = shift;
|
||||
sub isStorePath($path) {
|
||||
my $storePath = "@storeDir@";
|
||||
|
||||
return substr($path, 0, 1) eq "/" && dirname($path) eq $storePath;
|
||||
@@ -76,22 +74,18 @@ for my $p (@pathsToLink) {
|
||||
|
||||
sub findFiles;
|
||||
|
||||
sub findFilesInDir {
|
||||
my ($relName, $target, $ignoreCollisions, $ignoreSingleFileOutputs, $checkCollisionContents, $priority) = @_;
|
||||
|
||||
sub findFilesInDir($relName, $target, $ignoreCollisions, $checkCollisionContents, $priority, $ignoreSingleFileOutputs) {
|
||||
opendir DIR, "$target" or die "cannot open `$target': $!";
|
||||
my @names = readdir DIR or die;
|
||||
closedir DIR;
|
||||
|
||||
foreach my $name (@names) {
|
||||
next if $name eq "." || $name eq "..";
|
||||
findFiles("$relName/$name", "$target/$name", $name, $ignoreCollisions, $ignoreSingleFileOutputs, $checkCollisionContents, $priority);
|
||||
findFiles("$relName/$name", "$target/$name", $name, $ignoreCollisions, $checkCollisionContents, $priority, $ignoreSingleFileOutputs);
|
||||
}
|
||||
}
|
||||
|
||||
sub checkCollision {
|
||||
my ($path1, $path2) = @_;
|
||||
|
||||
sub checkCollision($path1, $path2) {
|
||||
if (! -e $path1 || ! -e $path2) {
|
||||
return 0;
|
||||
}
|
||||
@@ -109,14 +103,11 @@ sub checkCollision {
|
||||
return compare($path1, $path2) == 0;
|
||||
}
|
||||
|
||||
sub prependDangling {
|
||||
my $path = shift;
|
||||
sub prependDangling($path) {
|
||||
return (-l $path && ! -e $path ? "dangling symlink " : "") . "`$path'";
|
||||
}
|
||||
|
||||
sub findFiles {
|
||||
my ($relName, $target, $baseName, $ignoreCollisions, $ignoreSingleFileOutputs, $checkCollisionContents, $priority) = @_;
|
||||
|
||||
sub findFiles($relName, $target, $baseName, $ignoreCollisions, $checkCollisionContents, $priority, $ignoreSingleFileOutputs) {
|
||||
# The store path must not be a file when not ignoreSingleFileOutputs
|
||||
if (-f $target && isStorePath $target) {
|
||||
if ($ignoreSingleFileOutputs) {
|
||||
@@ -193,8 +184,8 @@ sub findFiles {
|
||||
}
|
||||
}
|
||||
|
||||
findFilesInDir($relName, $oldTarget, $ignoreCollisions, $ignoreSingleFileOutputs, $checkCollisionContents, $oldPriority) unless $oldTarget eq "";
|
||||
findFilesInDir($relName, $target, $ignoreCollisions, $ignoreSingleFileOutputs, $checkCollisionContents, $priority);
|
||||
findFilesInDir($relName, $oldTarget, $ignoreCollisions, $checkCollisionContents, $oldPriority, $ignoreSingleFileOutputs) unless $oldTarget eq "";
|
||||
findFilesInDir($relName, $target, $ignoreCollisions, $checkCollisionContents, $priority, $ignoreSingleFileOutputs);
|
||||
|
||||
$symlinks{$relName} = ["", $priority]; # denotes directory
|
||||
}
|
||||
@@ -203,13 +194,11 @@ sub findFiles {
|
||||
my %done;
|
||||
my %postponed;
|
||||
|
||||
sub addPkg {
|
||||
my ($pkgDir, $ignoreCollisions, $ignoreSingleFileOutputs, $checkCollisionContents, $priority) = @_;
|
||||
|
||||
sub addPkg($pkgDir, $ignoreCollisions, $checkCollisionContents, $priority, $ignoreSingleFileOutputs) {
|
||||
return if (defined $done{$pkgDir});
|
||||
$done{$pkgDir} = 1;
|
||||
|
||||
findFiles("", $pkgDir, "", $ignoreCollisions, $ignoreSingleFileOutputs, $checkCollisionContents, $priority);
|
||||
findFiles("", $pkgDir, "", $ignoreCollisions, $checkCollisionContents, $priority, $ignoreSingleFileOutputs);
|
||||
|
||||
my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages";
|
||||
if (-e $propagatedFN) {
|
||||
@@ -240,9 +229,9 @@ for my $pkg (@{decode_json $pkgs}) {
|
||||
for my $path (@{$pkg->{paths}}) {
|
||||
addPkg($path,
|
||||
$ENV{"ignoreCollisions"} eq "1",
|
||||
$ENV{"ignoreSingleFileOutputs"} eq "1",
|
||||
$ENV{"checkCollisionContents"} eq "1",
|
||||
$pkg->{priority})
|
||||
$pkg->{priority},
|
||||
$ENV{"ignoreSingleFileOutputs"} eq "1")
|
||||
if -e $path;
|
||||
}
|
||||
}
|
||||
@@ -257,7 +246,7 @@ while (scalar(keys %postponed) > 0) {
|
||||
my @pkgDirs = keys %postponed;
|
||||
%postponed = ();
|
||||
foreach my $pkgDir (sort @pkgDirs) {
|
||||
addPkg($pkgDir, 2, $ENV{"ignoreSingleFileOutputs"} eq "1", $ENV{"checkCollisionContents"} eq "1", $priorityCounter++);
|
||||
addPkg($pkgDir, 2, $ENV{"checkCollisionContents"} eq "1", $priorityCounter++, $ENV{"ignoreSingleFileOutputs"} eq "1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,9 +258,9 @@ if ($extraPathsFilePath) {
|
||||
chomp $line;
|
||||
addPkg($line,
|
||||
$ENV{"ignoreCollisions"} eq "1",
|
||||
$ENV{"ignoreSingleFileOutputs"} eq "1",
|
||||
$ENV{"checkCollisionContents"} eq "1",
|
||||
1000)
|
||||
1000,
|
||||
$ENV{"ignoreSingleFileOutputs"} eq "1")
|
||||
if -d $line;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user