Skip to content

Commit

Permalink
buildEnv: support ignoreFileOutputs
Browse files Browse the repository at this point in the history
Add option to ignore single-file output instead of failing.
  • Loading branch information
ShamrockLee committed Dec 2, 2024
1 parent 6f40e94 commit 6bacc2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
23 changes: 14 additions & 9 deletions pkgs/build-support/buildenv/builder.pl
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ sub isStorePath {
sub findFiles;

sub findFilesInDir {
my ($relName, $target, $ignoreCollisions, $checkCollisionContents, $priority) = @_;
my ($relName, $target, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority) = @_;

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, $checkCollisionContents, $priority);
findFiles("$relName/$name", "$target/$name", $name, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority);
}
}

Expand Down Expand Up @@ -115,11 +115,16 @@ sub prependDangling {
}

sub findFiles {
my ($relName, $target, $baseName, $ignoreCollisions, $checkCollisionContents, $priority) = @_;
my ($relName, $target, $baseName, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority) = @_;

# The store path must not be a file
# The store path must not be a file when not ignoreFileOutputs
if (-f $target && isStorePath $target) {
die "The store path $target is a file and can't be merged into an environment using pkgs.buildEnv!";
if ($ignoreFileOutputs) {
warn "The store path $target is a file and can't be merged into an environment using pkgs.buildEnv";
return;
} else {
die "The store path $target is a file and can't be merged into an environment using pkgs.buildEnv!";
}
}

# Urgh, hacky...
Expand Down Expand Up @@ -188,8 +193,8 @@ sub findFiles {
}
}

findFilesInDir($relName, $oldTarget, $ignoreCollisions, $checkCollisionContents, $oldPriority) unless $oldTarget eq "";
findFilesInDir($relName, $target, $ignoreCollisions, $checkCollisionContents, $priority);
findFilesInDir($relName, $oldTarget, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $oldPriority) unless $oldTarget eq "";
findFilesInDir($relName, $target, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority);

$symlinks{$relName} = ["", $priority]; # denotes directory
}
Expand All @@ -199,12 +204,12 @@ sub findFiles {
my %postponed;

sub addPkg {
my ($pkgDir, $ignoreCollisions, $checkCollisionContents, $priority) = @_;
my ($pkgDir, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority) = @_;

return if (defined $done{$pkgDir});
$done{$pkgDir} = 1;

findFiles("", $pkgDir, "", $ignoreCollisions, $checkCollisionContents, $priority);
findFiles("", $pkgDir, "", $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority);

my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages";
if (-e $propagatedFN) {
Expand Down
5 changes: 4 additions & 1 deletion pkgs/build-support/buildenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ lib.makeOverridable
, # Whether to ignore collisions or abort.
ignoreCollisions ? false

# Whether to outputs that is a single file instead of a directory.
, ignoreFileOutputs ? false

, # Whether to include closures of all input paths.
includeClosures ? false

Expand Down Expand Up @@ -78,7 +81,7 @@ let
];
in runCommand name
(rec {
inherit manifest ignoreCollisions checkCollisionContents passthru
inherit manifest ignoreCollisions checkCollisionContents ignoreFileOutputs passthru
meta pathsToLink extraPrefix postBuild
nativeBuildInputs buildInputs;
pkgs = builtins.toJSON chosenOutputs;
Expand Down

0 comments on commit 6bacc2f

Please sign in to comment.