Skip to content

Commit 0d1f1dd

Browse files
committed
T8599: Make source packages required and fix them
Ignoring source package failures leads to silent ignore of patch failures. Make source package required. To fix source packages: * Use <source_package>_<upstream_version>.orig.tar.gz naming for source archive. * Get `source_package` and `upstream_version` from changelog using dpkg-parsechangelog utility * Clean build-deps after usage or dpkg-source sees these files as changes relative to upstream. * Add '.github' to --diff-ignore source option
1 parent 4c0a579 commit 0d1f1dd

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

scripts/package-build/build.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,26 @@ def build_package(package: list, patch_dir: Path) -> None:
136136
if (repo_dir / 'patches'):
137137
apply_patches(repo_dir, patch_dir / repo_name)
138138

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"
139+
# Create original tarball for dpkg-source to be happy
140+
package_version = run(['dpkg-parsechangelog', '--show-field', 'Version', '--file', repo_dir / 'debian/changelog'], capture_output=True, check=False)
141+
if package_version.stdout:
142+
package_version = package_version.stdout.decode().strip()
143+
package_version = package_version.rsplit('-', maxsplit=1)[0]
144+
if ':' in package_version:
145+
package_version = package_version.split(':', maxsplit=1)[1]
146+
else:
147+
# On failure fallback to sanitized commit ID
148+
package_version = package['commit_id'].replace('/', '_')
149+
150+
package_name = run(['dpkg-parsechangelog', '--show-field', 'Source', '--file', repo_dir / 'debian/changelog'], capture_output=True, check=False)
151+
if package_name.stdout:
152+
package_name = package_name.stdout.decode().strip()
153+
else:
154+
# On failure fallback to repo name
155+
package_name = repo_name
156+
157+
# Build a tarball for the package
158+
tarball_name = f'{package_name}_{package_version}.orig.tar.gz'
142159
run(['tar', '--exclude=.git', '--exclude=.github', '-czf', tarball_name, '-C', str(repo_dir.parent), repo_name], check=True)
143160
print(f"I: Tarball created: {tarball_name}")
144161

@@ -151,18 +168,21 @@ def build_package(package: list, patch_dir: Path) -> None:
151168
try:
152169
run('sudo mk-build-deps --install --tool "apt-get --yes --no-install-recommends"', cwd=repo_dir, check=True, shell=True)
153170
run('sudo dpkg -i *build-deps*.deb', cwd=repo_dir, check=True, shell=True)
171+
# Clean up or dpkg-source will see this as changes to binary files
172+
run('sudo rm -f *build-deps*.deb', cwd=repo_dir, check=True, shell=True)
173+
run('sudo rm -f *build-deps*.buildinfo', cwd=repo_dir, check=True, shell=True)
174+
run('sudo rm -f *build-deps*.changes', cwd=repo_dir, check=True, shell=True)
154175
except CalledProcessError as e:
155176
print(f"Failed to build package {repo_name}: {e}")
156177

157178
# Build the package, check if we have build_cmd in the package.toml
158179
try:
159-
build_cmd = package.get('build_cmd', 'dpkg-buildpackage -uc -us -tc -F --source-option=--tar-ignore=.git --source-option=--tar-ignore=.github')
180+
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=--extend-diff-ignore="^\.github(?:/.*)?$"')
160181
run(build_cmd, cwd=repo_dir, check=True, shell=True)
161182
except CalledProcessError as e:
162183
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)
184+
print("E: Source packages build failed, possibly patches problem")
185+
sys.exit(1)
166186

167187
except CalledProcessError as e:
168188
print(f"Failed to build package {repo_name}: {e}")

0 commit comments

Comments
 (0)