Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SCsub, fix cpplize_debugger.py and add missing header (<tuple>). #143

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions SCsub
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
#!/usr/bin/env python

from debugger_ui import cpplize_debugger

cpplize_debugger.create_debugger_header()
import os
from debugger_ui import cpplize_debugger

Import("env")
Import("env_modules")

# Get the absolute path to the current directory where SCsub is located
source_path = env.Dir('.').abspath
print(f"source_path: {source_path}")

# Call the function with the correct source_path
cpplize_debugger.create_debugger_header(source_path)

# Clone the module environment
env_network_synchronizer = env_modules.Clone()

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

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

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

# Add the GENERATE_DEBUG_SYMBOLS preprocessor definition
env_network_synchronizer.Append(CPPDEFINES=["GENERATE_DEBUG_SYMBOLS=ON"])

# Add source files to the environment
env_network_synchronizer.add_source_files(env.modules_sources, "core/**.cpp")
env_network_synchronizer.add_source_files(env.modules_sources, "godot4/**.cpp")
env_network_synchronizer.add_source_files(env.modules_sources, "*.cpp")
env_network_synchronizer.add_source_files(env.modules_sources, "tests/**.cpp")

# Invoke CMake with the GENERATE_DEBUG_SYMBOLS flag
env.Execute("cmake ../cmake/ -DGENERATE_DEBUG_SYMBOLS=ON")
86 changes: 52 additions & 34 deletions debugger_ui/cpplize_debugger.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
from os import listdir
from os.path import isfile, join, isdir, exists
import os
import sys

def create_debugger_header(source_path):

f = open(source_path + "/core/__generated__debugger_ui.h", "w", encoding="utf-8")
f.write("#pragma once\n")
f.write("\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, you can 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 eventual\n")
f.write("/// changes made on that file.\n")
f.write("\n")
f.write("static const char __debugger_ui_code[] = R\"TheCodeRKS(")

size = 0
with open(source_path + '/debugger_ui/debugger.py', encoding="utf-8") as deb_f:
for l in deb_f.readlines():
l_utf8 = l.encode('utf-8')
size += len(l_utf8)
f.write(l);

f.write(" )TheCodeRKS\";\n")
f.write("static unsigned int __debugger_ui_code_size = "+str(size)+";\n")
f.close()

"""
Creates the generated header file for the debugger UI.

if len(sys.argv) < 2:
print("Usage: cpplize_debugger.py <source_path>")
sys.exit(1)
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)

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

create_debugger_header(source_path)
2 changes: 2 additions & 0 deletions tests/test_data_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "../core/net_math.h"
#include "../core/scene_synchronizer_debugger.h"

#include <tuple>

NS::SceneSynchronizerDebugger debugger;

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