mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-27 02:52:02 +03:00
Merge pull request #47 from ipetkov/dummy-fix
mkDummySrc: fix handling when src is already filtered
This commit is contained in:
commit
c850d8c935
@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
### Added
|
### Added
|
||||||
* Added `.overrideToolchain` as a convenience for using a custom rust toolchain
|
* 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
|
## [0.5.0] - 2022-06-12
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -1,22 +1,46 @@
|
|||||||
{ linkFarmFromDrvs
|
{ lib
|
||||||
|
, linkFarmFromDrvs
|
||||||
, mkDummySrc
|
, mkDummySrc
|
||||||
, runCommand
|
, runCommand
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
cmpDummySrc = name: path:
|
cmpDummySrcRaw = name: input: expected:
|
||||||
let
|
let
|
||||||
dummySrc = mkDummySrc {
|
dummySrc = mkDummySrc {
|
||||||
src = path + "/input";
|
src = input;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
runCommand "compare-${name}" { } ''
|
runCommand "compare-${name}" { } ''
|
||||||
diff -r ${path + /expected} ${dummySrc}
|
echo ${expected} ${dummySrc}
|
||||||
|
diff -r ${expected} ${dummySrc}
|
||||||
touch $out
|
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
|
in
|
||||||
linkFarmFromDrvs "cleanCargoToml" [
|
linkFarmFromDrvs "cleanCargoToml" (lib.flatten [
|
||||||
(cmpDummySrc "single" ./single)
|
(cmpDummySrc "single" ./single)
|
||||||
(cmpDummySrc "single-alt" ./single-alt)
|
(cmpDummySrc "single-alt" ./single-alt)
|
||||||
(cmpDummySrc "workspace" ./workspace)
|
(cmpDummySrc "workspace" ./workspace)
|
||||||
]
|
])
|
||||||
|
@ -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
|
# 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
|
# 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!
|
# 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;
|
cargoTomlsBase = uncleanSrcBasePath;
|
||||||
inherit (uncleanFiles) cargoTomls;
|
inherit (uncleanFiles) cargoTomls;
|
||||||
|
|
||||||
cleanSrc =
|
cleanSrc =
|
||||||
let
|
let
|
||||||
adjustPaths = builtins.map (p: removePrefix uncleanSrcBasePath (toString p));
|
|
||||||
allUncleanFiles = map
|
allUncleanFiles = map
|
||||||
(p: removePrefix uncleanSrcBasePath (toString p))
|
(p: removePrefix uncleanSrcBasePath (toString p))
|
||||||
# Allow the default `Cargo.lock` location to be picked up here
|
# Allow the default `Cargo.lock` location to be picked up here
|
||||||
|
Loading…
Reference in New Issue
Block a user