Skip to content

The Basics

Tal Liron edited this page Jan 15, 2017 · 8 revisions

Rōnin build scripts are regular old Python programs.

(Instead of starting from scratch, you can copy one of the example build.py files from the examples directory.)

It's a good idea to put the standard Python shebang on the first line, so that if you make your script executable it can be run directly:

#!/usr/bin/env python

Make sure the script is executable:

chmod +x build.py

And now you can run it:

./build.py

After that first line, there are a bunch of imports for the parts of Rōnin you are using (as well as other Python libraries):

from ronin.cli import cli
from ronin.contexts import new_context
from ronin.gcc import GccBuild
from ronin.phases import Phase
from ronin.pkg_config import Package
from ronin.projects import Project
from ronin.utils.paths import glob

All build configuration in Rōnin is handled by something called a "context," so you want to make sure that you're always working in one:

with new_context() as ctx:

(There's a lot more to say about contexts.)

You build your script out of a combination of "projects" (you can have several in once script), each producing its own Ninja file. A project comprises "phases," where each phase is associated with an "executor," which does the actual work (calling a command). Rōnin comes with handy executors to handle most common build work: compilation, linking, copying resources, etc. You can of course create your own.

Here's a simple project, which a single phase, which uses the GccBuild executor. It is from the "gcc GTK+ Hello World" example:

project = Project('gcc GTK+ Hello World')

Phase(project=project,
      name='build',
      executor=GccBuild(),
      inputs=glob('src/*.c'),
      extensions=[Package('gtk+-3.0')],
      output='example_1')

Finally, you want to delegate control to the Rōnin CLI to handle the rest:

cli(project)

Note that cli() can accept multiple projects as arguments, in which case it will generate several Ninja files and build them.

See CLI for more information.

Clone this wiki locally