-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.nix
30 lines (28 loc) · 855 Bytes
/
header.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{ lib, ... }:
rec {
parse = fpath:
fpath
|> lib.fpath.toPath
|> lib.readFile
|> lib.splitString "\n"
|> lib.filter (a: lib.hasPrefix "#include " a)
|> map (x: x
|> lib.strings.split ''#include ( |(/\*.*\*/))*(".*")|(<.*>)''
|> lib.filter (a: lib.isList a)
|> lib.lists.flatten
|> lib.filter (a: builtins.isString a)
|> lib.lists.last
)
|> lib.filter (a: lib.hasPrefix "\"" a)
|> map (x: x
|> lib.strings.removePrefix "\""
|> lib.strings.removeSuffix "\""
)
|> lib.lists.unique;
parseRecursivelyFpath = fpath:
let
includes = parse fpath;
fpathIncludes = (lib.forEach includes (include: fpath |> lib.fpath.leave |> lib.fpath.enter include));
in
fpathIncludes ++ (lib.forEach fpathIncludes (include: parseRecursivelyFpath include)) |> lib.flatten;
}