diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0d605a..8e333f18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/checks/mkDummySrcTests/default.nix b/checks/mkDummySrcTests/default.nix index 21f632ab..a9bd9feb 100644 --- a/checks/mkDummySrcTests/default.nix +++ b/checks/mkDummySrcTests/default.nix @@ -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) -] +]) diff --git a/lib/mkDummySrc.nix b/lib/mkDummySrc.nix index d52ce868..1fdf630d 100644 --- a/lib/mkDummySrc.nix +++ b/lib/mkDummySrc.nix @@ -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