2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-22 09:57:15 +01:00

protoc: handle extra taskgen and out of project include directories

This commit is contained in:
fedepell 2018-12-21 06:16:08 +01:00
parent b755748c4c
commit 70f1522fa1
4 changed files with 45 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package udp.tc.tests;
import "message_inc.proto";
import "message_inc_tl.proto";
option java_package ="com.udp.tc.tests";
option java_outer_classname= "MessageProtos";
@ -12,4 +13,5 @@ message Message {
required int32 test = 1;
optional uint32 blah = 2;
required IncludeMe custom = 3;
required IncludeMeFromTop customfromtop = 4;
}

View File

@ -6,4 +6,6 @@ def build(bld):
features = 'py',
name = 'pbpyrec',
source = ['increc/message.proto'],
protoc_includes = ['increc'])
protoc_includes = ['increc', 'othermod/deep/inc'],
protoc_extincludes = ['/usr/include/pblib', '/usr/share/protos']
)

View File

@ -0,0 +1,11 @@
package udp.tc.tests;
option java_package = "com.udp.tc.tests";
option java_outer_classname = "MessageInc";
option cc_generic_services = false;
option java_generic_services = false;
option py_generic_services = false;
message IncludeMeFromTop {
required int32 testext = 1;
}

View File

@ -67,6 +67,13 @@ Example for Java:
protoc_includes = ['inc']) # for protoc to search dependencies
Protoc includes passed via protoc_includes are either relative to the taskgen
or to the project and are searched in this order.
Include directories external to the waf project can also be passed to the
extra by using protoc_extincludes
protoc_extincludes = ['/usr/include/pblib']
Notes when using this tool:
@ -82,7 +89,7 @@ Notes when using this tool:
"""
class protoc(Task):
run_str = '${PROTOC} ${PROTOC_FL:PROTOC_FLAGS} ${PROTOC_ST:INCPATHS} ${PROTOC_ST:PROTOC_INCPATHS} ${SRC[0].bldpath()}'
run_str = '${PROTOC} ${PROTOC_FL:PROTOC_FLAGS} ${PROTOC_ST:INCPATHS} ${PROTOC_ST:PROTOC_INCPATHS} ${PROTOC_ST:PROTOC_EXTINCPATHS} ${SRC[0].bldpath()}'
color = 'BLUE'
ext_out = ['.h', 'pb.cc', '.py', '.java']
def scan(self):
@ -104,7 +111,17 @@ class protoc(Task):
if 'py' in self.generator.features or 'javac' in self.generator.features:
for incpath in getattr(self.generator, 'protoc_includes', []):
search_nodes.append(self.generator.path.find_node(incpath))
incpath_node = self.generator.path.find_node(incpath)
if incpath_node:
search_nodes.append(incpath_node)
else:
# Check if relative to top-level for extra tg dependencies
incpath_node = self.generator.bld.path.find_node(incpath)
if incpath_node:
search_nodes.append(incpath_node)
else:
raise Errors.WafError('protoc: include path %r does not exist' % incpath)
def parse_node(node):
if node in seen:
@ -126,7 +143,7 @@ class protoc(Task):
parse_node(node)
# Add also dependencies path to INCPATHS so protoc will find the included file
for deppath in nodes:
self.env.append_value('INCPATHS', deppath.parent.bldpath())
self.env.append_unique('INCPATHS', deppath.parent.bldpath())
return (nodes, names)
@extension('.proto')
@ -223,10 +240,18 @@ def process_protoc(self, node):
if incpath_node:
incdirs.append(incpath_node.bldpath())
else:
raise Errors.WafError('protoc: include path %r does not exist' % incpath)
# Check if relative to top-level for extra tg dependencies
incpath_node = self.bld.path.find_node(incpath)
if incpath_node:
incdirs.append(incpath_node.bldpath())
else:
raise Errors.WafError('protoc: include path %r does not exist' % incpath)
tsk.env.PROTOC_INCPATHS = incdirs
# Include paths external to the waf project (ie. shared pb repositories)
tsk.env.PROTOC_EXTINCPATHS = getattr(self, 'protoc_extincludes', [])
# PR2115: protoc generates output of .proto files in nested
# directories by canonicalizing paths. To avoid this we have to pass
# as first include the full directory file of the .proto file