It is possible to extend the capabilities of BuildCache with Lua. See lua-examples for some examples of Lua wrappers.
BuildCache first searches for Lua scripts in the paths given in the environment
variable BUILDCACHE_LUA_PATH (colon separated on POSIX systems, and semicolon
separated on Windows), and then continues searching in $BUILDCACHE_DIR/lua.
If no matching script file was found, BuildCache falls back to the built in
compiler wrappers (as listed above).
The first line of a Lua based program wrapper script must be a Lua comment with a special "match"-statement that specifies a regex that matches the name of the program that is to be wrapped, e.g:
-- match(gcc.*)More detailed checks can be done in the optional can_handle_command method.
The following methods can be implemented (see program_wrapper.hpp for a more detailed documentation):
*: get_input_files and get_implicit_input_files are only used in direct
mode, which requires that direct_mode is reported by get_capabilities.
**: run_for_miss, when defined, shall run the actual command (as specified by
ARGS) if a cache miss occurs. The return value shall be a table consisting of
std_out, std_err and return_code (see
sys::run_result_t). The default implementation is
equivalent to bcache.run(ARGS, false).
All program arguments are available in the global ARGS array (an array of
strings). ARGS[1] is the path to the program that is being wrapped.
To use Lua standard libraries (coroutine, debug, io, math, os,
package, string, table or utf8), you must first load them by calling
require_std(name). For convenience it is possible to load all standard
libraries with require_std("*"), but beware that it is slower than to load
only the libraries that are actually used.
There is a bcache library that exposes some of the internal BuildCache
functions that may be useful. To use the library, call require_std("bcache").
The following functions are available (for more detailed information, look up the corresponding C++ function documentation):
