Does Portage rebuild full packages when updating

gentoopackage-managementportage

When I update a Gentoo system, does Portage fetch new sources, extract them and recompile everything from scratch, or does it extract it to existing sources and compile only changed files?

Best Answer

While make(1) and many buildsystems, such as autotools, do support incremental compilation, Gentoo with stock Portage does not take advantage of it. After a package is compiled and installed, the working directory is discarded.

The actual difficulty with using incremental compilation would be getting packages to build reliably in this fashion. It is much easier to be assured that a build will be both successful, correct, and reproducible if you always do a clean build. Many buildsystems would break subtly if Gentoo tried to support rebuilding incrementally. And, in many cases, one would have to re-run ./configure (or its equivalent) which would likely create a new config.h or update environment variables such as CFLAGS and CPPFLAGS in the generated Makefiles (or equivalents if other buildsystems are used). Touching config.h would require most sources to be rebuilt. And if PACKAGE_VERSION changes, which might be passed by Makefile via CPPFLAGS if the package doesn’t use config.h, all sources should be rebuilt to see the new values—unless you can somehow figure that certain source files wouldn’t need to be recompiled because they don’t reference a particular C preprocessor macro.

So, in the end, even if Gentoo devs went to all the work to try to support incremental compilation between package version updates, many packages would either need to be fully recompiled or make(1) would end up fully recompiling them anyway (e.g. if config.h’s timestamp changes). So this would be a high cost effort for a very marginal gain—and even likely introduce a lot of subtle bugs, in my best understanding. Thus, I do not expect such a feature to ever be introduced.

My answer mostly refers to autotools/simple Makefile-type packages, but not everything builds this way, so the exact reasons would likely differ depending on the exact package in question.

Related Question