Skip to content

Ninja build file generated with backslashes on Windows #113

@aleclouisgrant

Description

@aleclouisgrant

(on Windows 10)
When I run configure.py, the generated build.ninja uses single backslashes in all of its paths for the commands that makes running ninja to build the project fail for me.
For example:

$ python configure.py 
$ ninja 
[1/3] TOOL 'build\tools\dtk.exe' FAILED: [code=2] build\tools\dtk.exe "C:\Python311\python.exe" tools\download_tool.py dtk 'build\tools\dtk.exe' --tag v1.3.0 C:\Python311\python.exe: can't open file 'C:\\Users\\$USERNAME\\Games\\Game Development\\Decomp\\sms\\toolsdownload_tool.py': [Errno 2] No such file or directory ninja: error: rebuilding 'build.ninja': subcommand failed

Specifically it's the \\toolsdownload_tool.py part of the path that should be tools/download_tool.py

This is from tools/ninja_syntax.py [211] :

def serialize_path(input: Optional[NinjaPath]) -> str:
    if not input:
        return ""
    if isinstance(input, Path):
        return str(input).replace("/", os.sep)
    else:
        return str(input)

I know that we are trying to be good by using os.sep but that maps to a backslash on Windows which ninja seemingly doesn't interpret nicely for paths on Windows when used as part of its build.ninja file.

When I brute force changed it to:

def serialize_path(input: Optional[NinjaPath]) -> str:
    if not input:
        return ""
    else:
        return str(input).replace('\\', '/')

it built correctly for me.

I don't necessarily know if that change is the best approach because I am not familiar with the rest of the building process and how it could impact Linux/MacOS users - also probably the .replace('\\', '/') is redundant if we were only replacing forward slash with os.sep before, but wanted to see if this is an issue that other people have had on Windows and if so, if there was value in me pursuing it further.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions