1# Use cleanSourceWith to filter just the files needed for a particular
2# component of the package
3{ lib, cleanSourceWith }: package: component: src:
5 srcStr' = src.origSrcSubDir or src.origSrc or null;
10 normalizeRelativePath = rel:
11 if rel == "." || rel == "./."
13 else lib.strings.removePrefix "./" rel;
14 # Like normalizeRelativePath but with a trailing / when needed
15 normalizeRelativeDir = dir:
16 let p = normalizeRelativePath dir;
17 in if p == "" || p == "/"
19 else if lib.hasSuffix "/" p
23 if srcStr' == null || package.detailLevel != "FullDetails"
27 srcStr = toString srcStr';
28 dataDir = normalizeRelativeDir package.dataDir;
29 hsSourceDirs = builtins.map normalizeRelativeDir component.hsSourceDirs
30 ++ (if component.hsSourceDirs == [] then [""] else []);
31 includeDirs = builtins.map normalizeRelativeDir component.includeDirs;
32 dirsNeeded = [dataDir]
35 fileMatch = dir: list:
37 prefixes = builtins.map (f: dir + f) (
38 lib.lists.remove null (lib.lists.flatten (
39 builtins.map (f: builtins.match "([^*]*)[*].*" f) list)));
40 exactMatches = builtins.map (f: dataDir + f) (
41 lib.lists.remove null (lib.lists.flatten (
42 builtins.map (f: builtins.match "([^*]*)" f) list)));
43 in rPath: lib.any (d: lib.strings.hasPrefix d rPath) prefixes
44 || lib.any (d: d == rPath) exactMatches;
45 dataFileMatch = fileMatch dataDir package.dataFiles;
46 licenseMatch = fileMatch "" package.licenseFiles;
47 extraSrcMatch = fileMatch "" (
49 ++ component.extraSrcFiles);
50 extraDocMatch = fileMatch "" package.extraDocFiles;
53 ++ component.cmmSources
55 ++ component.cxxSources
56 ++ component.jsSources;
60 assert (if !lib.strings.hasPrefix (srcStr + "/") (path + "/")
61 then throw ("Unexpected path " + path + " (expected something in " + srcStr + "/)")
64 srcStrLen = lib.strings.stringLength srcStr;
65 rPath = lib.strings.substring (srcStrLen + 1) (lib.strings.stringLength path - srcStrLen - 1) path;
66 # This is a handy way to find out why different files are included
67 # traceReason = reason: v: if v then builtins.trace (rPath + " : " + reason) true else false;
68 traceReason = reason: v: v;
70 traceReason "directory is needed" (
71 lib.any (d: lib.strings.hasPrefix (rPath + "/") d) (
73 ++ package.extraSrcFiles
74 ++ component.extraSrcFiles
75 ++ package.extraDocFiles
76 ++ builtins.map (f: dataDir + f) package.dataFiles
78 || traceReason "cabal package definition" (lib.strings.hasSuffix ".cabal" rPath)
79 || traceReason "hpack package defintion" (rPath == "package.yaml")
80 || traceReason "data file" (lib.strings.hasPrefix dataDir rPath
81 && dataFileMatch rPath)
82 || traceReason "haskell source dir" (lib.any (d: lib.strings.hasPrefix d rPath) hsSourceDirs)
83 || traceReason "include dir" (lib.any (d: lib.strings.hasPrefix d rPath) includeDirs)
84 || traceReason "license file" (licenseMatch rPath)
85 || traceReason "extra source file" (extraSrcMatch rPath)
86 || traceReason "extra doc file" (extraDocMatch rPath)
87 || traceReason "other source file" (lib.any (f: f == rPath) otherSourceFiles);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list