[Scons-users] recording compilation commands with scons

Handa, Ramneek Ramneek.Handa at sc.com
Tue Apr 23 22:31:36 EDT 2013


Yes. That is a solution though a very generic one. I would like to go
more pythonic though.

More specifically,

1. How can I intercept the call to compile the file just in time
so that i know what the environment variables?

2. How do I expand variables within python as I see some of the
variables end up to be referring to another variable? I am specifically
interested in CCFLAGS? Is env['CCFLAGS'] the right way to go (when i
have specific env variable)?



Below is the trick I am using by monkey patching the Shared and Static
Object emitters. Is that the right direction to proceed? This works well
so far although I am not sure if I am picking up the compilation flag
from the source of truth or there are more manipulations likely to
happen in static/shared object emitters?



Regards.



import sys

import SCons.Defaults

import SCons.Builder



class Singleton(type):

_instances = {}

def __call__(cls, *args, **kwargs):

if cls not in cls._instances:

cls._instances[cls] = super(Singleton, cls).__call__(*args,
**kwargs)

return cls._instances[cls]



class MyTestClass:

__metaclass__ = Singleton



def __init__(self):

self.f = open('/tmp/testfile.out', 'w')

self.OriginalShared = SCons.Defaults.SharedObjectEmitter

self.OriginalStatic = SCons.Defaults.StaticObjectEmitter

pass



def WriteToFile(self, env, source):

for s in source:

val = str(s.srcnode().path) + str(" ") + str(env['CCFLAGS'])
+ str('\r\n')

self.f.write(val)



def SharedObjectEmitter(self, target, source, env):

self.WriteToFile(env, source)

return self.OriginalShared(target, source, env)



def StaticObjectEmitter(self, target, source, env):

self.WriteToFile(env, source)

return self.OriginalStatic(target, source, env)



SCons.Defaults.SharedObjectEmitter = MyTestClass().SharedObjectEmitter

SCons.Defaults.StaticObjectEmitter = MyTestClass().StaticObjectEmitter







From: scons-users-bounces at scons.org
[mailto:scons-users-bounces at scons.org] On Behalf Of Gary Oberbrunner
Sent: Tuesday, April 23, 2013 8:59 PM
To: SCons users mailing list
Subject: Re: [Scons-users] recording compilation commands with scons



Yes, that should work. Alternatively you could make wrapper scripts for
your compiler and linker and use those as $CXX/$SHCXX/$CC/$LINK/$SHLINK;
the wrapper scripts could record the commands they run.



On Tue, Apr 23, 2013 at 8:28 AM, Francis Bolduc <fbolduc at gmail.com>
wrote:

One way would be to change the C++ compile command into something else:

This is the default I believe.
env['SHCXXCOM'] = '$SHCXX -o $TARGET -c $SHCXXFLAGS $SHCCFLAGS
$_CCCOMCOM $SOURCES'

You could change it to be a list... think.. have not tried..
env['SHCXXCOM'] = ['$SHCXX -o $TARGET -c $SHCXXFLAGS $SHCCFLAGS
$_CCCOMCOM $SOURCES', 'echo $SOURCES']


--
Francis Bolduc, B.Sc.



On Tue, Apr 23, 2013 at 5:47 AM, Handa, Ramneek <Ramneek.Handa at sc.com>
wrote:

> Hi Folks,

>

> I work on a large repository which is divided into modules and I

would

> like to record the compilation triggered by scons in a format

specified by

> llvm.

>

> http://clang.llvm.org/docs/JSONCompilationDatabase.html

>

>

>

> Is there a way to write a hook in scons to get the information like

source

> filename and the exact C++ options being used to compile the file?

>

>

>

> Regards,

>

> Ramneek

>

>

> This email and any attachments are confidential and may also be

privileged.

> If you are not the intended recipient, please delete all copies and

notify

> the sender immediately. You may wish to refer to the incorporation

details

> of Standard Chartered PLC, Standard Chartered Bank and their

subsidiaries at

> http://www.standardchartered.com/en/incorporation-details.html.

>



> _______________________________________________

> Scons-users mailing list

> Scons-users at scons.org

> http://four.pairlist.net/mailman/listinfo/scons-users

>

_______________________________________________
Scons-users mailing list
Scons-users at scons.org
http://four.pairlist.net/mailman/listinfo/scons-users







--
Gary


This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard Chartered Bank and their subsidiaries at http://www.standardchartered.com/en/incorporation-details.html.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20130424/858b710d/attachment.htm>


More information about the Scons-users mailing list