-
Notifications
You must be signed in to change notification settings - Fork 9
/
create-patch.py
52 lines (45 loc) · 2.26 KB
/
create-patch.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
45
46
47
48
49
50
51
52
import subprocess
import os
# import py7zr
from zipfile import ZipFile, ZIP_LZMA
import re
import shutil
version = subprocess.run(["git", "describe", "--tags", "--abbrev=0"], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
print("Creating patch for version " + version)
# Check if version number is correct in script files
with open("PROGRAM/globals.c", "r") as globals_file:
globals_content = globals_file.read()
script_version = re.search(r'#define BUILDVERSION\W+"(\d+\.\d+\.\d+(\-[a-z]+\.\d+)?)"', globals_content)
if script_version is None:
raise Exception("No valid version number found in globals.c!")
if script_version.group(1) != version:
raise Exception("Version number in globals.c does not match latest tag " + version + " != " + script_version.group(1))
files = subprocess.run(['git', '--no-pager', 'diff', '--name-only', '--diff-filter=d', "15.0.0-alpha.11.."],
stdout=subprocess.PIPE).stdout.decode("utf-8").replace('"', '').split("\n")
def add_directory(z, path, target = None):
for base, dirs, files in os.walk(path):
for file in files:
fn = os.path.join(base, file)
# print(fn)
add_file(z, fn, fn.replace(path, target or ""))
def add_file(z, source_file, target_file=None):
# z.write(source_file, target_file)
if target_file is None:
target_file = source_file
print(target_file)
target_path = "installer/patch/" + target_file
os.makedirs(os.path.dirname(target_path), exist_ok=True)
shutil.copy2(source_file, target_path)
# with ZipFile('patch.zip', 'a', compression=ZIP_LZMA) as z:
z = None
for file in files:
if file != "" and file != "engine.ini" and not file.startswith("installer/") and not file.endswith(".py"):
add_file(z, file)
add_file(z, "installer/resources/engine.ini", 'engine.ini')
add_file(z, "installer/engine/crashpad_handler.exe", 'crashpad_handler.exe')
add_file(z, "installer/engine/engine.exe", 'engine.exe')
add_file(z, "installer/engine/engine.pdb", 'engine.pdb')
add_file(z, "installer/engine/fmod.dll", 'fmod.dll')
add_file(z, "installer/engine/mimalloc.dll", 'mimalloc.dll')
add_file(z, "installer/engine/mimalloc-redirect.dll", 'mimalloc-redirect.dll')
add_directory(z, "installer/engine/resource", "RESOURCE")