diff options
author | RJ Ryan <rryan@mixxx.org> | 2013-06-19 00:46:54 -0400 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2013-06-19 00:46:54 -0400 |
commit | 25d57b59dff3947212909634864dd82365c9606b (patch) | |
tree | f0d0f8a048f8ed2f45c5ff015fc96891662f72f1 /build/protoc.py | |
parent | e50f9f168fa08f2be6d0f13e8a225bbcc9de09bb (diff) |
Moving mixxx/* to the root. A new era begins!
Diffstat (limited to 'build/protoc.py')
-rw-r--r-- | build/protoc.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/build/protoc.py b/build/protoc.py new file mode 100644 index 0000000000..09746d3e2c --- /dev/null +++ b/build/protoc.py @@ -0,0 +1,80 @@ +""" +protoc.py: Protoc Builder for SCons + +This Builder invokes protoc to generate C++ and Python +from a .proto file. + +NOTE: Java is not currently supported.""" + +__author__ = "Scott Stafford" + +import SCons.Action +import SCons.Builder +import SCons.Defaults +import SCons.Node.FS +import SCons.Util + +from SCons.Script import File, Dir + +import os.path +protocs = 'protoc' + +ProtocAction = SCons.Action.Action('$PROTOCCOM', '$PROTOCCOMSTR') +def ProtocEmitter(target, source, env): + dirOfCallingSConscript = Dir('.').srcnode() + env.Prepend(PROTOCPROTOPATH = dirOfCallingSConscript.path) + + source_with_corrected_path = [] + for src in source: + commonprefix = os.path.commonprefix([dirOfCallingSConscript.path, src.srcnode().path]) + if len(commonprefix)>0: + source_with_corrected_path.append( src.srcnode().path[len(commonprefix + os.sep):] ) + else: + source_with_corrected_path.append( src.srcnode().path ) + + source = source_with_corrected_path + + for src in source: + modulename = os.path.splitext(src)[0] + + if env['PROTOCOUTDIR']: + #base = os.path.join(env['PROTOCOUTDIR'] , modulename) + base = os.path.join(modulename) + target.extend( [ base + '.pb.cc', base + '.pb.h' ] ) + + if env['PROTOCPYTHONOUTDIR']: + base = os.path.join(env['PROTOCPYTHONOUTDIR'] , modulename) + target.append( base + '_pb2.py' ) + + try: + target.append(env['PROTOCFDSOUT']) + except KeyError: + pass + + #~ print "PROTOC SOURCE:", [str(s) for s in source] + #~ print "PROTOC TARGET:", [str(s) for s in target] + + return target, source + +ProtocBuilder = SCons.Builder.Builder(action = ProtocAction, + emitter = ProtocEmitter, + srcsuffix = '$PROTOCSRCSUFFIX') + +def generate(env): + """Add Builders and construction variables for protoc to an Environment.""" + try: + bld = env['BUILDERS']['Protoc'] + except KeyError: + bld = ProtocBuilder + env['BUILDERS']['Protoc'] = bld + + env['PROTOC'] = env.Detect(protocs) or 'protoc' + env['PROTOCFLAGS'] = SCons.Util.CLVar('') + env['PROTOCPROTOPATH'] = SCons.Util.CLVar('') + env['PROTOCCOM'] = '$PROTOC ${["-I%s"%x for x in PROTOCPROTOPATH]} $PROTOCFLAGS --cpp_out=$PROTOCCPPOUTFLAG$PROTOCOUTDIR ${PROTOCPYTHONOUTDIR and ("--python_out="+PROTOCPYTHONOUTDIR) or ""} ${PROTOCFDSOUT and ("-o"+PROTOCFDSOUT) or ""} ${SOURCES}' + env['PROTOCOUTDIR'] = '${SOURCE.dir}' + env['PROTOCPYTHONOUTDIR'] = "python" + env['PROTOCSRCSUFFIX'] = '.proto' + +def exists(env): + return env.Detect(protocs) |