-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcpplize_debugger.py
More file actions
58 lines (45 loc) · 2.36 KB
/
cpplize_debugger.py
File metadata and controls
58 lines (45 loc) · 2.36 KB
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
import os
import sys
def create_debugger_header(source_path):
"""
Creates the generated header file for the debugger UI.
Args:
source_path (str): The path to the source directory where the header will be created.
"""
# Define the path to the 'core' directory
core_dir = os.path.join(source_path, "core")
# Create the 'core' directory if it doesn't exist
os.makedirs(core_dir, exist_ok=True)
# Define the full path to the generated header file
header_path = os.path.join(core_dir, "__generated__debugger_ui.h")
try:
with open(header_path, "w", encoding="utf-8") as f:
f.write("#pragma once\n\n")
f.write("/// This is a generated file by `cpplize_debugger.py`, executed by `SCsub`.\n")
f.write("///\n")
f.write("/// DO NOT EDIT this header.\n")
f.write("/// If you want to modify this Python code, simply change `debugger.py`\n")
f.write("/// During the next compilation, this header will be updated.\n")
f.write("///\n")
f.write("/// HOWEVER! The file will not be copied into the `bin` folder unless you remove the\n")
f.write("/// existing `bin/debugger.py` first; this algorithm prevents destroying any\n")
f.write("/// changes made to that file.\n\n")
f.write("static const char __debugger_ui_code[] = R\"TheCodeRKS(\n")
size = 0
debugger_py_path = os.path.join(source_path, 'debugger_ui', 'debugger.py')
if not os.path.isfile(debugger_py_path):
print(f"Error: The file '{debugger_py_path}' was not found.")
sys.exit(1)
with open(debugger_py_path, encoding="utf-8") as deb_f:
for line in deb_f:
line_utf8 = line.encode('utf-8')
size += len(line_utf8)
f.write(line)
f.write(")TheCodeRKS\";\n")
f.write(f"static unsigned int __debugger_ui_code_size = {size};\n")
print(f"Header file successfully generated at '{header_path}'.")
except IOError as e:
print(f"Error writing the header file: {e}")
sys.exit(1)
# The create_debugger_header function is called directly from SCsub,
# so there's no need for a main function handling sys.argv.