[9.0.0] Compensate for Windows filesystems lacking junction support #27695
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
Bazel fails completely on Windows when using filesystems that don't support junction/reparse point operations (e.g., virtiofs, VirtualBox shared folders, network drives, RAM disks).
The fatal error occurs when
ReadSymlinkOrJunctionfails during path resolution (e.g., when Starlark code calls.realpath): "Cannot read link: DeviceIoControl: Incorrect function".This causes build analysis to abort completely.
Additionally,
CreateJunctionfailures when creating convenience symlinks produce cryptic error messages, though these were already non-fatal warnings.Both fail because
DeviceIoControlreturnsERROR_INVALID_FUNCTIONwhen the filesystem doesn't implementFSCTL_GET_REPARSE_POINTorFSCTL_SET_REPARSE_POINToperations.Proposed solution:
Handle
ERROR_INVALID_FUNCTIONgracefully by treating it as a "not supported" condition rather than a fatal error:ReadSymlinkOrJunction(file.cc:592): returnkNotALinkinstead ofkErrorwhenERROR_INVALID_FUNCTIONoccurs. This allows path resolution to continue for non-symlink paths on unsupported filesystems.CreateJunction(file.cc:461): return newkNotSupportedresult code whenERROR_INVALID_FUNCTIONoccurs. This produces clear "filesystem does not support junctions" warnings instead of cryptic "Incorrect function" messages. This improves UX but doesn't change behavior (these failures were already non-fatal).This follows the try-first, fallback-on-error pattern (EAFP) used by other major projects when handling unsupported filesystem operations.
Prior art:
ERROR_INVALID_FUNCTION,ERROR_NOT_SUPPORTED, andERROR_INVALID_PARAMETERfor filesystem operation fallbacks instd::fs::rename.<filesystem>:read_symlinkdoes not work with junctions microsoft/STL#2077): handles junctions and reparse point errors includingERROR_INVALID_PARAMETERwith robust fallback logic infilesystem.cpp.ERROR_INVALID_FUNCTIONindicatesSTATUS_NOT_IMPLEMENTEDfor unsupported operations.FILE_SUPPORTS_REPARSE_POINTSflag viaGetVolumeInformation, but try-catch approach is simpler and handles edge cases where detection succeeds but operations fail.Impact:
Limitations:
Full junction support would require filesystem-level changes (e.g., virtiofs driver improvements).
Testing:
Tested on Windows 11 VM with host directory mounted via virtiofs, with rules_pkg. Before change: build analysis aborted with "Cannot read link" fatal error. After change: builds complete successfully with clearer warnings about unsupported junctions for convenience symlinks.
Closes #27598.
PiperOrigin-RevId: 833360316
Change-Id: I3751602b2bd793c1cee75b7b66fa73c955a72517
Commit dab96fc