Merge pull request #47 from ipetkov/dummy-fix

mkDummySrc: fix handling when src is already filtered
This commit is contained in:
Ivan Petkov 2022-06-30 15:20:17 +00:00 committed by GitHub
commit c850d8c935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 10 deletions

View File

@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
* Added `.overrideToolchain` as a convenience for using a custom rust toolchain
### Fixed
* Fixed an issue where `mkDummySrc` would produce incorrect results for filtered
sources: #46
## [0.5.0] - 2022-06-12
### Changed

View File

@ -1,22 +1,46 @@
{ linkFarmFromDrvs
{ lib
, linkFarmFromDrvs
, mkDummySrc
, runCommand
}:
let
cmpDummySrc = name: path:
cmpDummySrcRaw = name: input: expected:
let
dummySrc = mkDummySrc {
src = path + "/input";
src = input;
};
in
runCommand "compare-${name}" { } ''
diff -r ${path + /expected} ${dummySrc}
echo ${expected} ${dummySrc}
diff -r ${expected} ${dummySrc}
touch $out
'';
cmpDummySrc = name: path:
let
expected = path + "/expected";
input = path + "/input";
# Regression test for https://github.com/ipetkov/crane/issues/46
filteredInput = lib.cleanSourceWith {
src = input;
filter = path: type:
let baseName = builtins.baseNameOf path;
in
type == "directory" || lib.any (s: lib.hasPrefix s (builtins.baseNameOf path)) [
"Cargo"
"config"
];
};
in
[
(cmpDummySrcRaw name input expected)
(cmpDummySrcRaw "${name}-filtered" filteredInput expected)
];
in
linkFarmFromDrvs "cleanCargoToml" [
linkFarmFromDrvs "cleanCargoToml" (lib.flatten [
(cmpDummySrc "single" ./single)
(cmpDummySrc "single-alt" ./single-alt)
(cmpDummySrc "workspace" ./workspace)
]
])

View File

@ -78,17 +78,25 @@ let
# directory, we check if it happens to be an ancestor for an interesting file (i.e. is a prefix of
# an interesting file). That way we are left with the smallest possible source needed for our
# dummy derivation, and we bring any cache invalidation to a minimum. Whew!
mkBasePath = p: (toString p) + "/";
uncleanSrcBasePath = mkBasePath src;
uncleanFiles = findCargoFiles src;
# NB: if the `src` we were provided was filtered, make sure that we crawl the `origSrc`! Otherwise
# when we try to crawl the source Nix will evaluate the filter(s) fully resulting in a store path
# whose prefix won't match the paths we observe when we try to clean the source a bit further down
# (Nix optimizes multiple filters by running them all once against the original source).
# https://github.com/ipetkov/crane/issues/46
origSrc =
if src ? _isLibCleanSourceWith
then src.origSrc
else src;
uncleanSrcBasePath = (toString origSrc) + "/";
uncleanFiles = findCargoFiles origSrc;
cargoTomlsBase = uncleanSrcBasePath;
inherit (uncleanFiles) cargoTomls;
cleanSrc =
let
adjustPaths = builtins.map (p: removePrefix uncleanSrcBasePath (toString p));
allUncleanFiles = map
(p: removePrefix uncleanSrcBasePath (toString p))
# Allow the default `Cargo.lock` location to be picked up here