blob: 1849494c53fdaf215191cbae193cc96fe8b17caf [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001#!/usr/bin/env python3
2
3import os
4import shutil
5
James Kuszmaulcf324122023-01-14 14:07:17 -08006from upstream_utils import (
7 get_repo_root,
8 clone_repo,
9 comment_out_invalid_includes,
10 walk_cwd_and_copy_if,
11 git_am,
12)
Austin Schuh812d0d12021-11-04 20:16:48 -070013
14
15def main():
James Kuszmaulcf324122023-01-14 14:07:17 -080016 upstream_root = clone_repo("https://github.com/RobotLocomotion/drake", "v1.6.0")
17 wpilib_root = get_repo_root()
18 wpimath = os.path.join(wpilib_root, "wpimath")
19
20 # Apply patches to upstream Git repo
21 os.chdir(upstream_root)
22 for f in [
23 "0001-Replace-Eigen-Dense-with-Eigen-Core.patch",
24 "0002-Add-WPILIB_DLLEXPORT-to-DARE-function-declarations.patch",
25 ]:
26 git_am(os.path.join(wpilib_root, "upstream_utils/drake_patches", f))
Austin Schuh812d0d12021-11-04 20:16:48 -070027
28 # Delete old install
29 for d in [
James Kuszmaulcf324122023-01-14 14:07:17 -080030 "src/main/native/thirdparty/drake/src",
31 "src/main/native/thirdparty/drake/include",
32 "src/test/native/cpp/drake",
33 "src/test/native/include/drake",
Austin Schuh812d0d12021-11-04 20:16:48 -070034 ]:
35 shutil.rmtree(os.path.join(wpimath, d), ignore_errors=True)
36
37 # Copy drake source files into allwpilib
38 src_files = walk_cwd_and_copy_if(
James Kuszmaulcf324122023-01-14 14:07:17 -080039 lambda dp, f: f
40 in ["drake_assert_and_throw.cc", "discrete_algebraic_riccati_equation.cc"],
41 os.path.join(wpimath, "src/main/native/thirdparty/drake/src"),
42 )
Austin Schuh812d0d12021-11-04 20:16:48 -070043
44 # Copy drake header files into allwpilib
45 include_files = walk_cwd_and_copy_if(
James Kuszmaulcf324122023-01-14 14:07:17 -080046 lambda dp, f: f
47 in [
48 "drake_assert.h",
49 "drake_assertion_error.h",
50 "is_approx_equal_abstol.h",
51 "never_destroyed.h",
52 "drake_copyable.h",
53 "drake_throw.h",
54 "discrete_algebraic_riccati_equation.h",
55 ],
56 os.path.join(wpimath, "src/main/native/thirdparty/drake/include/drake"),
57 )
Austin Schuh812d0d12021-11-04 20:16:48 -070058
59 # Copy drake test source files into allwpilib
James Kuszmaulcf324122023-01-14 14:07:17 -080060 os.chdir(os.path.join(upstream_root, "math/test"))
Austin Schuh812d0d12021-11-04 20:16:48 -070061 test_src_files = walk_cwd_and_copy_if(
62 lambda dp, f: f == "discrete_algebraic_riccati_equation_test.cc",
James Kuszmaulcf324122023-01-14 14:07:17 -080063 os.path.join(wpimath, "src/test/native/cpp/drake"),
64 )
65 os.chdir(upstream_root)
Austin Schuh812d0d12021-11-04 20:16:48 -070066
67 # Copy drake test header files into allwpilib
68 test_include_files = walk_cwd_and_copy_if(
69 lambda dp, f: f == "eigen_matrix_compare.h",
James Kuszmaulcf324122023-01-14 14:07:17 -080070 os.path.join(wpimath, "src/test/native/include/drake"),
71 )
Austin Schuh812d0d12021-11-04 20:16:48 -070072
73 for f in src_files:
74 comment_out_invalid_includes(
James Kuszmaulcf324122023-01-14 14:07:17 -080075 f, [os.path.join(wpimath, "src/main/native/thirdparty/drake/include")]
76 )
Austin Schuh812d0d12021-11-04 20:16:48 -070077 for f in include_files:
78 comment_out_invalid_includes(
James Kuszmaulcf324122023-01-14 14:07:17 -080079 f, [os.path.join(wpimath, "src/main/native/thirdparty/drake/include")]
80 )
Austin Schuh812d0d12021-11-04 20:16:48 -070081 for f in test_src_files:
James Kuszmaulcf324122023-01-14 14:07:17 -080082 comment_out_invalid_includes(
83 f,
84 [
85 os.path.join(wpimath, "src/main/native/thirdparty/drake/include"),
86 os.path.join(wpimath, "src/test/native/include"),
87 ],
88 )
Austin Schuh812d0d12021-11-04 20:16:48 -070089 for f in test_include_files:
James Kuszmaulcf324122023-01-14 14:07:17 -080090 comment_out_invalid_includes(
91 f,
92 [
93 os.path.join(wpimath, "src/main/native/thirdparty/drake/include"),
94 os.path.join(wpimath, "src/test/native/include"),
95 ],
96 )
Austin Schuh812d0d12021-11-04 20:16:48 -070097
98
99if __name__ == "__main__":
100 main()