Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import os |
| 4 | import shutil |
| 5 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 6 | from 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 13 | |
| 14 | |
| 15 | def main(): |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 16 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 27 | |
| 28 | # Delete old install |
| 29 | for d in [ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 30 | "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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 34 | ]: |
| 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 39 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 43 | |
| 44 | # Copy drake header files into allwpilib |
| 45 | include_files = walk_cwd_and_copy_if( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 46 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 58 | |
| 59 | # Copy drake test source files into allwpilib |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 60 | os.chdir(os.path.join(upstream_root, "math/test")) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 61 | test_src_files = walk_cwd_and_copy_if( |
| 62 | lambda dp, f: f == "discrete_algebraic_riccati_equation_test.cc", |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 63 | os.path.join(wpimath, "src/test/native/cpp/drake"), |
| 64 | ) |
| 65 | os.chdir(upstream_root) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 66 | |
| 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 Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 70 | os.path.join(wpimath, "src/test/native/include/drake"), |
| 71 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 72 | |
| 73 | for f in src_files: |
| 74 | comment_out_invalid_includes( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 75 | f, [os.path.join(wpimath, "src/main/native/thirdparty/drake/include")] |
| 76 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 77 | for f in include_files: |
| 78 | comment_out_invalid_includes( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 79 | f, [os.path.join(wpimath, "src/main/native/thirdparty/drake/include")] |
| 80 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 81 | for f in test_src_files: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 82 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 89 | for f in test_include_files: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 90 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 97 | |
| 98 | |
| 99 | if __name__ == "__main__": |
| 100 | main() |