blob: a6b64993d7dbe48da2a06d4c60c19827db898c5a [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001#!/usr/bin/env python3
2
3import os
4import shutil
5
6from upstream_utils import setup_upstream_repo, comment_out_invalid_includes, walk_cwd_and_copy_if, apply_patches
7
8
9def main():
10 root, repo = setup_upstream_repo("https://github.com/RobotLocomotion/drake",
11 "v0.35.0")
12 wpimath = os.path.join(root, "wpimath")
13
14 # Delete old install
15 for d in [
16 "src/main/native/cpp/drake", "src/main/native/include/drake",
17 "src/test/native/cpp/drake", "src/test/native/include/drake"
18 ]:
19 shutil.rmtree(os.path.join(wpimath, d), ignore_errors=True)
20
21 # Copy drake source files into allwpilib
22 src_files = walk_cwd_and_copy_if(
23 lambda dp, f: f in
24 ["drake_assert_and_throw.cc", "discrete_algebraic_riccati_equation.cc"],
25 os.path.join(wpimath, "src/main/native/cpp/drake"))
26
27 # Copy drake header files into allwpilib
28 include_files = walk_cwd_and_copy_if(
29 lambda dp, f: f in [
30 "drake_assert.h", "drake_assertion_error.h",
31 "is_approx_equal_abstol.h", "never_destroyed.h", "drake_copyable.h",
32 "drake_throw.h", "discrete_algebraic_riccati_equation.h"
33 ], os.path.join(wpimath, "src/main/native/include/drake"))
34
35 # Copy drake test source files into allwpilib
36 os.chdir(os.path.join(repo, "math/test"))
37 test_src_files = walk_cwd_and_copy_if(
38 lambda dp, f: f == "discrete_algebraic_riccati_equation_test.cc",
39 os.path.join(wpimath, "src/test/native/cpp/drake"))
40 os.chdir(repo)
41
42 # Copy drake test header files into allwpilib
43 test_include_files = walk_cwd_and_copy_if(
44 lambda dp, f: f == "eigen_matrix_compare.h",
45 os.path.join(wpimath, "src/test/native/include/drake"))
46
47 for f in src_files:
48 comment_out_invalid_includes(
49 f, [os.path.join(wpimath, "src/main/native/include")])
50 for f in include_files:
51 comment_out_invalid_includes(
52 f, [os.path.join(wpimath, "src/main/native/include")])
53 for f in test_src_files:
54 comment_out_invalid_includes(f, [
55 os.path.join(wpimath, "src/main/native/include"),
56 os.path.join(wpimath, "src/test/native/include")
57 ])
58 for f in test_include_files:
59 comment_out_invalid_includes(f, [
60 os.path.join(wpimath, "src/main/native/include"),
61 os.path.join(wpimath, "src/test/native/include")
62 ])
63
64 apply_patches(root, [
65 "upstream_utils/drake-replace-dense-with-core.patch",
66 "upstream_utils/drake-dllexport-dare.patch",
67 "upstream_utils/drake-fix-doxygen.patch"
68 ])
69
70
71if __name__ == "__main__":
72 main()