portage on gentoo has this kind of functionality, although it needs to be enabled by the package, producing multiple 'slots' which can each hold a different version of the same software. GCC by default works like this, as does python between major versions. It can also do compiling from git although I don't think it keeps the build files around, but with ccache you can somewhat mitigate the recompilation time.