Skip to content

Commit d792d1d

Browse files
erwei-xilinxclaude
andcommitted
Make apply_patches.py tolerate CRLF/LF in patch context
On Windows runners (and local Windows clones), git checkout converts text files to CRLF by default, but our patches in third_party/ were generated with LF endings. The mismatch in context lines makes git apply --check report "patch failed: X: patch does not apply" even when the actual change is fine. apply_patches.py was bailing on first conflict — meaning when the Sanitizer/SanitizerAttributes/CMakeLists.txt hunk in triton_shared.patch failed CRLF matching, the PtrAnalysis.cpp hunk (which contains the size_t = ~0ULL fix that prevents an MSVC narrowing-conversion error) never got applied either. The Windows wheel build then died at compile time: PtrAnalysis.cpp(980): error C2397: conversion from 'int' to 'size_t' requires a narrowing conversion Add --ignore-whitespace to all three git apply invocations (check, reverse-check, real apply). git apply documents this flag as making context-line matching tolerant of whitespace differences; in practice CRLF vs LF falls under that tolerance. Linux and macOS behavior is unchanged because their checkouts already match the patch's LF endings. Note: gitattributes can't fix this because they don't cross submodule boundaries — the affected files live inside third_party/triton_shared/, which is its own git repo with its own attribute scope. A workflow-only fix (core.autocrlf=false) would help CI but not local Windows developers; this fix helps both. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c65c2c9 commit d792d1d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

scripts/apply_patches.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ def check_patch_applicable(patch_file: Path, target_dir: Path) -> tuple[bool, st
7777
Returns:
7878
(can_apply, reason) tuple
7979
"""
80+
# --ignore-whitespace tolerates CRLF/LF differences in context lines,
81+
# which matters on Windows where git checkout converts text files to
82+
# CRLF by default but our patches were generated with LF.
8083
result = run_git(
81-
["apply", "--check", str(patch_file)],
84+
["apply", "--check", "--ignore-whitespace", str(patch_file)],
8285
cwd=target_dir,
8386
check=False,
8487
)
@@ -88,7 +91,7 @@ def check_patch_applicable(patch_file: Path, target_dir: Path) -> tuple[bool, st
8891

8992
# Check if patch is already applied by trying reverse
9093
result_reverse = run_git(
91-
["apply", "--check", "--reverse", str(patch_file)],
94+
["apply", "--check", "--reverse", "--ignore-whitespace", str(patch_file)],
9295
cwd=target_dir,
9396
check=False,
9497
)
@@ -102,7 +105,7 @@ def check_patch_applicable(patch_file: Path, target_dir: Path) -> tuple[bool, st
102105
def apply_patch(patch_file: Path, target_dir: Path) -> bool:
103106
"""Apply a patch file to the target directory."""
104107
try:
105-
run_git(["apply", str(patch_file)], cwd=target_dir)
108+
run_git(["apply", "--ignore-whitespace", str(patch_file)], cwd=target_dir)
106109
return True
107110
except subprocess.CalledProcessError as e:
108111
print(f" ✗ Failed to apply patch: {e.stderr}", file=sys.stderr)

0 commit comments

Comments
 (0)