-
Notifications
You must be signed in to change notification settings - Fork 647
/
Copy pathmemory.py
executable file
·104 lines (78 loc) · 2.87 KB
/
memory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
import os
import shutil
from upstream_utils import Lib, copy_to, walk_if
def run_source_replacements(memory_files):
for wpi_file in memory_files:
with open(wpi_file) as f:
content = f.read()
# Fix #includes
content = content.replace('include "', 'include "wpi/memory/')
content = content.replace(
"wpi/memory/free_list_utils.hpp", "free_list_utils.hpp"
)
with open(wpi_file, "w") as f:
f.write(content)
def run_header_replacements(memory_files):
for wpi_file in memory_files:
if "detail" not in wpi_file:
continue
with open(wpi_file) as f:
content = f.read()
# Fix #includes
content = content.replace('include "config.hpp', 'include "../config.hpp')
with open(wpi_file, "w") as f:
f.write(content)
def run_global_replacements(memory_files):
for wpi_file in memory_files:
with open(wpi_file) as f:
content = f.read()
# Rename namespace from foonathan to wpi
content = content.replace("namespace foonathan", "namespace wpi")
content = content.replace("foonathan::", "wpi::")
content = content.replace("FOONATHAN_", "WPI_")
# Fix #includes
content = content.replace('include "foonathan', 'include "wpi')
with open(wpi_file, "w") as f:
f.write(content)
def copy_upstream_src(wpilib_root):
wpiutil = os.path.join(wpilib_root, "wpiutil")
# Delete old install
for d in [
"src/main/native/thirdparty/memory/src",
"src/main/native/thirdparty/memory/include",
]:
shutil.rmtree(os.path.join(wpiutil, d), ignore_errors=True)
# Copy sources
src_files = walk_if("src", lambda dp, f: f.endswith(".cpp") or f.endswith(".hpp"))
src_files = copy_to(
src_files, os.path.join(wpiutil, "src/main/native/thirdparty/memory")
)
run_global_replacements(src_files)
run_source_replacements(src_files)
# Copy headers
os.chdir(os.path.join("include", "foonathan"))
include_files = walk_if(".", lambda dp, f: f.endswith(".hpp"))
include_files = copy_to(
include_files,
os.path.join(wpiutil, "src/main/native/thirdparty/memory/include/wpi"),
)
os.chdir(os.path.join("..", ".."))
run_global_replacements(include_files)
run_header_replacements(include_files)
# Copy config_impl.hpp
shutil.copyfile(
os.path.join(wpilib_root, "upstream_utils/memory_files/config_impl.hpp"),
os.path.join(
wpiutil,
"src/main/native/thirdparty/memory/include/wpi/memory/config_impl.hpp",
),
)
def main():
name = "memory"
url = "https://github.com/foonathan/memory"
tag = "v0.7-3"
memory = Lib(name, url, tag, copy_upstream_src)
memory.main()
if __name__ == "__main__":
main()