Skip to content

fix: Windows spaces in manifest paths - #1296

Merged
fmeum merged 2 commits into
bazel-contrib:mainfrom
AustinSchuh:windows-spaces-in-manifest-paths
Sep 16, 2026
Merged

fmeum merged 2 commits into
bazel-contrib:mainfrom
AustinSchuh:windows-spaces-in-manifest-paths

Conversation

@AustinSchuh

Copy link
Copy Markdown
Contributor

The batch rlocation helper parsed manifest lines with
for /F "tokens=2*" and kept only %%i, the first space-delimited word
of the target path. Bazel escapes a manifest entry only when the
RLOCATION path contains a space or a newline, marking such lines with a
leading space; in an unescaped line the first space is the separator and
everything after it is the target, spaces included. Keeping %%i
therefore truncated every target under a path like
C:/Users/First Last/... to C:/Users/First.

Every consumer of BATCH_RLOCATION_FUNCTION was affected. diff_test, for
example, reported

ERROR: Cannot compare directory "_main/pkg/_gendir" and a file
"_main/pkg/src/generated"

because the source directory resolved to a path that does not exist, so
its if exist check failed. Split on the first space instead.

Resolving the path correctly then exposed a second defect: the launcher
invoked bash -c "!run_script! !args!" unquoted, so bash word-split the
now-correct path at its spaces. Quote it.

The batch rlocation helper parsed manifest lines with
`for /F "tokens=2*"` and kept only `%%i`, the first space-delimited word
of the target path. Bazel escapes a manifest entry only when the
RLOCATION path contains a space or a newline, marking such lines with a
leading space; in an unescaped line the first space is the separator and
everything after it is the target, spaces included. Keeping `%%i`
therefore truncated every target under a path like
C:/Users/First Last/... to C:/Users/First.

Every consumer of BATCH_RLOCATION_FUNCTION was affected. diff_test, for
example, reported

  ERROR: Cannot compare directory "_main/pkg/_gendir" and a file
         "_main/pkg/src/generated"

because the source directory resolved to a path that does not exist, so
its `if exist` check failed. Split on the first space instead.

Resolving the path correctly then exposed a second defect: the launcher
invoked `bash -c "!run_script! !args!"` unquoted, so bash word-split the
now-correct path at its spaces. Quote it.

Signed-off-by: Austin Schuh <austin.linux@gmail.com>
…dstr

create_windows_native_launcher_script declares the .bat as a sibling of
the shell script it runs, so in the common case the payload sits next to
the launcher and can be named directly from %~dp0 plus a basename known
at analysis time.

Doing that first avoids two failure modes of the manifest lookup, both
reported in bazel-contrib#1287: findstr.exe cannot open a manifest whose path exceeds
MAX_PATH, which LongPathsEnabled does not lift for cmd.exe built-ins; and
when Bazel invokes the .bat through its 8.3 short-path alias, %~f0.runfiles
expands to a directory that does not exist, because 8.3 aliases are
allocated per file and a literal suffix cannot be appended to one.

The manifest lookup is kept as a fallback for when the sibling is absent,
so launchers staged apart from their payload keep working.

Signed-off-by: Austin Schuh <austin.linux@gmail.com>
@AustinSchuh AustinSchuh changed the title Windows spaces in manifest paths Fix: Windows spaces in manifest paths Sep 12, 2026
@AustinSchuh AustinSchuh changed the title Fix: Windows spaces in manifest paths fix: Windows spaces in manifest paths Sep 12, 2026
@fmeum
fmeum enabled auto-merge (squash) September 16, 2026 11:12
@fmeum
fmeum merged commit 7ca5f6d into bazel-contrib:main Sep 16, 2026
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants