forked from duckdb/duckdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply_extension_patches.py
44 lines (35 loc) · 1.33 KB
/
apply_extension_patches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import sys
import glob
import subprocess
import os
# Get the directory and construct the patch file pattern
directory = sys.argv[1]
patch_pattern = f"{directory}*.patch"
# Find patch files matching the pattern
patches = glob.glob(patch_pattern)
def raise_error(error_msg):
sys.stderr.write(error_msg + '\n')
sys.exit(1)
patches = sorted(os.listdir(directory))
for patch in patches:
if not patch.endswith('.patch'):
raise_error(
f'Patch file {patch} found in directory {directory} does not end in ".patch" - rename the patch file'
)
# Exit if no patches are found
if not patches:
error_message = (
f"\nERROR: Extension patching enabled, but no patches found in '{directory}'. "
"Please make sure APPLY_PATCHES is only enabled when there are actually patches present. "
"See .github/patches/extensions/README.md for more details."
)
raise_error(error_message)
print(f"Resetting patches in {directory}\n")
subprocess.run(["git", "log"], check=True)
subprocess.run(["git", "clean", "-f"], check=True)
subprocess.run(["git", "reset", "--hard", "HEAD"], check=True)
# Apply each patch file using patch
for patch in patches:
print(f"Applying patch: {patch}\n")
subprocess.run(["patch", "-p1", "--forward", "-i", os.path.join(directory, patch)], check=True)