diff --git a/SCsub b/SCsub index 2e14dfc..4268682 100644 --- a/SCsub +++ b/SCsub @@ -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") diff --git a/debugger_ui/cpplize_debugger.py b/debugger_ui/cpplize_debugger.py index 86572dc..b15c33d 100644 --- a/debugger_ui/cpplize_debugger.py +++ b/debugger_ui/cpplize_debugger.py @@ -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 ") - 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) diff --git a/tests/test_data_buffer.cpp b/tests/test_data_buffer.cpp index a4b02fa..3612dec 100644 --- a/tests/test_data_buffer.cpp +++ b/tests/test_data_buffer.cpp @@ -5,6 +5,8 @@ #include "../core/net_math.h" #include "../core/scene_synchronizer_debugger.h" +#include + NS::SceneSynchronizerDebugger debugger; inline std::vector int_values(NS::DataBuffer::CompressionLevel p_compression_level) {