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 | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 16 | upstream_root = clone_repo("https://github.com/fmtlib/fmt", "10.1.1") |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 17 | wpilib_root = get_repo_root() |
| 18 | wpiutil = os.path.join(wpilib_root, "wpiutil") |
| 19 | |
| 20 | # Apply patches to upstream Git repo |
| 21 | os.chdir(upstream_root) |
| 22 | for f in [ |
| 23 | "0001-Don-t-throw-on-write-failure.patch", |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 24 | "0002-Suppress-warnings-we-can-t-fix.patch", |
Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame^] | 25 | "0003-Remove-this-from-decltype.patch", |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 26 | ]: |
| 27 | git_am(os.path.join(wpilib_root, "upstream_utils/fmt_patches", f)) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 28 | |
| 29 | # Delete old install |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 30 | for d in [ |
| 31 | "src/main/native/thirdparty/fmtlib/src", |
| 32 | "src/main/native/thirdparty/fmtlib/include", |
| 33 | ]: |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 34 | shutil.rmtree(os.path.join(wpiutil, d), ignore_errors=True) |
| 35 | |
| 36 | # Copy fmt source files into allwpilib |
| 37 | src_files = walk_cwd_and_copy_if( |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 38 | lambda dp, f: dp.startswith("./src") and f.endswith(".cc") and f != "fmt.cc", |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 39 | os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"), |
| 40 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 41 | |
| 42 | # Copy fmt header files into allwpilib |
| 43 | include_files = walk_cwd_and_copy_if( |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 44 | lambda dp, f: dp.startswith("./include/fmt"), |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 45 | os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"), |
| 46 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 47 | |
| 48 | for f in src_files: |
| 49 | comment_out_invalid_includes( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 50 | f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")] |
| 51 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 52 | for f in include_files: |
| 53 | comment_out_invalid_includes( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 54 | f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")] |
| 55 | ) |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 56 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 57 | |
| 58 | if __name__ == "__main__": |
| 59 | main() |