on iko/ghcjs-patch-master help sign in
Use `subDir` not `src` to construct default names (#506)
0aa17d8Hamish Mackenzie
@@ -59,6 +59,8 @@ then
59
59
60 # Identify the .git directory and filter just the files that we need.
60 # Identify the .git directory and filter just the files that we need.
61 gitDir = cleanSourceWith ({
61 gitDir = cleanSourceWith ({
62+ caller = "cleanGit";
63+ name = (if name == null then "" else name + "-") + "gitFiles";
62 filter = path: type:
64 filter = path: type:
63 type == "directory" ||
65 type == "directory" ||
64 lib.any (i: (lib.hasSuffix i path)) [
66 lib.any (i: (lib.hasSuffix i path)) [
@@ -102,6 +104,8 @@ then
102 gitModules = builtins.path { name = "gitmodules"; path = gitModulesStr; };
104 gitModules = builtins.path { name = "gitmodules"; path = gitModulesStr; };
103
105
104 gitSubmoduleFiles = cleanSourceWith {
106 gitSubmoduleFiles = cleanSourceWith {
107+ caller = "cleanGit";
108+ name = (if name == null then "" else name + "-") + "gitSubmoduleFiles";
105 inherit src;
109 inherit src;
106 filter = path: type:
110 filter = path: type:
107 type == "directory" # TODO get sudmodule directories from `.gitmodules`
111 type == "directory" # TODO get sudmodule directories from `.gitmodules`
@@ -143,12 +147,14 @@ then
143 filter = filter_from_list src whitelist;
147 filter = filter_from_list src whitelist;
144 in
148 in
145 cleanSourceWith {
149 cleanSourceWith {
150+ caller = "cleanGit";
146 inherit name src subDir filter;
151 inherit name src subDir filter;
147 }
152 }
148
153
149else
154else
150 trace "gitSource.nix: ${toString src} does not seem to be a git repository,\nassuming it is a clean checkout." (
155 trace "gitSource.nix: ${toString src} does not seem to be a git repository,\nassuming it is a clean checkout." (
151 cleanSourceWith {
156 cleanSourceWith {
157+ caller = "cleanGit";
152 inherit name src subDir;
158 inherit name src subDir;
153 }
159 }
154 )
160 )
lib/clean-source-with.nix+39−10
@@ -32,18 +32,25 @@
32 # https://nixos.org/nix/manual/#builtin-filterSource
32 # https://nixos.org/nix/manual/#builtin-filterSource
33 #
33 #
34 # subDir: Descend into a subdirectory in a way that will compose.
34 # subDir: Descend into a subdirectory in a way that will compose.
35− # It will be ase if `src = src + "/${subDir}` and filters
35+ # It will be as if `src = src + "/${subDir}` and filters
36 # already applied to `src` will be respected.
36 # already applied to `src` will be respected.
37 #
37 #
38 # name: Optional name to use as part of the store path.
38 # name: Optional name to use as part of the store path.
39− # This defaults `src.name` or otherwise `baseNameOf src`.
39+ # If you do not provide a `name` it wil be derived
40− # We recommend setting `name` whenever `src` is syntactically `./.`.
40+ # from the `subDir`. You should provide `name` or
41− # Otherwise, you depend on `./.`'s name in the parent directory,
41+ # `subDir`. If you do not a warning will be displayed
42− # which can cause inconsistent names, defeating caching.
42+ # and the name used will be `source`.
43 #
43 #
44+ # caller: Name of the function used in warning message.
45+ # Functions that are implemented using `cleanSourceWith`
46+ # (and forward a `name` argument) can use this to make
47+ # the message to the use more meaningful.
48+ #
44− cleanSourceWith = { filter ? _path: _type: true, src, subDir ? "", name ? null }:
49+ cleanSourceWith = { filter ? _path: _type: true, src, subDir ? "", name ? null
50+ , caller ? "cleanSourceWith" }:
45 let
51 let
46 subDir' = if subDir == "" then "" else "/" + subDir;
52 subDir' = if subDir == "" then "" else "/" + subDir;
53+ subDirName = __replaceStrings ["/"] ["-"] subDir;
47 # In case this is mixed with older versions of cleanSourceWith
54 # In case this is mixed with older versions of cleanSourceWith
48 isFiltered = src ? _isLibCleanSourceWith;
55 isFiltered = src ? _isLibCleanSourceWith;
49 isFilteredEx = src ? _isLibCleanSourceWithEx;
56 isFilteredEx = src ? _isLibCleanSourceWithEx;
@@ -62,10 +69,32 @@
62 && (filter path type && parentFilter path type));
69 && (filter path type && parentFilter path type));
63 name' = if name != null
70 name' = if name != null
64 then name
71 then name
65− else (if isFiltered && src ? name
72+ else
66− then src.name
73+ if subDirName != ""
67− else baseNameOf src)
74+ then if src ? name
68− + (lib.optionalString (origSubDir != "") ("--" + baseNameOf origSubDir));
75+ then src.name + "-" + subDirName
76+ else "source-" + subDirName
77+ else if src ? name
78+ then src.name
79+ else
80+ # No name was provided and one could not be constructed from
81+ # the `subDirName`.
82+
83+ # We used to use `baseNameOf src` as a default here.
84+ # This was cute, but it lead to cache misses. For instance if
85+ # `x = cleanSourceWith { src = ./.; }` then `baseName src`
86+ # will be different when `src` resolves to "/nix/store/X"
87+ # than when it is in a local directory. If people use
88+ # git worktrees they also may wind up with different
89+ # values for `name`. Anything that depends on `x.name` will
90+ # propagate the issue.
91+
92+ # Encourage adding a suitable `name` with:
93+ # * A warning message.
94+ # * A default name that gives a hint as to why there is no name.
95+ __trace (
96+ "WARNING: `${caller}` called on ${toString src} without a `name`. "
97+ + "Consider adding `name = \"${baseNameOf src};\"`") "source";
69 in {
98 in {
70 inherit origSrc origSubDir origSrcSubDir;
99 inherit origSrc origSubDir origSrcSubDir;
71 filter = filter';
100 filter = filter';