-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
executable file
·195 lines (142 loc) · 5.47 KB
/
build.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/env python3
import requests
import os
import subprocess
import sys
import tarfile
from shutil import move, rmtree
from contextlib import chdir
from shutil import copytree
HELIX_VERSION = "24.07"
DEBIAN_DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "debian")
TARGET_DIRECTORY = os.path.join(os.getcwd(), "target")
HELIX_SOURCE_CODE_URL = f"https://github.com/helix-editor/helix/releases/download/{HELIX_VERSION}/helix-{HELIX_VERSION}-source.tar.xz"
def get_args() -> tuple[str, str]:
args = sys.argv[1:]
if len(args) < 2:
print(
"""
Usage:
./build.py <ubuntu-codename> <changelog-version>
Example:
./build.py kinetic 22.12-5~ubuntu22.10~ppa1
"""
)
sys.exit(1)
return args[0], args[1]
def prepare_target(target_directory: str) -> None:
if os.path.exists(target_directory):
rmtree(target_directory)
os.mkdir(target_directory)
def download_helix_release(target_directory_path: str, helix_version: str) -> str:
filename = f"helix_{helix_version}.orig.tar.xz"
print(f"-> Downloading {HELIX_SOURCE_CODE_URL}...")
response = requests.get(HELIX_SOURCE_CODE_URL, allow_redirects=True)
target_file_path = os.path.join(target_directory_path, filename)
with open(target_file_path, "wb") as file:
file.write(response.content)
return target_file_path
def unarchive_helix_release(target_directory_path: str, archive_file_path: str) -> None:
with chdir(target_directory_path):
print("-> Unarchive helix release...")
with tarfile.open(archive_file_path) as tar:
tar.extractall()
def prepare_debian_files(target_directory_path: str) -> str:
debian_files_path = os.path.join(target_directory_path, "debian")
print("-> Copy debian files")
copytree(DEBIAN_DIRECTORY, debian_files_path)
return debian_files_path
def create_cargo_vendor_archive(
source_directory_path: str, destination_directory_path: str
) -> None:
with chdir(source_directory_path):
print("-> Run cargo vendor...")
subprocess.check_call(["cargo", "vendor"])
tar_file_path = os.path.join(destination_directory_path, "vendor.tar.xz")
print(f"-> Create {tar_file_path}...")
subprocess.check_call(["tar", "cJf", tar_file_path, "vendor/"])
def create_dependencies_archives(
source_directory_path: str, destination_directory_path: str
) -> None:
create_cargo_vendor_archive(
source_directory_path=source_directory_path,
destination_directory_path=destination_directory_path,
)
def prepare_for_build(
source_directory_path: str
) -> str:
prepare_target(TARGET_DIRECTORY)
prepare_target(source_directory_path)
release_file_path = download_helix_release(
target_directory_path=TARGET_DIRECTORY,
helix_version=HELIX_VERSION,
)
unarchive_helix_release(
target_directory_path=source_directory_path,
archive_file_path=release_file_path,
)
debian_files_directory = prepare_debian_files(TARGET_DIRECTORY)
create_dependencies_archives(
source_directory_path=source_directory_path,
destination_directory_path=debian_files_directory,
)
return release_file_path
def move_debian_files(source_directory_path: str, target_directory_path: str) -> None:
move(source_directory_path, target_directory_path)
def update_changelog(source_directory_path, ubuntu_codename, changelog_version) -> None:
with chdir(source_directory_path):
print("-> Create new changelog entry...")
subprocess.check_call(
[
"dch",
"--force-bad-version", # we use this because we use this script for back porting!
"--distribution",
ubuntu_codename,
"--package",
"helix",
"--newversion",
changelog_version,
f"No-change backport to {ubuntu_codename}",
]
)
def run_debuild(source_directory_path: str) -> None:
with chdir(source_directory_path):
print("-> Run debuild...")
subprocess.check_call(["debuild", "--no-lintian", "-S", "-sa"])
def run_build(
source_directory_path: str,
release_file_path: str,
ubuntu_codename: str,
changelog_version: str,
) -> None:
# We remove the extracted source directory because it contains
# many compiled files from the prepare-for-build step that we
# do not want in the final source archive.
prepare_target(source_directory_path)
unarchive_helix_release(
target_directory_path=source_directory_path, archive_file_path=release_file_path
)
move_debian_files(
source_directory_path=os.path.join(TARGET_DIRECTORY, "debian"),
target_directory_path=source_directory_path,
)
update_changelog(
source_directory_path=source_directory_path,
ubuntu_codename=ubuntu_codename,
changelog_version=changelog_version,
)
run_debuild(source_directory_path)
def main():
ubuntu_codename, changelog_version = get_args()
source_directory_path = os.path.join(TARGET_DIRECTORY, f"helix-{HELIX_VERSION}")
release_file_path = prepare_for_build(
source_directory_path=source_directory_path,
)
run_build(
source_directory_path=source_directory_path,
release_file_path=release_file_path,
ubuntu_codename=ubuntu_codename,
changelog_version=changelog_version,
)
if __name__ == "__main__":
main()