Wrong escape sequence paths with spaces in MSCV
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
Background: my Windows project symlinks the C:\ directory as an external repository so that I can depend on system libraries.
```
# system_deps.bzl
def _is_windows(repo_ctx):
return repo_ctx.os.name.lower().startswith("windows")
windows_system_build = \
"""
package(default_visibility = ["//visibility:public"])
cc_library(
name = "cudnn",
includes = ["c/Program Files/NVIDIA/CUDNN/v9.0/include"],
srcs = glob([
"c/Program Files/NVIDIA/CUDNN/v9.0/bin/*.dll",
"c/Program Files/NVIDIA/CUDNN/v9.0/lib/x64/*.lib"
],)
)
"""
linux_system_build = "" # omitted for readability
def _system_deps_impl(repository_ctx):
if _is_windows(repository_ctx):
repository_ctx.symlink("C:/", "c")
repository_ctx.file("BUILD", windows_system_build, executable=False)
else:
repository_ctx.symlink("/usr", "usr")
repository_ctx.symlink("/opt", "opt")
repository_ctx.file("BUILD", linux_system_build, executable=False)
system_deps = repository_rule(
implementation = _system_deps_impl,
)
def _init(module_ctx):
# instantiate the system deps repo
system_deps(name = "system_deps")
make_system_deps = module_extension(implementation = _init)
```
```
# MODULE.bazel
make_system_deps = use_extension("@//:system_deps.bzl", "make_system_deps")
use_repo(make_system_deps, "system_deps")
```
Now in my `BUILD` files I can depend on `@system_deps//:cudnn`. This works, as long as the `@system_deps//:cudnn` target's `includes` list has paths which do not include spaces. However, if there are spaces, as in "Program Files", the compilation fails. Here is the error reported from cl for a little test binary that depends on the `@system_deps//:cudnn`.
```
cl : Command line warning D9024 : unrecognized source file type 'Files/NVIDIA/CUDNN/v9.0/include', object file assumed
```
Looking at the related `.params` file, the related line is
```
/Iexternal/_main~make_system_deps~system_deps/c/Program\ Files/NVIDIA/CUDNN/v9.0/include
```
I believe what is happening is that the space in "Program Files" is not being properly escaped. Doing a little research, I found maybe it's supposed to be the caret symbol `^`. Or maybe just surrounding the whole thing in quotes will fix the issue.
### Which category does this issue belong to?
C++ Rules
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
You may copy my setup and place some dummy files at 'C:\Program Files\NVIDIA\...`
### Which operating system are you running Bazel on?
Windows 10
### What is the output of `bazel info release`?
release 8.1.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
This post says use the caret symbol https://superuser.com/a/279121/238769
### Any other information, logs, or outputs that you want to share?
I'm using Visual Studio 2022
Contributor guide
Research direction
Reproduce the issue from system_deps.bzl and MODULE.bazel on Windows 10 with the shown BUILD target, then inspect the generated .params file and the cl invocation. Trace how the C++ rules serialize the includes path containing "Program Files"; done means the path reaches cl without being split and the test binary compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100