Skip to content

Instantly share code, notes, and snippets.

@modelmat
Last active January 6, 2021 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save modelmat/21e70adeafaf1dd980588f6f849dd3d2 to your computer and use it in GitHub Desktop.
Save modelmat/21e70adeafaf1dd980588f6f849dd3d2 to your computer and use it in GitHub Desktop.
Build debug packages for Arch Linux from a list of files
"""Build debug packages for Arch Linux from a list of files
Install:
In `/etc/makepkg.conf` disabling stripping binaries and enable the
creation of `-debug` packages.
$ pip install pyalpm
Usage:
Create a file named "debug_symbol_files.txt"
$ python build_debug_packages.py
Rationale:
Arch Linux currently does not include XX-debug packages in its repos.
This makes it difficult to provide complete backtraces in projects
such as KDE. Each package would have to be found (with `pacman -F`)
then downloaded (`asp export <package-name>`) then built (`makepkg`).
This script aims to automate this process by handling the above
transparently.
Future Goals:
* Automatically parse files without debug symbols from `coredumpctl`.
Probably not going to happen since it's not worth the time
https://xkcd.com/1205/
"""
import os
import pyalpm
handle = pyalpm.Handle(".", "/var/lib/pacman")
localdb = handle.get_localdb()
def search_for_file(target_file_name):
for pkg in localdb.pkgcache:
for (file_name, *_) in pkg.files:
if f"/{file_name}" == target_file_name:
return pkg
def build_package(name):
initial_dir = os.getcwd()
os.system(f"asp export {name}")
os.chdir(name)
os.system("makepkg --noconfirm --nocheck --rmdeps --syncdeps --skippgpcheck --install")
os.chdir(initial_dir)
def main():
with open("debug_symbol_files.txt") as f:
files = set(f.read().splitlines())
packages_to_rebuild = set()
for wanted_file in files:
if not wanted_file: continue
pkg = search_for_file(wanted_file)
if pkg:
packages_to_rebuild.add(pkg.name)
else:
print(f"error: no package found for {wanted_file}")
os.system("asp update")
for pkg in packages_to_rebuild:
build_package(pkg)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment