summaryrefslogtreecommitdiff
path: root/src/SConscript
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2013-01-07 13:05:37 -0500
committerAndreas Hansson <andreas.hansson@arm.com>2013-01-07 13:05:37 -0500
commit41f228c2ea5ab28d6400a259538e77d122066711 (patch)
tree022848d7896ed4a449c996b95de86d198f68121e /src/SConscript
parent63f1d0516d8a4e5a688cc3000b5a3597518d3dc7 (diff)
downloadgem5-41f228c2ea5ab28d6400a259538e77d122066711.tar.xz
scons: Add support for google protobuf building
This patch enables the use of protobuf input files in the build process, thus allowing .proto files to be added to input. Each .proto file is compiled using the protoc tool and the newly created C++ source is added to the list of sources. The first location where the protobufs will be used is in the capturing and replay of memory traces, involving the communication monitor and the trace-generator state of the traffic generator. This will follow in the next patch. This patch does add a dependency on the availability of the BSD licensed protobuf library (and headers), and the protobuf compiler, protoc. These dependencies are checked in the SConstruct, similar to e.g. swig. The user can override the use of protoc from the PATH by specifying the PROTOC environment variable. Although the dependency on libprotobuf and protoc might seem like a big step, they add significant value to the project going forward. Execution traces and other types of traces could easily be added and parsers for C++ and Python are automatically generated. We could also envision using protobufs for the checkpoints, description of the traffic-generator behaviour etc. The sky is the limit. We could also use the GzipOutputStream from the protobuf library instead of the current GPL gzstream. Currently, only the C++ source and header is generated. Going forward we might want to add the Python output to support simple command-line tools for displaying and editing the traces.
Diffstat (limited to 'src/SConscript')
-rwxr-xr-xsrc/SConscript35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/SConscript b/src/SConscript
index 9af71c9a6..845f514c5 100755
--- a/src/SConscript
+++ b/src/SConscript
@@ -233,6 +233,22 @@ class SwigSource(SourceFile):
self.cc_source = Source(cc_file, swig=True, parent=self)
self.py_source = PySource(package, py_file, parent=self)
+class ProtoBuf(SourceFile):
+ '''Add a Protocol Buffer to build'''
+
+ def __init__(self, source, **guards):
+ '''Specify the source file, and any guards'''
+ super(ProtoBuf, self).__init__(source, **guards)
+
+ # Get the file name and the extension
+ modname,ext = self.extname
+ assert ext == 'proto'
+
+ # Currently, we stick to generating the C++ headers, so we
+ # only need to track the source and header.
+ self.cc_file = File(joinpath(self.dirname, modname + '.pb.cc'))
+ self.hh_file = File(joinpath(self.dirname, modname + '.pb.h'))
+
class UnitTest(object):
'''Create a UnitTest'''
@@ -260,6 +276,7 @@ Export('Source')
Export('PySource')
Export('SimObject')
Export('SwigSource')
+Export('ProtoBuf')
Export('UnitTest')
########################################################################
@@ -676,6 +693,24 @@ for swig in SwigSource.all:
MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW")))
Source(init_file, **swig.guards)
+# Build all protocol buffers if we have got protoc and protobuf available
+if env['HAVE_PROTOBUF']:
+ for proto in ProtoBuf.all:
+ # Use both the source and header as the target, and the .proto
+ # file as the source. When executing the protoc compiler, also
+ # specify the proto_path to avoid having the generated files
+ # include the path.
+ env.Command([proto.cc_file, proto.hh_file], proto.tnode,
+ MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
+ '--proto_path ${SOURCE.dir} $SOURCE',
+ Transform("PROTOC")))
+
+ # Add the C++ source file
+ Source(proto.cc_file, **proto.guards)
+elif ProtoBuf.all:
+ print 'Got protobuf to build, but lacks support!'
+ Exit(1)
+
#
# Handle debug flags
#