mkDummySrc: fix cleaning to work with Nix store overrides (#448)

* Turns out if a build is invoked with `--store` then the source
  cleaning filter will observe paths rooted at the alternative store
  which breaks out previous string handling (and results in incorrectly
  ignoring files which should be included)
This commit is contained in:
Ivan Petkov 2023-11-05 19:32:24 +01:00 committed by GitHub
parent 2c89c36bff
commit 418ec86477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
gcroot
result*
target/
/extra-tests/*/alt-store
/extra-tests/*/flake.lock

View File

@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* All dependencies (outside of `nixpkgs`) have been dropped from the (main)
flake.lock file so they do not pollute downstream projects' lock files.
### Fixed
* `mkDummySrc` now properly handles file cleaning (and file including) when a
build is invoked with a `--store ...` override
## [0.14.3] - 2023-10-17
### Changed

View File

@ -0,0 +1,18 @@
{
inputs = {
crane.url = "github:ipetkov/crane";
nixpkgs.follows = "crane/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { flake-utils, crane, ... }: flake-utils.lib.eachDefaultSystem (system:
let
craneLib = crane.lib.${system};
in
{
# https://github.com/ipetkov/crane/issues/446
packages.default = craneLib.buildPackage {
src = craneLib.cleanCargoSource (craneLib.path ../../checks/simple);
};
});
}

8
extra-tests/alt-store/test.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
# Regression test for https://github.com/ipetkov/crane/issues/446
set -eu
scriptDir=$(dirname "$0")
cd "${scriptDir}"
nix build .#default --override-input crane ../.. --store $(pwd)/alt-store

View File

@ -18,6 +18,7 @@ runTest() {
scriptPath=$(dirname "$0")
cd "${scriptPath}"
runTest ./alt-store/test.sh
runTest ./dummy-does-not-depend-on-flake-source-via-path/test.sh
runTest ./dummy-does-not-depend-on-flake-source-via-self/test.sh
runTest ./fetch-cargo-git/test.sh

View File

@ -93,7 +93,7 @@ let
then src.origSrc
else src;
uncleanSrcBasePath = (toString origSrc) + "/";
uncleanSrcBasePath = builtins.unsafeDiscardStringContext ((toString origSrc) + "/");
uncleanFiles = findCargoFiles origSrc;
cargoTomlsBase = uncleanSrcBasePath;
@ -112,7 +112,11 @@ let
name = "cleaned-mkDummySrc";
filter = path: type:
let
strippedPath = removePrefix uncleanSrcBasePath path;
# using `path` can have weird consequences here with alternative store paths
# so we cannot assume `uncleanSrcBasePath` will be a strict prefix. Thus we
# chop off anything up to and including its value
# https://github.com/ipetkov/crane/issues/446
strippedPath = lib.last (lib.splitString uncleanSrcBasePath path);
filter = x:
if type == "directory" then
lib.hasPrefix strippedPath x