Saturday, June 9, 2012

Support for build directories

Build directories are a mechanism for keeping the source tree and its build products separate: during a build, the source tree remains read only and all the results of the build are placed in a different directory. It is often considered good practice to use build directories, as this ensures that the build does not have any effects on the sources and permits creating different binaries (think about "debug" vs. "production" binaries) from the same source tree without an intermediate make clean.

Most, if not all, modern build systems support the concept of build directories. The GNU Automake/Autoconf combination is not a exception, although I believe that not many people are aware of this. However, those that are probably use this feature routinely.

Up until now, integrating Kyua into a project that used build directories had always been cumbersome. In the case of Lutok and Kyua, for example, I came up with a populate-builddir.sh script that did a recursive copy of the Kyuafiles from the source directory into the build directory. This script was run as part of make check, and allowed the subsequent kyua test to run within the build directory before the final installation. Needless to say, this hack was awful.

Just yesterday, there was a discussion in the atf-devel mailing list that about this exact topic: how to get Kyua to work with a project that uses build directories. Along the thread, I realized that the obvious solution to this problem was to add support for build directories to Kyua. And this is what just happened!

The code that just landed in HEAD adds support for a new --build-root option.  When specified, the value of this option points to the directory containing the build products if it is different from the source tree.  A common usage example for your Makefile.am files would be:
check-local:
        kyua test --kyuafile='$(top_srcdir)/Kyuafile' \
            --build-root='$(top_builddir)'
And that's it. It had never been easier.

2 comments: