repo: catch error due to broken build packages
Metadata
Current evaluation
Merged PR #2023 (commit aa8f5f2b4) catches failed build-package installation and reports apt dependency conflicts via BuildPackagesNotInstalledError.
Resolution: closed resolved
Reason: PR #2023 was merged as commit aa8f5f2b4. It falls back to apt-get for conflicting packages and converts its failure into a clear build-package installation error.
Evaluated by: mr-cal-bot
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)?
- [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh unit`?
-----
This PR modifies `repo._deb` to handle failure to `sudo apt-get install` new packages as [reported in the forum](https://forum.snapcraft.io/t/unable-to-correct-problems-you-have-held-broken-packages/4584). Typically this occurs when packages have conflicting dependencies. Currently Snapcraft just bails out with a stack trace in this case.
The Python Apt bindings have a heuristic that's similar to what `apt-get` does but exposes less information. So if it fails to resolve conflicts in `apt.Package.mark_install` we get a `SystemError` with not enough details to produce a sensible error message. By specifying `auto_fix=False` we can always fall-through to `apt-get` which will show a verbose error message so just referring to the packages we couldn't install is still clear enough even if we don't know which one(s) specifically failed. For this case I'm introducing a new `BuildPackagesNotInstalledError`.
The following new tests are being added:
- tests.unit.repo.test_deb.test_broken_package_apt_install
- To verify that `apt-get install` failing with a `CalledProcessError` is handled.
I locally ran the tests:
- `./runtests.sh tests/unit` with unrelated failures in [tests.unit.test_lifecycle.CoreSetupTestCase.test_core_setup_if_docker_env](https://bugs.launchpad.net/snapcraft/+bug/1752576), `tests.unit.test_mangling.TestClearExecstack.test_execstack_clears` and `tests.unit.test_elf`.
- `./runtests.sh tests/integration` with one unrelated failure in [tests.integration.general.test_parser.TestParserWikis](https://bugs.launchpad.net/snapcraft/+bug/1752580)
- `./runtests.sh static`: Everything passed
Manual test steps:
- cd tests/integration/snaps/basic
- Add this line to `snap/snapcraft.yaml`:
`build-packages: [cpp-arm-linux-gnueabihf, gcc-5-arm-linux-gnueabihf, gcc-arm-linux-gnueabihf, gcc-multilib]`
- snapcraft
- Observe that you get an error that looks like this:
`The following packages have unmet dependencies:`
` gcc-5-arm-linux-gnueabihf : Conflicts: gcc-multilib but 4:5.3.1-1ubuntu1 is to be installed`
` gcc-multilib : Conflicts: gcc-5-arm-linux-gnueabihf`
` Conflicts: gcc-5-arm-linux-gnueabihf:i386`
`Could not install all requested build packages: gcc-5-arm-linux-gnueabihf gcc-arm-linux-gnueabihf gcc-multilib`
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #2023 (commit aa8f5f2b4) catches failed build-package installation and reports apt dependency conflicts via BuildPackagesNotInstalledError. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #2023 added BuildPackagesNotInstalledError and apt-get fallback to report conflicting build-package dependencies clearly. | |
| qwen/qwen3.6-35b-a3b | — | — | Resolved broken build package errors by introducing BuildPackagesNotInstalledError and falling back to apt-get for detailed conflict messages. Merged after reviewer approval and passing CI checks. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix handling broken build packages during apt installation. Introduces BuildPackagesNotInstalledError and falls back to apt-get for verbose conflict messages instead of crashing with a stack trace. Includes unit tests. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #3411 repo: only install build packages marked for installation | snapcraft | merged | Merged PR #3411 in commit e5f3422af, limiting apt build-package installation to packages explicitly marked for installation, excluding those marked for deletion. | |
| #3221 repo: install requested build-package versions | snapcraft | merged | Merged PR #3221 (commit 727c46f22) restored installation of versioned build packages, using --allow-downgrades so requested apt versions are honored. |