-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mkDummySrc: fix handling when src is already filtered #47
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
] | ||
]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I correct in saying that this was added in 4f2b1c4 but wasn't actually used (I'm assuming it was just leftover from an iteration of that commit)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep I think I was iterating on whether to make the filter on the next line as its own variable, but it looks like it was never used (since Nix is lazy it just ignores unused input 🤷 ) |
||
allUncleanFiles = map | ||
(p: removePrefix uncleanSrcBasePath (toString p)) | ||
# Allow the default `Cargo.lock` location to be picked up here | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is done to forcefully evaluate the source derivation? Wouldn't this already be evaluated in the call to
findCargoFiles
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a good enough intuitive understanding of how Nix treats paths and strings (and coercing between the two) to explain why this is needed... I did try taking it out and a bunch of tests failed so it's load bearing at some capacity 😅