GameNetworking / NetworkSynchronizer

Lib to create realtime multiplayer game. It uses Prediction & Rewinding networking model.
MIT License
94 stars 19 forks source link

The file cpplize_debugger.py does not compile on linux. #141

Open Malkverbena opened 1 month ago

Malkverbena commented 1 month ago
Building for platform "linuxbsd", architecture "x86_64", target "editor".
FileNotFoundError: [Errno 2] No such file or directory: '-j8/core/__generated__debugger_ui.h':
  File "/media/cleber/DATA/COMPILATIONS/godot/SConstruct", line 1082:
    SConscript("modules/SCsub")
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/media/cleber/DATA/COMPILATIONS/godot/modules/SCsub", line 73:
    SConscript(base_path + "/SCsub")
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 661:
    return method(*args, **kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 598:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python3/dist-packages/SCons/Script/SConscript.py", line 287:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/media/cleber/DATA/COMPILATIONS/godot/modules/NetworkSynchronizer/SCsub", line 3:
    from debugger_ui import cpplize_debugger
  File "/media/cleber/DATA/COMPILATIONS/godot/modules/NetworkSynchronizer/debugger_ui/cpplize_debugger.py", line 40:
    create_debugger_header(source_path)
  File "/media/cleber/DATA/COMPILATIONS/godot/modules/NetworkSynchronizer/debugger_ui/cpplize_debugger.py", line 7:
    f = open(source_path + "/core/__generated__debugger_ui.h", "w", encoding="utf-8")
Malkverbena commented 1 month ago

The "create_debugger_header" function is receiving the first argument used after the scons command. This is generating errors. For example, if I use "-j8", the argument received by the function is "-j8". I believe the error is in SCsub, when the function is invoked.

What the function "create_debugger_header" supose to recive?

Malkverbena commented 1 month ago

Line 8 will also cause issues on different platforms. The ideal would be to use: To ensure that your code works on Windows, Linux, and macOS, it is important to use directory separators that are compatible with all operating systems. In Python, the recommended way to build platform-independent file paths is by using os.path.join. Like this:

f = open(os.path.join(source_path, "core", "__generated__debugger_ui.h"), "w", encoding="utf-8")
AndreaCatania commented 1 month ago

I think the issue is caused by a recent change I needed to make in order to use the cpplize_debugger.py with CMake.

The change I did was adding these lines https://github.com/GameNetworking/NetworkSynchronizer/blob/main/debugger_ui/cpplize_debugger.py#L34-L40

With those lines, as soon as you execute that file the file is generated. The way I'm using it with CMake is this one: https://github.com/GameNetworking/NetworkSynchronizer/blob/main/cmake/CMakeLists.txt#L35-L39

The fix is to refactor the way the SCsub is implemented so that it "executes" the script instead of importing it and calling the function. If you have any other idea, I'm open to it.

Malkverbena commented 1 month ago

What do you think about including a method to fix the value of the "source_path" variable?

Somethink like:

source_path = os.path.dirname(os.path.abspath(__file__))
AndreaCatania commented 1 month ago

On the SCsub? I think that make sense

Malkverbena commented 1 month ago

Yes. but also can be done on cpplize_debugger.py. Depends what you have in mind. Simple adding the lines below to cpplize_debugger.py you can fix it. This makes the script determine the source_path insted to depend of poarameters coming from another scripts

    source_path = os.path.dirname(os.path.abspath(__file__))
    source_path = os.path.dirname(source_path)
Malkverbena commented 1 month ago

What do you think about this solution?

def create_debugger_header(source_path):

    if not os.path.exists(source_path):
        source_path = os.path.dirname(os.path.abspath(__file__))
        source_path = os.path.dirname(source_path)
AndreaCatania commented 1 month ago

I would prefer to have this logic inside the Scons config instead and prevent this section https://github.com/GameNetworking/NetworkSynchronizer/blob/main/debugger_ui/cpplize_debugger.py#L34-L40 from executing when the file is imported, somehow.

Malkverbena commented 1 month ago

I dont undestood exacly when the funcion "create_debugger_header" is called. This function is being called on SCsub and on cpplize_debugger. In other words, it is being invoked twice. When this function is supposed to be called?

Malkverbena commented 1 month ago

Should the "source_path" variable be passed in the function call or discovered automatically?

AndreaCatania commented 1 month ago

I prefer that we pass the path, because automatic discovering the directory is not going to work in all situations.

Malkverbena commented 1 month ago

I just updated my fork and cant compile at all. After the #138 I got tons of errors. Ill open a diferent issue foir that.