Using Ninja with SCons projects

585 views
Skip to first unread message

Remko Tronçon

unread,
Aug 6, 2013, 3:23:50 PM8/6/13
to ninja...@googlegroups.com
Hi all,

In case someone's interested: I created a script to use Ninja with a SCons-based build system. The way it works is that it bootstraps by doing a SCons dry-run build, and then parses the output commands (and dependency tree), and generates Ninja rules for it. For the commands it doesn't have commands for (e.g. python code), it invokes SCons to generate the files (a batching feature would help us a bit here btw).

We are currently using this for our day-to-day development, giving us very fast modify/build/test cycles (for which SCons isn't really a champion), and this seems to be working quite well. Of course, regeneration of the Ninja file is a lot slower than just running an incremental SCons build, but this rarely happens in a day anyway. The major other caveat is that it requires full knowledge of all tools used in the build system (as it needs to parse the command line to determine inputs and outputs), so the script may not work out of the box for a different project.

You can find more about it here: http://el-tramo.be/blog/scons2ninja/

cheers,
Remko

Evan Martin

unread,
Aug 8, 2013, 12:03:27 PM8/8/13
to Remko Tronçon, ninja-build
This is a neat hack!  I will link to it from the manual.

It is oddly similar to the Mozilla makefile hack that was also just posted to the mailing list, in that both are extracting a ninja file out of another build system by running it.  I wonder if there's some generalization we could be doing...


--
You received this message because you are subscribed to the Google Groups "ninja-build" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninja-build...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Giridhar Tammana

unread,
May 20, 2014, 6:32:03 AM5/20/14
to ninja...@googlegroups.com, Remko Tronçon, mar...@danga.com
How do I set dump_trace variable?
My project uses Scons but its heavily customized, I tried to print env['dump_trace'] which gave error

KeyError: 'dump_trace':

I even tried setting env['dump_trace']  = True
But I don't see any commands being printed.

Thanks

Remko Tronçon

unread,
May 20, 2014, 11:19:18 AM5/20/14
to Giridhar Tammana, ninja...@googlegroups.com, mar...@danga.com
Hi Giridhar,

On 20 May 2014 12:32, Giridhar Tammana <girid...@gmail.com> wrote:
> How do I set dump_trace variable?

The 'dump_trace' is a customization that needs to be done to your
SConscript file. The reason is that there's no command-line option in
SCons to say "please treat everything as dirty" (and last time I asked
about it, it didn't seem like there would ever be one). The following
should do the trick:

if ARGUMENTS.get("dump_trace", False) :
env.SetOption("no_exec", True)
env.Decider(lambda x, y, z : True)
SCons.Node.Python.Value.changed_since_last_build = (lambda x, y, z: True)

cheers,
Remko
Reply all
Reply to author
Forward
0 new messages