blob: 1088c3937b7f36f31e164f9719e972b7af7ba404 [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 Kuszmaulcf324122023-01-14 14:07:17 -080016 upstream_root = clone_repo("https://github.com/fmtlib/fmt", "9.1.0")
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",
24 "0002-Suppress-C-20-clang-tidy-warning-false-positive.patch",
25 ]:
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 Kuszmaulcf324122023-01-14 14:07:17 -080037 lambda dp, f: dp.endswith("src") and f.endswith(".cc") and f != "fmt.cc",
38 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(
43 lambda dp, f: dp.endswith("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()