network_synchronizer icon indicating copy to clipboard operation
network_synchronizer copied to clipboard

The file cpplize_debugger.py does not compile on linux.

Open Malkverbena opened this issue 1 year ago • 12 comments

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 avatar Sep 17 '24 12:09 Malkverbena

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 avatar Sep 17 '24 14:09 Malkverbena

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")

Malkverbena avatar Sep 17 '24 15:09 Malkverbena

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.

AndreaCatania avatar Sep 17 '24 15:09 AndreaCatania

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__))

Malkverbena avatar Sep 17 '24 15:09 Malkverbena

On the SCsub? I think that make sense

AndreaCatania avatar Sep 17 '24 15:09 AndreaCatania

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 avatar Sep 17 '24 16:09 Malkverbena

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)

Malkverbena avatar Sep 17 '24 16:09 Malkverbena

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.

AndreaCatania avatar Sep 17 '24 18:09 AndreaCatania

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 avatar Sep 17 '24 21:09 Malkverbena

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

Malkverbena avatar Sep 20 '24 13:09 Malkverbena

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

AndreaCatania avatar Sep 20 '24 19:09 AndreaCatania

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.

Malkverbena avatar Sep 20 '24 19:09 Malkverbena