lundi 2 février 2015

Thinking about a language for build definitions


I want to write a little tool that parses build definitions and converts them to a ninja.build file. It should not abstract compilation like CMake or Meson, but be similar to make in that you manually write the commands for a build step.


I have built an almost working solution in Python, but there are some stepping stones that I could not easily solve yet and the design is not ideal. My main goal is to have modular build definitions and be able to modify these definitions from another project for its requirements. Imagine



use platform
use platform.compiler as compiler

# Another user created build definition file.
use foolib

build_dir : join(project_path, 'build')
foolib.build_dir : build_dir # Here we change the build_dir of the library
foolib.defines : array(foolib.defines, 'FOOLIB_LEGACY_API') # And here we add another define

sources : wildcard('source/*.cpp')
objects : transform(sources, 'source', join(build_dir, 'obj'), platform.objsuffix)
executable = join(build_dir, platform.exename('main'))
includes : array(localpath('include'), boost.includes)
defines : array(foolib.defines, 'BUFSIZE=512')

target sources -> objects
compiler.cpp quote(input) compiler.includes(includes) \
compiler.defines(defines) compiler.compile_only compiler.out(output)

target array(objects, boost.library) -> executable
compiler.cpp quote(input) compiler.out(executable)


foolib would look pretty similar, outputting a library file from source files to its build_dir.


I use lazy variable expansion at all times to allow things like changing the build directory of an imported project or update macro definitions used while compiling the dependency.


The problem I have with lazy evaluation is with self-references, and it also adds a lot of overhead. However, doing immediate evaluation on assignment will not allow this late configuration change.


Can you think of a better/different design that would better fit my needs?





Aucun commentaire:

Enregistrer un commentaire