blob: 68315e933a9da8a0674295ca6e2688432db10284 [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001#!/usr/bin/env python3
2
3import os
4import shutil
5import subprocess
6
7from upstream_utils import (
8 get_repo_root,
9 clone_repo,
10 walk_cwd_and_copy_if,
11 git_am,
12)
13
14
15def main():
James Kuszmaulb13e13f2023-11-22 20:44:04 -080016 upstream_root = clone_repo("https://github.com/ludocode/mpack", "v1.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 # Delete old install
21 for d in [
22 "src/main/native/thirdparty/mpack/src",
23 "src/main/native/thirdparty/mpack/include",
24 ]:
25 shutil.rmtree(os.path.join(wpiutil, d), ignore_errors=True)
26
27 # Apply patches to upstream Git repo
28 os.chdir(upstream_root)
29
30 for f in [
31 "0001-Don-t-emit-inline-defs.patch",
32 "0002-Update-amalgamation-script.patch",
33 "0003-Use-namespace-for-C.patch",
James Kuszmaulb13e13f2023-11-22 20:44:04 -080034 "0004-Group-doxygen-into-MPack-module.patch",
James Kuszmaulcf324122023-01-14 14:07:17 -080035 ]:
36 git_am(
37 os.path.join(wpilib_root, "upstream_utils/mpack_patches", f),
38 )
39
40 # Run the amalgmation script
41 subprocess.check_call(["bash", "tools/amalgamate.sh"])
42
43 # Copy the files
44 amalgamation_source_dir = os.path.join(
45 ".", ".build", "amalgamation", "src", "mpack"
46 )
47 os.chdir(amalgamation_source_dir)
48
49 walk_cwd_and_copy_if(
50 lambda dp, f: f.endswith(".h"),
51 os.path.join(wpiutil, "src/main/native/thirdparty/mpack/include/wpi"),
52 )
53 walk_cwd_and_copy_if(
54 lambda dp, f: f.endswith(".c"),
55 os.path.join(wpiutil, "src/main/native/thirdparty/mpack/src"),
56 )
57
58
59if __name__ == "__main__":
60 main()