blob: a58886ec7995d9c7dae75910f2fb88d5f246d694 [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001#!/usr/bin/env python3
2
3import os
4import shutil
5import subprocess
6
7from 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
16def 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
38def main():
39 upstream_root = clone_repo(
40 "https://github.com/JochenKalmbach/StackWalker",
James Kuszmaulb13e13f2023-11-22 20:44:04 -080041 "5b0df7a4db8896f6b6dc45d36e383c52577e3c6b",
James Kuszmaulcf324122023-01-14 14:07:17 -080042 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080053 "0001-Add-advapi-pragma.patch",
James Kuszmaulcf324122023-01-14 14:07:17 -080054 ]:
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
71if __name__ == "__main__":
72 main()