2022-05-09 01:21:54 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
|
|
|
|
|
2022-07-01 06:41:44 -07:00
|
|
|
from upstream_utils import (
|
2022-08-20 07:26:34 -07:00
|
|
|
get_repo_root,
|
|
|
|
|
clone_repo,
|
2022-07-01 06:41:44 -07:00
|
|
|
comment_out_invalid_includes,
|
|
|
|
|
walk_cwd_and_copy_if,
|
2022-08-20 07:26:34 -07:00
|
|
|
git_am,
|
2022-07-01 06:41:44 -07:00
|
|
|
)
|
2022-05-09 01:21:54 -04:00
|
|
|
|
|
|
|
|
|
2022-05-25 00:51:32 -04:00
|
|
|
def crlf_to_lf(stackwalker_dir):
|
|
|
|
|
for root, _, files in os.walk(stackwalker_dir):
|
|
|
|
|
if ".git" in root:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
for fname in files:
|
|
|
|
|
filename = os.path.join(root, fname)
|
|
|
|
|
print(f"Converting CRLF -> LF for {filename}")
|
2022-07-01 06:41:44 -07:00
|
|
|
with open(filename, "rb") as f:
|
2022-05-25 00:51:32 -04:00
|
|
|
content = f.read()
|
2022-07-01 06:41:44 -07:00
|
|
|
content = content.replace(b"\r\n", b"\n")
|
2022-05-25 00:51:32 -04:00
|
|
|
|
2022-07-01 06:41:44 -07:00
|
|
|
with open(filename, "wb") as f:
|
2022-05-25 00:51:32 -04:00
|
|
|
f.write(content)
|
|
|
|
|
|
2022-08-20 07:26:34 -07:00
|
|
|
cwd = os.getcwd()
|
|
|
|
|
os.chdir(stackwalker_dir)
|
2022-05-25 00:51:32 -04:00
|
|
|
subprocess.check_call(["git", "add", "-A"])
|
|
|
|
|
subprocess.check_call(["git", "commit", "-m", "Fix line endings"])
|
2022-08-20 07:26:34 -07:00
|
|
|
os.chdir(cwd)
|
2022-05-25 00:51:32 -04:00
|
|
|
|
|
|
|
|
|
2022-05-09 01:21:54 -04:00
|
|
|
def main():
|
2022-08-20 07:26:34 -07:00
|
|
|
upstream_root = clone_repo(
|
2022-05-09 01:21:54 -04:00
|
|
|
"https://github.com/JochenKalmbach/StackWalker",
|
2023-07-24 22:46:25 -07:00
|
|
|
"5b0df7a4db8896f6b6dc45d36e383c52577e3c6b",
|
2022-07-01 06:41:44 -07:00
|
|
|
shallow=False,
|
|
|
|
|
)
|
2022-08-20 07:26:34 -07:00
|
|
|
wpilib_root = get_repo_root()
|
|
|
|
|
wpiutil = os.path.join(wpilib_root, "wpiutil")
|
2022-05-09 01:21:54 -04:00
|
|
|
|
2022-05-25 00:51:32 -04:00
|
|
|
# Run CRLF -> LF before trying any patches
|
2022-08-20 07:26:34 -07:00
|
|
|
crlf_to_lf(upstream_root)
|
2022-05-25 00:51:32 -04:00
|
|
|
|
2022-08-20 07:26:34 -07:00
|
|
|
# Apply patches to upstream Git repo
|
|
|
|
|
os.chdir(upstream_root)
|
|
|
|
|
for f in [
|
2023-07-24 22:46:25 -07:00
|
|
|
"0001-Add-advapi-pragma.patch",
|
2022-08-20 07:26:34 -07:00
|
|
|
]:
|
|
|
|
|
git_am(
|
|
|
|
|
os.path.join(wpilib_root, "upstream_utils/stack_walker_patches", f),
|
|
|
|
|
ignore_whitespace=True,
|
|
|
|
|
)
|
2022-05-09 01:21:54 -04:00
|
|
|
|
2022-07-01 06:41:44 -07:00
|
|
|
shutil.copy(
|
|
|
|
|
os.path.join("Main", "StackWalker", "StackWalker.h"),
|
|
|
|
|
os.path.join(wpiutil, "src/main/native/windows/StackWalker.h"),
|
|
|
|
|
)
|
2022-05-09 01:21:54 -04:00
|
|
|
|
|
|
|
|
shutil.copy(
|
|
|
|
|
os.path.join("Main", "StackWalker", "StackWalker.cpp"),
|
2022-07-01 06:41:44 -07:00
|
|
|
os.path.join(wpiutil, "src/main/native/windows/StackWalker.cpp"),
|
|
|
|
|
)
|
2022-05-09 01:21:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|