blob: 25eabfc4939cecce4c6e9c545cce72b11dfa0f19 [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():
16 upstream_root = clone_repo("https://github.com/ludocode/mpack", "v1.1")
17 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",
34 ]:
35 git_am(
36 os.path.join(wpilib_root, "upstream_utils/mpack_patches", f),
37 )
38
39 # Run the amalgmation script
40 subprocess.check_call(["bash", "tools/amalgamate.sh"])
41
42 # Copy the files
43 amalgamation_source_dir = os.path.join(
44 ".", ".build", "amalgamation", "src", "mpack"
45 )
46 os.chdir(amalgamation_source_dir)
47
48 walk_cwd_and_copy_if(
49 lambda dp, f: f.endswith(".h"),
50 os.path.join(wpiutil, "src/main/native/thirdparty/mpack/include/wpi"),
51 )
52 walk_cwd_and_copy_if(
53 lambda dp, f: f.endswith(".c"),
54 os.path.join(wpiutil, "src/main/native/thirdparty/mpack/src"),
55 )
56
57
58if __name__ == "__main__":
59 main()