Chroot for package testing

Preparing a chroot environment
An efficient way of preparing a reusable chroot environment is by using a btrfs file system and use snapshots. If one do not have access to such a file system then one can use a subdirectory instead of a btrfs subvolume.

You can also use bwrap to boot into a container instead of a chroot.

Get the stage 3 tarball. Then unpack stage 3 in it

When using a btrfs file system, space and operations will be saved by creating a snapshot:

Then you can chroot and set up a stable gentoo from stage 3 by following.

If you want to use containers instead, you can use bwrap:

Inside the chroot (or container), you may want to install repoman and portage with the  USE flag enabled:

At this point if you are using a btrfs file system, exit the chroot / bwrap and then make a snapshot. You may then delete the original subvolume:

Testing the package foo
If you are using a btrfs filesystem, create a snapshot of the stable stage 3 and chroot in it. If not, just chroot into the stable stage 3.

For a chroot:

For Bwrap:

If you are testing multiple packages, you may want to rename the prompt according to the package you are testing :

Next create a custom repository and copy in it the ebuild you want to test. Before testing the package foo/bar, emerge all its test depencencies.

Then make the adjustments of the make.conf, and then emerge the package

Once you are done with the test, if you are using a btrfs file system you may delete your test subvolume :

And make another test by going back to the beginning of this section. If you are using another file system, then execute the following after each test to get back to a stable stage 3.

Keeping up to date
Do not forget to keep your stable_stage3 up to date by chrooting in it from time to time and execute :