Search code examples
dependenciesdebianpackagingdpkg

How to install deb dependencies without installing the package?


I have a Debianized project with a debian/control file. I know how to use the mk-build-deps script from the devscripts package to install the build dependencies for this project; i.e., the packages immediately following the Build-Depends:.

What I need is a way to do something similar with the runtime dependencies; i.e., the packages immediately following the Depends: key. Essentially I need a mk-run-deps in addition to mk-build-deps.

Here's something I hacked together that works okay:

export TMP_DEBIAN_CONTROL=$(mktemp)
dpkg-gencontrol \
    -O${TMP_DEBIAN_CONTROL} \
    -P$(mktemp -d) \
    -c"$(pwd)/debian/control" \
    -f$(mktemp) \
    -p'project-name'
sed -ri 's|^Package: |Source: |;s|^Depends: |Build-Depends: |' \
    ${TMP_DEBIAN_CONTROL}
mk-build-deps -irt'apt-get -y' ${TMP_DEBIAN_CONTROL}

Is there a better way to do this?


Solution

  • The short answer is that there's no proper and general way to fetch the dependencies, except for actually building the binary packages and extracting them from the .debs.

    That's because there are going to be dependencies generated at build-time by either helper tooling or even by debian/rules via substvars, which might depend on dynamic checks, such as OS vendor, architectures, etc.

    If you control the source package and know what are the assumptions then the snippet you provide might work, but it might still miss dependencies injected by say debhelper if you are using that.

    I guess the real question is why do you need this for? For testing purposes, you would be better served with autopkgtests, which are able to declare dependencies by reference on either the source package build-dependencies or the run-time dependencies for specific binary packages being tested. If this is needed as part of the build process, then those should be listed instead in the source package build-dependencies.

    For run-time dependencies you might also be missing Pre-Depends, although those are unusual. For build-dependencies, you can use apt build-dep ., but that has the problem of not tracking these via a metapackage that can be then removed to drop all the unneeded dependencies.