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", |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 25 | ]: |
| 26 | git_am(os.path.join(wpilib_root, "upstream_utils/fmt_patches", f)) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 27 | |
| 28 | # Delete old install |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 29 | for d in [ |
| 30 | "src/main/native/thirdparty/fmtlib/src", |
| 31 | "src/main/native/thirdparty/fmtlib/include", |
| 32 | ]: |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 33 | shutil.rmtree(os.path.join(wpiutil, d), ignore_errors=True) |
| 34 | |
| 35 | # Copy fmt source files into allwpilib |
| 36 | src_files = walk_cwd_and_copy_if( |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 37 | 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] | 38 | os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"), |
| 39 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 40 | |
| 41 | # Copy fmt header files into allwpilib |
| 42 | include_files = walk_cwd_and_copy_if( |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 43 | lambda dp, f: dp.startswith("./include/fmt"), |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 44 | os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"), |
| 45 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 46 | |
| 47 | for f in src_files: |
| 48 | comment_out_invalid_includes( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 49 | f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")] |
| 50 | ) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 51 | for f in include_files: |
| 52 | comment_out_invalid_includes( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 53 | f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")] |
| 54 | ) |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 55 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 56 | |
| 57 | if __name__ == "__main__": |
| 58 | main() |