|  | @@ -5,20 +5,27 @@ directly.
 | 
	
		
			
				|  |  |  """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def generate_cc_impl(ctx):
 | 
	
		
			
				|  |  | -  """Implementation of the gengrpccc rule."""
 | 
	
		
			
				|  |  | +  """Implementation of the generate_cc rule."""
 | 
	
		
			
				|  |  |    protos = [f for src in ctx.attr.srcs for f in src.proto.direct_sources]
 | 
	
		
			
				|  |  |    includes = [f for src in ctx.attr.srcs for f in src.proto.transitive_imports]
 | 
	
		
			
				|  |  |    outs = []
 | 
	
		
			
				|  |  | -  outs += [proto.basename[:-len(".proto")] + ".grpc.pb.h" for proto in protos]
 | 
	
		
			
				|  |  | -  outs += [proto.basename[:-len(".proto")] + ".grpc.pb.cc" for proto in protos]
 | 
	
		
			
				|  |  | +  if ctx.executable.plugin:
 | 
	
		
			
				|  |  | +    outs += [proto.basename[:-len(".proto")] + ".grpc.pb.h" for proto in protos]
 | 
	
		
			
				|  |  | +    outs += [proto.basename[:-len(".proto")] + ".grpc.pb.cc" for proto in protos]
 | 
	
		
			
				|  |  | +  else:
 | 
	
		
			
				|  |  | +    outs += [proto.basename[:-len(".proto")] + ".pb.h" for proto in protos]
 | 
	
		
			
				|  |  | +    outs += [proto.basename[:-len(".proto")] + ".pb.cc" for proto in protos]
 | 
	
		
			
				|  |  |    out_files = [ctx.new_file(out) for out in outs]
 | 
	
		
			
				|  |  |    # The following should be replaced with ctx.configuration.buildout
 | 
	
		
			
				|  |  |    # whenever this is added to Skylark.
 | 
	
		
			
				|  |  |    dir_out = out_files[0].dirname[:-len(protos[0].dirname)]
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    arguments = []
 | 
	
		
			
				|  |  | -  arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path]
 | 
	
		
			
				|  |  | -  arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
 | 
	
		
			
				|  |  | +  if ctx.executable.plugin:
 | 
	
		
			
				|  |  | +    arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path]
 | 
	
		
			
				|  |  | +    arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
 | 
	
		
			
				|  |  | +  else:
 | 
	
		
			
				|  |  | +    arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
 | 
	
		
			
				|  |  |    arguments += ["-I{0}={0}".format(include.path) for include in includes]
 | 
	
		
			
				|  |  |    arguments += [proto.path for proto in protos]
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -41,16 +48,16 @@ generate_cc = rule(
 | 
	
		
			
				|  |  |          "plugin": attr.label(
 | 
	
		
			
				|  |  |              executable = True,
 | 
	
		
			
				|  |  |              providers = ["files_to_run"],
 | 
	
		
			
				|  |  | -            cfg = HOST_CFG,
 | 
	
		
			
				|  |  | +            cfg = "host",
 | 
	
		
			
				|  |  |          ),
 | 
	
		
			
				|  |  |          "flags": attr.string_list(
 | 
	
		
			
				|  |  | -            mandatory = True,
 | 
	
		
			
				|  |  | -            allow_empty = False
 | 
	
		
			
				|  |  | +            mandatory = False,
 | 
	
		
			
				|  |  | +            allow_empty = True,
 | 
	
		
			
				|  |  |          ),
 | 
	
		
			
				|  |  |          "_protoc": attr.label(
 | 
	
		
			
				|  |  | -            default = Label("//extern:protocol_compiler"),
 | 
	
		
			
				|  |  | +            default = Label("//external:protocol_compiler"),
 | 
	
		
			
				|  |  |              executable = True,
 | 
	
		
			
				|  |  | -            cfg = HOST_CFG,
 | 
	
		
			
				|  |  | +            cfg = "host",
 | 
	
		
			
				|  |  |          ),
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |      # We generate .h files, so we need to output to genfiles.
 |