Skip to content

Commit 4680107

Browse files
committed
Fix SCsub, fix cpplize_debugger.py and add missing header (<tuple>).
1 parent ea99887 commit 4680107

File tree

3 files changed

+74
-37
lines changed

3 files changed

+74
-37
lines changed

SCsub

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
#!/usr/bin/env python
22

3-
from debugger_ui import cpplize_debugger
43

5-
cpplize_debugger.create_debugger_header()
4+
import os
5+
from debugger_ui import cpplize_debugger
66

77
Import("env")
88
Import("env_modules")
99

10+
# Get the absolute path to the current directory where SCsub is located
11+
source_path = env.Dir('.').abspath
12+
print(f"source_path: {source_path}")
13+
14+
# Call the function with the correct source_path
15+
cpplize_debugger.create_debugger_header(source_path)
16+
17+
# Clone the module environment
1018
env_network_synchronizer = env_modules.Clone()
1119

20+
# Check if Tracy is enabled and add the definition if necessary
1221
if "tracy_enable" in env and env["tracy_enable"] == "yes":
1322
env_network_synchronizer.Append(CPPDEFINES=["TRACY_ENABLE"])
1423

15-
# TODO ensure debugs are enabled only in debug builds.
24+
# TODO: Ensure that debugs are enabled only in debug builds.
1625
env_network_synchronizer.Append(CPPDEFINES=["NS_DEBUG_ENABLED"])
1726

27+
# Add the definition to disable the debug data buffer
1828
env_network_synchronizer.Append(CPPDEFINES=["DISABLE_DEBUG_DATA_BUFFER"])
1929

30+
# Add the GENERATE_DEBUG_SYMBOLS preprocessor definition
31+
env_network_synchronizer.Append(CPPDEFINES=["GENERATE_DEBUG_SYMBOLS=ON"])
32+
33+
# Add source files to the environment
2034
env_network_synchronizer.add_source_files(env.modules_sources, "core/**.cpp")
2135
env_network_synchronizer.add_source_files(env.modules_sources, "godot4/**.cpp")
2236
env_network_synchronizer.add_source_files(env.modules_sources, "*.cpp")
2337
env_network_synchronizer.add_source_files(env.modules_sources, "tests/**.cpp")
38+
39+
# Invoke CMake with the GENERATE_DEBUG_SYMBOLS flag
40+
env.Execute("cmake ../cmake/ -DGENERATE_DEBUG_SYMBOLS=ON")

debugger_ui/cpplize_debugger.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,58 @@
1-
from os import listdir
2-
from os.path import isfile, join, isdir, exists
1+
import os
32
import sys
43

54
def create_debugger_header(source_path):
6-
7-
f = open(source_path + "/core/__generated__debugger_ui.h", "w", encoding="utf-8")
8-
f.write("#pragma once\n")
9-
f.write("\n")
10-
f.write("/// This is a generated file by `cpplize_debugger.py`, executed by `SCsub`.\n")
11-
f.write("/// \n")
12-
f.write("/// DO NOT EDIT this header.\n")
13-
f.write("/// If you want to modify this python code, you can simply change `debugger.py`\n")
14-
f.write("/// During the next compilation this header will be updated.\n")
15-
f.write("/// \n")
16-
f.write("/// HOWEVER! The file will not be copied into the `bin` folder unless you remove the\n")
17-
f.write("/// existing `bin/debugger.py` first; this algorithm prevents destroying eventual\n")
18-
f.write("/// changes made on that file.\n")
19-
f.write("\n")
20-
f.write("static const char __debugger_ui_code[] = R\"TheCodeRKS(")
21-
22-
size = 0
23-
with open(source_path + '/debugger_ui/debugger.py', encoding="utf-8") as deb_f:
24-
for l in deb_f.readlines():
25-
l_utf8 = l.encode('utf-8')
26-
size += len(l_utf8)
27-
f.write(l);
28-
29-
f.write(" )TheCodeRKS\";\n")
30-
f.write("static unsigned int __debugger_ui_code_size = "+str(size)+";\n")
31-
f.close()
32-
5+
"""
6+
Creates the generated header file for the debugger UI.
337
34-
if len(sys.argv) < 2:
35-
print("Usage: cpplize_debugger.py <source_path>")
36-
sys.exit(1)
8+
Args:
9+
source_path (str): The path to the source directory where the header will be created.
10+
"""
11+
# Define the path to the 'core' directory
12+
core_dir = os.path.join(source_path, "core")
13+
14+
# Create the 'core' directory if it doesn't exist
15+
os.makedirs(core_dir, exist_ok=True)
16+
17+
# Define the full path to the generated header file
18+
header_path = os.path.join(core_dir, "__generated__debugger_ui.h")
19+
20+
try:
21+
with open(header_path, "w", encoding="utf-8") as f:
22+
f.write("#pragma once\n\n")
23+
f.write("/// This is a generated file by `cpplize_debugger.py`, executed by `SCsub`.\n")
24+
f.write("///\n")
25+
f.write("/// DO NOT EDIT this header.\n")
26+
f.write("/// If you want to modify this Python code, simply change `debugger.py`\n")
27+
f.write("/// During the next compilation, this header will be updated.\n")
28+
f.write("///\n")
29+
f.write("/// HOWEVER! The file will not be copied into the `bin` folder unless you remove the\n")
30+
f.write("/// existing `bin/debugger.py` first; this algorithm prevents destroying any\n")
31+
f.write("/// changes made to that file.\n\n")
32+
f.write("static const char __debugger_ui_code[] = R\"TheCodeRKS(\n")
33+
34+
size = 0
35+
debugger_py_path = os.path.join(source_path, 'debugger_ui', 'debugger.py')
36+
37+
if not os.path.isfile(debugger_py_path):
38+
print(f"Error: The file '{debugger_py_path}' was not found.")
39+
sys.exit(1)
40+
41+
with open(debugger_py_path, encoding="utf-8") as deb_f:
42+
for line in deb_f:
43+
line_utf8 = line.encode('utf-8')
44+
size += len(line_utf8)
45+
f.write(line)
46+
47+
f.write(")TheCodeRKS\";\n")
48+
f.write(f"static unsigned int __debugger_ui_code_size = {size};\n")
49+
50+
print(f"Header file successfully generated at '{header_path}'.")
51+
52+
except IOError as e:
53+
print(f"Error writing the header file: {e}")
54+
sys.exit(1)
3755

38-
source_path = sys.argv[1]
56+
# The create_debugger_header function is called directly from SCsub,
57+
# so there's no need for a main function handling sys.argv.
3958

40-
create_debugger_header(source_path)

tests/test_data_buffer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "../core/net_math.h"
66
#include "../core/scene_synchronizer_debugger.h"
77

8+
#include <tuple>
9+
810
NS::SceneSynchronizerDebugger debugger;
911

1012
inline std::vector<std::int64_t> int_values(NS::DataBuffer::CompressionLevel p_compression_level) {

0 commit comments

Comments
 (0)