blob: 0df72a8d779f4623b5f74cecf24d4051a6a870e4 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001#!/usr/bin/env python3
2
3import os
4import re
5import shutil
6
7from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, apply_patches
8
9
10def eigen_inclusions(dp, f):
11 """Returns true if the given file in the "Eigen" include directory of the
12 Eigen git repo should be copied into allwpilib
13
14 Keyword arguments:
15 dp -- directory path
16 f -- filename
17 """
18 if not dp.startswith("./Eigen"):
19 return False
20
21 abspath = os.path.join(dp, f)
22
23 # Exclude NonMPL2.h since all non-MPL2 code will be excluded anyway
24 if f == "NonMPL2.h":
25 return False
26
27 # Exclude BLAS support
28 if f.endswith("_BLAS.h") or "blas" in f:
29 return False
30
31 # Exclude LAPACK support
32 if f.endswith("_LAPACKE.h") or "lapack" in f:
33 return False
34
35 # Exclude MKL support
36 if "MKL" in f:
37 return False
38
39 # Include architectures we care about
40 if "Core/arch/" in abspath:
41 return ("arch/AVX/" in abspath or "arch/Default" in abspath or
42 "arch/NEON" in abspath or "arch/SSE" in abspath)
43
44 # Include the following modules
45 modules = [
46 "Cholesky",
47 "Core",
48 "Eigenvalues",
49 "Householder",
50 "Jacobi",
51 "LU",
52 "QR",
53 "SVD",
54 "StlSupport",
55 "misc",
56 "plugins",
57 ]
58 modules_rgx = r"|".join("/" + m for m in modules)
59
60 # "Std" matches StdDeque, StdList, and StdVector headers
61 if re.search(modules_rgx, abspath) or "Std" in f:
62 return True
63 else:
64 # Exclude all other modules
65 return False
66
67
68def unsupported_inclusions(dp, f):
69 """Returns true if the given file in the "unsupported" include directory of
70 the Eigen git repo should be copied into allwpilib
71
72 Keyword arguments:
73 dp -- directory path
74 f -- filename
75 """
76 if not dp.startswith("./unsupported"):
77 return False
78
79 abspath = os.path.join(dp, f)
80
81 # Exclude build system and READMEs
82 if f == "CMakeLists.txt" or "README" in f:
83 return False
84
85 # Include the AutoDiff and MatrixFunctions modules
86 return "AutoDiff" in abspath or "MatrixFunctions" in abspath
87
88
89def main():
90 root, repo = setup_upstream_repo("https://gitlab.com/libeigen/eigen.git",
91 "3.4.0")
92 wpimath = os.path.join(root, "wpimath")
93
94 # Delete old install
95 for d in [
96 "src/main/native/eigeninclude/Eigen",
97 "src/main/native/eigeninclude/unsupported"
98 ]:
99 shutil.rmtree(os.path.join(wpimath, d), ignore_errors=True)
100
101 # Copy Eigen headers into allwpilib
102 eigen_files = walk_cwd_and_copy_if(
103 eigen_inclusions, os.path.join(wpimath, "src/main/native/eigeninclude"))
104
105 # Copy unsupported headers into allwpilib
106 unsupported_files = walk_cwd_and_copy_if(
107 unsupported_inclusions,
108 os.path.join(wpimath, "src/main/native/eigeninclude"))
109
110 for f in eigen_files:
111 comment_out_invalid_includes(
112 f, [os.path.join(wpimath, "src/main/native/eigeninclude")])
113 for f in unsupported_files:
114 comment_out_invalid_includes(
115 f, [os.path.join(wpimath, "src/main/native/eigeninclude")])
116
117 apply_patches(root, ["upstream_utils/eigen-maybe-uninitialized.patch"])
118
119
120if __name__ == "__main__":
121 main()