James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import os |
| 4 | import shutil |
| 5 | import subprocess |
| 6 | |
| 7 | from upstream_utils import ( |
| 8 | get_repo_root, |
| 9 | clone_repo, |
| 10 | comment_out_invalid_includes, |
| 11 | walk_cwd_and_copy_if, |
| 12 | git_am, |
| 13 | ) |
| 14 | |
| 15 | |
| 16 | def crlf_to_lf(stackwalker_dir): |
| 17 | for root, _, files in os.walk(stackwalker_dir): |
| 18 | if ".git" in root: |
| 19 | continue |
| 20 | |
| 21 | for fname in files: |
| 22 | filename = os.path.join(root, fname) |
| 23 | print(f"Converting CRLF -> LF for {filename}") |
| 24 | with open(filename, "rb") as f: |
| 25 | content = f.read() |
| 26 | content = content.replace(b"\r\n", b"\n") |
| 27 | |
| 28 | with open(filename, "wb") as f: |
| 29 | f.write(content) |
| 30 | |
| 31 | cwd = os.getcwd() |
| 32 | os.chdir(stackwalker_dir) |
| 33 | subprocess.check_call(["git", "add", "-A"]) |
| 34 | subprocess.check_call(["git", "commit", "-m", "Fix line endings"]) |
| 35 | os.chdir(cwd) |
| 36 | |
| 37 | |
| 38 | def main(): |
| 39 | upstream_root = clone_repo( |
| 40 | "https://github.com/JochenKalmbach/StackWalker", |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 41 | "5b0df7a4db8896f6b6dc45d36e383c52577e3c6b", |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 42 | shallow=False, |
| 43 | ) |
| 44 | wpilib_root = get_repo_root() |
| 45 | wpiutil = os.path.join(wpilib_root, "wpiutil") |
| 46 | |
| 47 | # Run CRLF -> LF before trying any patches |
| 48 | crlf_to_lf(upstream_root) |
| 49 | |
| 50 | # Apply patches to upstream Git repo |
| 51 | os.chdir(upstream_root) |
| 52 | for f in [ |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 53 | "0001-Add-advapi-pragma.patch", |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 54 | ]: |
| 55 | git_am( |
| 56 | os.path.join(wpilib_root, "upstream_utils/stack_walker_patches", f), |
| 57 | ignore_whitespace=True, |
| 58 | ) |
| 59 | |
| 60 | shutil.copy( |
| 61 | os.path.join("Main", "StackWalker", "StackWalker.h"), |
| 62 | os.path.join(wpiutil, "src/main/native/windows/StackWalker.h"), |
| 63 | ) |
| 64 | |
| 65 | shutil.copy( |
| 66 | os.path.join("Main", "StackWalker", "StackWalker.cpp"), |
| 67 | os.path.join(wpiutil, "src/main/native/windows/StackWalker.cpp"), |
| 68 | ) |
| 69 | |
| 70 | |
| 71 | if __name__ == "__main__": |
| 72 | main() |