blob: 746e879ad2458fa4040f35e6e05b230a547e8eb4 [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",
James Kuszmaulcf324122023-01-14 14:07:17 -080025 ]:
26 git_am(os.path.join(wpilib_root, "upstream_utils/fmt_patches", f))
Austin Schuh812d0d12021-11-04 20:16:48 -070027
28 # Delete old install
James Kuszmaulcf324122023-01-14 14:07:17 -080029 for d in [
30 "src/main/native/thirdparty/fmtlib/src",
31 "src/main/native/thirdparty/fmtlib/include",
32 ]:
Austin Schuh812d0d12021-11-04 20:16:48 -070033 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080037 lambda dp, f: dp.startswith("./src") and f.endswith(".cc") and f != "fmt.cc",
James Kuszmaulcf324122023-01-14 14:07:17 -080038 os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"),
39 )
Austin Schuh812d0d12021-11-04 20:16:48 -070040
41 # Copy fmt header files into allwpilib
42 include_files = walk_cwd_and_copy_if(
James Kuszmaulb13e13f2023-11-22 20:44:04 -080043 lambda dp, f: dp.startswith("./include/fmt"),
James Kuszmaulcf324122023-01-14 14:07:17 -080044 os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib"),
45 )
Austin Schuh812d0d12021-11-04 20:16:48 -070046
47 for f in src_files:
48 comment_out_invalid_includes(
James Kuszmaulcf324122023-01-14 14:07:17 -080049 f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")]
50 )
Austin Schuh812d0d12021-11-04 20:16:48 -070051 for f in include_files:
52 comment_out_invalid_includes(
James Kuszmaulcf324122023-01-14 14:07:17 -080053 f, [os.path.join(wpiutil, "src/main/native/thirdparty/fmtlib/include")]
54 )
Austin Schuh75263e32022-02-22 18:05:32 -080055
Austin Schuh812d0d12021-11-04 20:16:48 -070056
57if __name__ == "__main__":
58 main()