Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/48134 )

Change subject: scons: Turn the ProtoBuf and GrpcProtoBuf classes into methods.
......................................................................

scons: Turn the ProtoBuf and GrpcProtoBuf classes into methods.

These now instantiate Builders for the protobuf .cc and .h files of the
right flavors, and install the .cc files as sources.

Also, this sets up the builder for .cc files so that it will know how to
build those files from .proto using the protobuf compiler. This is
optional, but will make it possible to pass .proto files in place of .cc
files or even object files as sources for other builders, and for scons
to figure out what chain of rules to use to get the desired results.

This is a step towards handing over more responsibility to scons and
eliminating at least some of our bespoke build code.

Change-Id: I7188a0917e999ad9148f7079830b2c26bcd563db
---
M src/SConscript
1 file changed, 26 insertions(+), 47 deletions(-)



diff --git a/src/SConscript b/src/SConscript
index a6229a6..1750ed5 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -430,36 +430,25 @@
     root, ext = os.path.splitext(source[0].get_abspath())
     return [root + '.pb.cc', root + '.pb.h'], source

-env.Append(BUILDERS={'ProtoBufCC' : Builder(
-            action=MakeAction('${PROTOC} --cpp_out ${BUILDDIR} '
-                              '--proto_path ${BUILDDIR} '
-                              '${SOURCE.get_abspath()}',
-                              Transform("PROTOC")),
-            emitter=protoc_emitter
-        )})
+protoc_action = MakeAction('${PROTOC} --cpp_out ${BUILDDIR} '
+        '--proto_path ${BUILDDIR} ${SOURCE.get_abspath()}',
+        Transform("PROTOC"))
+protobuf_builder = Builder(action=protoc_action, emitter=protoc_emitter,
+        src_suffix='.proto')
+env.Append(BUILDERS={'ProtoBufCC' : protobuf_builder})

-class ProtoBuf(SourceFile):
+c_file, cxx_file = SCons.Tool.createCFileBuilders(env)
+cxx_file.add_action('.proto', protoc_action)
+cxx_file.add_emitter('.proto', protoc_emitter)
+
+def ProtoBuf(source, tags=None, add_tags=None):
     '''Add a Protocol Buffer to build'''

-    def __init__(self, source, tags=None, add_tags=None):
-        '''Specify the source file, and any tags'''
-        super(ProtoBuf, self).__init__(source, tags, add_tags)
+    if not env['HAVE_PROTOC'] or not env['HAVE_PROTOBUF']:
+        error('Got protobuf to build, but lacks support!')

-        if not env['HAVE_PROTOC'] or not env['HAVE_PROTOBUF']:
-            error('Got protobuf to build, but lacks support!')
-
-        # Get the file name and the extension
-        basename = os.path.basename(self.filename)
-        modname, ext = os.path.splitext(basename)
-        assert ext == '.proto'
-
-        self.cc_file, self.hh_file = env.ProtoBufCC(source=source)
-
-        # Add the C++ source file
-        Source(self.cc_file, tags=self.tags,
-                append={'CXXFLAGS': '-Wno-array-bounds'})
-
-
+    '''Specify the source file, and any tags'''
+ Source(source, tags, add_tags, append={'CXXFLAGS': '-Wno-array-bounds'})

 env['PROTOC_GRPC'] = distutils.spawn.find_executable('grpc_cpp_plugin')
 if env['PROTOC_GRPC']:
@@ -469,34 +458,24 @@
     root, ext = os.path.splitext(source[0].get_abspath())
     return [root + '.grpc.pb.cc', root + '.grpc.pb.h'], source

+protoc_grpc_action=MakeAction('${PROTOC} --grpc_out ${BUILDDIR} '
+        '--plugin=protoc-gen-grpc=${PROTOC_GRPC} --proto_path ${BUILDDIR} '
+        '${SOURCE.get_abspath()}',
+        Transform("PROTOC"))
+
 env.Append(BUILDERS={'GrpcProtoBufCC' : Builder(
-            action=MakeAction('${PROTOC} --grpc_out ${BUILDDIR} '
-                              '--plugin=protoc-gen-grpc=${PROTOC_GRPC} '
-                              '--proto_path ${BUILDDIR} '
-                              '${SOURCE.get_abspath()}',
-                              Transform("PROTOC")),
+            action=protoc_grpc_action,
             emitter=protoc_grpc_emitter
         )})

-class GrpcProtoBuf(SourceFile):
+def GrpcProtoBuf(source, tags=None, add_tags=None):
     '''Add a GRPC protocol buffer to the build'''

-    def __init__(self, source, tags=None, add_tags=None):
-        '''Specify the source file, and any tags'''
+    if not env['PROTOC_GRPC']:
+        error('No grpc_cpp_plugin found')

-        super(GrpcProtoBuf, self).__init__(source, tags, add_tags)
-
-        if not env['PROTOC_GRPC']:
-            error('No grpc_cpp_plugin found')
-
-        self.cc_file, self.hh_file = env.GrpcProtoBufCC(source=source)
-
-        # We still need to build the normal protobuf code too.
-        self.protobuf = ProtoBuf(source, tags=self.tags)
-
-        # Add the C++ source file.
-        Source(self.cc_file, tags=self.tags,
-                append={'CXXFLAGS': '-Wno-array-bounds'})
+ Source(env.GrpcProtoBufCC(source=source)[0], tags=tags, add_tags=add_tags)
+    Source(env.ProtoBufCC(source=source)[0], tags=tags, add_tags=add_tags)


 exectuable_classes = []

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/48134
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I7188a0917e999ad9148f7079830b2c26bcd563db
Gerrit-Change-Number: 48134
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to