blob: 3af48a27f2078008edfa74129e8bf2353253c43e [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 Kuszmaulb13e13f2023-11-22 20:44:04 -080016 upstream_root = clone_repo("https://github.com/fmtlib/fmt", "10.1.1")
James Kuszmaulcf324122023-01-14 14:07:17 -080017 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080024 "0002-Suppress-warnings-we-can-t-fix.patch",
Maxwell Henderson80bec322024-01-09 15:48:44 -080025 "0003-Remove-this-from-decltype.patch",
James Kuszmaulcf324122023-01-14 14:07:17 -080026 ]:
27 git_am(os.path.join(wpilib_root, "upstream_utils/fmt_patches", f))
Austin Schuh812d0d12021-11-04 20:16:48 -070028
29 # Delete old install
James Kuszmaulcf324122023-01-14 14:07:17 -080030 for d in [
31 "src/main/native/thirdparty/fmtlib/src",
32 "src/main/native/thirdparty/fmtlib/include",
33 ]:
Austin Schuh812d0d12021-11-04 20:16:48 -070034 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080038 lambda dp, f: dp.startswith("./src") and f.endswith(".cc") and f != "fmt.cc",
James Kuszmaulcf324122023-01-14 14:07:17 -080039 os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"),
40 )
Austin Schuh812d0d12021-11-04 20:16:48 -070041
42 # Copy fmt header files into allwpilib
43 include_files = walk_cwd_and_copy_if(
James Kuszmaulb13e13f2023-11-22 20:44:04 -080044 lambda dp, f: dp.startswith("./include/fmt"),
James Kuszmaulcf324122023-01-14 14:07:17 -080045 os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"),
46 )
Austin Schuh812d0d12021-11-04 20:16:48 -070047
48 for f in src_files:
49 comment_out_invalid_includes(
James Kuszmaulcf324122023-01-14 14:07:17 -080050 f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")]
51 )
Austin Schuh812d0d12021-11-04 20:16:48 -070052 for f in include_files:
53 comment_out_invalid_includes(
James Kuszmaulcf324122023-01-14 14:07:17 -080054 f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")]
55 )
Austin Schuh75263e32022-02-22 18:05:32 -080056
Austin Schuh812d0d12021-11-04 20:16:48 -070057
58if __name__ == "__main__":
59 main()