-
-
Notifications
You must be signed in to change notification settings - Fork 687
Fix CMake generation on Windows #536
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
Conversation
On Windows, paths are mixed by os.path.join with different slash directions. This should generally be fine but when using the print function we print "C:\\mypath/myfile.cpp" as "C:\mypath/myfile.cpp" which is unescaped on the backward slash. To fix this I propose to replace "\\" with "/" just before printing it out for CMake usage. I would suggest using pathlib but it is not included by default on python versions <= 3.3 which may still be an issue.
|
Catch this on our GDNative project. When this will be merged? |
|
I don't really understand this change. If we want to use Also, I don't think we need to worry about compatibility with EOL Python versions. Everyone should have a maintained Python 3 version installed. |
|
In summary, the change fixes the following issue: when you create a path in python for some file the path will be with mixed slashes "/" and "\". Both python and cmake can handle those but... python as other programming languages will store back slashes escaped "C:\\Program Files\\Project/file.h" but when you call print so that they are provided to CMake it will actually print them unescaped as "C:\Program Files\Project/file.h" and then CMake will crash saying it doesn't know what the escape symbol "\P" means. |
|
And to answer your question - yes it is better to not use os.path.join and instead use Pathlib but it is only recently added by default in python versions higher than 3.3 . If you're okay with that I will change this commit to instead use Pathlib for the paths in python and then call the as_posix() method when printing them out to CMake. |
I do understand the issue, I just don't understand why there are paths with mixed slashes in the first place. I would prefer not have mixed slashes to begin with instead of fixing them with a post-hoc replace. I'm okay with using pathlib. As I said, we should not need to keep compatibility with EOL Python versions (even 3.4 is EOL now). I'd rather have a proper fix instead of patching this, because otherwise it'll never be fixed properly. |
It was causing issue on windows with escaped backwards slashes. This should now solve the issue as PosixPath will always be used which is understandable both by CMake and python and doesn't require backwards slashes.
|
@vnen I modified the generators file to now use pathlib and Path by default so that it doesn't cause issues on windows. |
…re printing it out
|
I've tried to use it in our project and get error: I worked on cb837cb |
|
i will check it out tomorrow |
|
I suppose it was better to accept fix as is and refactor it later especially after accepting CI changes. |
|
Nah, my fix was merely the simplest solution and I thoutght it would be enough. Anyway it is better to address the underlying problem and provide a good fix even if it causes a few more issues before its ideal. |
…ors. Also now calling Path.open(mode) instead of open(Path, mode).
|
@o01eg Can you try and reproduce the issue with the latest commit? I wasn't able to reproduce it on my PC and the windows build seems to be successful. |
|
@object71 Yes, it works |
|
I checked out @object71 code and reduced the hundreds of errors to one: |
|
Well, I'll need to check that out. What hundreds of errors? |
|
Do we need to wait fix for Ninja generator to merge it? |
|
I think this could be merged anyway - the error described above is just a warning. It is just that @kelteseth has made it into an error report which blocks the Ninja generation. EDIT: and by looking at it, it should be also reproducible without my change. I couldn't find how I can produce the same issue but my change doesn't enumerate more files. It just enumerates them with the correct slashes. |
|
I've added CMake+Ninja test to Linux CI and it works: #518 |
|
Well I guess someone responsible for merging should make the decision. My opinion is that the error described above is not caused from my changes and I couldn't reproduce it neither on windows neither on linux machine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Congratulations for your first merged pull request 🎉
|
I know this is old and dead, but I encountered the issues described with duplicate build objects when running with CLion. I've got a stop-gap fix here: https://github.com/godotengine/godot-cpp/compare/3.x...zphensley42:godot-cpp:fix/3.x_duplicate_ninja_error?expand=1 I hope it helps someone. |
On Windows, paths are mixed by os.path.join with different slash directions. This should generally be fine but when using the print function we print "C:\\mypath/myfile.cpp" as "C:\mypath/myfile.cpp" which is unescaped on the backward slash. To fix this I propose to replace "\\" with "/" just before printing it out for CMake usage. I would suggest using pathlib but it is not included by default on python versions <= 3.3 which may still be an issue.