Skip to content

Commit

Permalink
mkDummySrc: fix cleaning to work with Nix store overrides (#448)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
ipetkov authored Nov 5, 2023
1 parent 2c89c36 commit 418ec86
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
gcroot
result*
target/
/extra-tests/*/alt-store
/extra-tests/*/flake.lock
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions extra-tests/alt-store/flake.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions extra-tests/alt-store/test.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions extra-tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/mkDummySrc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let
then src.origSrc
else src;

uncleanSrcBasePath = (toString origSrc) + "/";
uncleanSrcBasePath = builtins.unsafeDiscardStringContext ((toString origSrc) + "/");
uncleanFiles = findCargoFiles origSrc;

cargoTomlsBase = uncleanSrcBasePath;
Expand All @@ -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
Expand Down

0 comments on commit 418ec86

Please sign in to comment.