forked from WireCell/wire-cell-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotobuf.py
56 lines (40 loc) · 1.47 KB
/
protobuf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# encoding: utf-8
# Philipp Bender, 2012
from waflib.Task import Task
from waflib.TaskGen import extension
import generic
"""
A simple tool to integrate protocol buffers into your build system.
def configure(conf):
conf.load('compiler_cxx cxx protoc_cxx')
def build(bld):
bld.program(source = "main.cpp file1.proto proto/file2.proto",
target = "executable")
"""
class protoc(Task):
# the cp is to bring the .h file into the build working directory
run_str = '${PROTOC} ${SRC} --cpp_out=. -I.. && cp ${TGT[1].abspath()} .'
color = 'BLUE'
ext_out = ['.h', 'pb.cc']
class protopy(Task):
run_str = '${PROTOC} ${SRC} --python_out=. -I..'
color = 'BLUE'
ext_out = ['pb2.py']
@extension('.proto')
def process_protoc(self, node):
py_node = node.change_ext('_pb2.py')
cpp_node = node.change_ext('.pb.cc')
hpp_node = node.change_ext('.pb.h')
self.create_task('protopy', node, [py_node])
self.create_task('protoc', node, [cpp_node, hpp_node])
self.source.append(cpp_node)
self.env.append_value('INCLUDES', ['.'] )
self.use = self.to_list(getattr(self, 'use', '')) + ['PROTOBUF']
def options(opt):
generic._options(opt, 'protobuf')
def configure(cfg):
generic._configure(cfg, 'protobuf',
incs=('google/protobuf/message.h',), libs=('protobuf',),
mandatory=False)
cfg.find_program('protoc', var='PROTOC', mandatory=False)