Skip to content

Commit 67f7e54

Browse files
authored
Merge pull request #1175 from hedrok/T8599-fail-build-on-patch-fail
T8599: Make source packages required and fix them
2 parents 6f3f7b7 + c596d7e commit 67f7e54

2 files changed

Lines changed: 42 additions & 13 deletions

File tree

scripts/package-build/build.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def build_package(package: list, patch_dir: Path) -> None:
120120
print(f'I: execute pre_build_hook for the package "{repo_name}"')
121121
run(pre_build_hook, cwd=repo_dir, check=True, shell=True)
122122
except CalledProcessError as e:
123-
print(e)
124-
print(f"I: pre_build_hook failed for the {repo_name}")
123+
print(f"E: pre_build_hook failed for the {repo_name}")
125124
raise
126125

127126
# Apply patches if the 'apply_patches' key is set to True (default) in the package configuration
@@ -136,9 +135,35 @@ def build_package(package: list, patch_dir: Path) -> None:
136135
if (repo_dir / 'patches'):
137136
apply_patches(repo_dir, patch_dir / repo_name)
138137

139-
# Sanitize the commit ID and build a tarball for the package
140-
commit_id_sanitized = package['commit_id'].replace('/', '_')
141-
tarball_name = f"{repo_name}_{commit_id_sanitized}.tar.gz"
138+
# Create original tarball for dpkg-source to be happy
139+
package_version = run(['dpkg-parsechangelog', '--show-field', 'Version', '--file', repo_dir / 'debian/changelog'], capture_output=True, check=False)
140+
if package_version.stdout:
141+
package_version = package_version.stdout.decode().strip()
142+
package_version = package_version.rsplit('-', maxsplit=1)[0]
143+
if ':' in package_version:
144+
package_version = package_version.split(':', maxsplit=1)[1]
145+
else:
146+
# On failure fallback to sanitized commit ID
147+
package_version = package['commit_id'].replace('/', '_')
148+
149+
package_name = run(['dpkg-parsechangelog', '--show-field', 'Source', '--file', repo_dir / 'debian/changelog'], capture_output=True, check=False)
150+
if package_name.stdout:
151+
package_name = package_name.stdout.decode().strip()
152+
else:
153+
# On failure fallback to repo name
154+
package_name = repo_name
155+
156+
# 1.0 version needs 'native' format - without '.orig'
157+
# 3.0 needs '.orig'
158+
source_format_suffix = ''
159+
if (repo_dir / 'debian/source/format').exists():
160+
with open(repo_dir / 'debian/source/format') as f:
161+
source_format_version = f.read()
162+
if '3.0' in source_format_version:
163+
source_format_suffix = '.orig'
164+
165+
# Build a tarball for the package
166+
tarball_name = f'{package_name}_{package_version}{source_format_suffix}.tar.gz'
142167
run(['tar', '--exclude=.git', '--exclude=.github', '-czf', tarball_name, '-C', str(repo_dir.parent), repo_name], check=True)
143168
print(f"I: Tarball created: {tarball_name}")
144169

@@ -151,21 +176,23 @@ def build_package(package: list, patch_dir: Path) -> None:
151176
try:
152177
run('sudo mk-build-deps --install --tool "apt-get --yes --no-install-recommends"', cwd=repo_dir, check=True, shell=True)
153178
run('sudo dpkg -i *build-deps*.deb', cwd=repo_dir, check=True, shell=True)
179+
# Clean up or dpkg-source will see this as changes to binary files
180+
cleanup_build_deps(repo_dir)
154181
except CalledProcessError as e:
155-
print(f"Failed to build package {repo_name}: {e}")
182+
print(f"E: Failed to create/install dependency package for {repo_name}: {e}")
183+
raise
156184

157185
# Build the package, check if we have build_cmd in the package.toml
158186
try:
159-
build_cmd = package.get('build_cmd', 'dpkg-buildpackage -uc -us -tc -F --source-option=--tar-ignore=.git --source-option=--tar-ignore=.github')
187+
build_cmd = package.get('build_cmd', r'dpkg-buildpackage -uc -us -tc -F --source-option=--tar-ignore=.git --source-option=--tar-ignore=.github --source-option=-i --source-option=--extend-diff-ignore="^\.github(?:/.*)?$"')
160188
run(build_cmd, cwd=repo_dir, check=True, shell=True)
161189
except CalledProcessError as e:
162-
print(e)
163-
print("I: Source packages build failed, ignoring - building binaries only")
164-
build_cmd = package.get('build_cmd', 'dpkg-buildpackage -uc -us -tc -b')
165-
run(build_cmd, cwd=repo_dir, check=True, shell=True)
190+
print(f"E: Build command failed for '{repo_name}': {build_cmd}")
191+
raise
166192

167193
except CalledProcessError as e:
168194
print(f"Failed to build package {repo_name}: {e}")
195+
sys.exit(1)
169196
finally:
170197
# Clean up repository directory
171198
# shutil.rmtree(repo_dir, ignore_errors=True)
@@ -176,8 +203,9 @@ def cleanup_build_deps(repo_dir: Path) -> None:
176203
"""Clean up build dependency packages"""
177204
try:
178205
if repo_dir.exists():
179-
for file in glob.glob(str(repo_dir / '*build-deps*.deb')):
180-
os.remove(file)
206+
for suffix in ('deb', 'buildinfo', 'changes'):
207+
for file in glob.glob(str(repo_dir / f'*build-deps*.{suffix}')):
208+
os.remove(file)
181209
print("I: Cleaned up build dependency packages")
182210
except Exception as e:
183211
print(f"Error cleaning up build dependencies: {e}")

scripts/package-build/dropbear/package.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "dropbear"
33
commit_id = "debian/2022.83-1+deb12u1"
44
scm_url = "https://salsa.debian.org/debian/dropbear.git"
5+
build_cmd = "dpkg-buildpackage -us -uc -tc -b"
56

67
[dependencies]
78
packages = ["libpam0g-dev"]

0 commit comments

Comments
 (0)