From 0b3ddfcd69f614c69a52668ef633d1eed4479cca Mon Sep 17 00:00:00 2001 From: Angus He Date: Wed, 20 Mar 2013 22:55:36 +0800 Subject: [PATCH 1/4] minor fix: include the correct protobuf compiler generated file --- lua_protobuf/generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua_protobuf/generator.py b/lua_protobuf/generator.py index 7081667..2b43529 100644 --- a/lua_protobuf/generator.py +++ b/lua_protobuf/generator.py @@ -131,7 +131,7 @@ def c_header_header(filename, package): '#define LUA_PROTOBUF_%s_H' % package.replace('.', '_'), '', '#include "lua-protobuf.h"', - '#include <%s.pb.h>' % package.replace('.', '/'), + '#include <%s.pb.h>' % filename[:-len('.proto')], '', '#ifdef __cplusplus', 'extern "C" {', From 53f17e7ba690605d9912c28675f6d9f0099c90d0 Mon Sep 17 00:00:00 2001 From: Angus He Date: Fri, 22 Mar 2013 18:03:16 +0800 Subject: [PATCH 2/4] generate file names that are consistent with protobuf's --- lua_protobuf/generator.py | 6 +++--- protoc-gen-lua | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lua_protobuf/generator.py b/lua_protobuf/generator.py index 2b43529..946b915 100644 --- a/lua_protobuf/generator.py +++ b/lua_protobuf/generator.py @@ -127,8 +127,8 @@ def c_header_header(filename, package): '//', '// source proto file: %s' % filename, '', - '#ifndef LUA_PROTOBUF_%s_H' % package.replace('.', '_'), - '#define LUA_PROTOBUF_%s_H' % package.replace('.', '_'), + '#ifndef LUA_PROTOBUF_%s_H' % filename[:-len('.proto')], + '#define LUA_PROTOBUF_%s_H' % filename[:-len('.proto')], '', '#include "lua-protobuf.h"', '#include <%s.pb.h>' % filename[:-len('.proto')], @@ -152,7 +152,7 @@ def source_header(filename, package): '//', '// source proto file: %s' % filename, '', - '#include "%s.pb-lua.h"' % package.replace('.', '/'), + '#include "%s.pb-lua.h"' % filename[:-len('.proto')], '', '#ifdef __cplusplus', 'extern "C" { // make sure functions treated with C naming', diff --git a/protoc-gen-lua b/protoc-gen-lua index d9a81bb..be15e4e 100755 --- a/protoc-gen-lua +++ b/protoc-gen-lua @@ -55,11 +55,11 @@ for i in range(0, len(request.proto_file)): cpp_namespace = '::%s' % package.replace('.', '::') f = response.file.add() - f.name = '%s.pb-lua.h' % package.replace('.', '/') + f.name = '%s.pb-lua.h' % filename[:-len('.proto')] f.content = file_header(file_descriptor) f = response.file.add() - f.name = '%s.pb-lua.cc' % package.replace('.', '/') + f.name = '%s.pb-lua.cc' % filename[:-len('.proto')] f.content = file_source(file_descriptor) f = response.file.add() From 1e43842082334f38051f94a67da40917dadf4ffb Mon Sep 17 00:00:00 2001 From: Angus He Date: Mon, 21 Oct 2013 11:52:03 +0800 Subject: [PATCH 3/4] add plugin_pb2 python module gen script --- gen_plugin_pb2.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 gen_plugin_pb2.py diff --git a/gen_plugin_pb2.py b/gen_plugin_pb2.py new file mode 100755 index 0000000..a896472 --- /dev/null +++ b/gen_plugin_pb2.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import google.protobuf +import os +from distutils.spawn import find_executable +import subprocess +import sys + + +def gen_plugin_pb2(pb_dir): + pkgdir = os.path.dirname(google.protobuf.__file__) + outputdir = os.path.join(pkgdir, "compiler") + os.makedirs(outputdir) + open(os.path.join(outputdir, "__init__.py"), "w+").close() + protoc = find_executable('protoc') + subprocess.call( + [protoc, "-I" + os.path.join(pb_dir, "src"), + "--python_out=" + os.path.join(pkgdir, "../../"), + os.path.join(pb_dir, "src/google/protobuf/compiler/plugin.proto")]) + + +if __name__ == '__main__': + if len(sys.argv) < 2: + sys.stderr.write("gen_plugin_pb2.py \n") + sys.exit(1) + gen_plugin_pb2(os.path.expanduser(sys.argv[1])) From b1b404a0852a644a50b2cf162e5013da5d050a55 Mon Sep 17 00:00:00 2001 From: Angus He Date: Tue, 23 Sep 2014 15:54:03 +0800 Subject: [PATCH 4/4] Make scripts python 2.4 compatiable --- protoc-gen-lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protoc-gen-lua b/protoc-gen-lua index be15e4e..497b056 100755 --- a/protoc-gen-lua +++ b/protoc-gen-lua @@ -30,7 +30,7 @@ from lua_protobuf.generator import file_source, file_header, lua_protobuf_header, lua_protobuf_source from google.protobuf.descriptor import FieldDescriptor from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest, CodeGeneratorResponse -from sys import stdin, stdout, stderr +from sys import stdin, stdout, stderr, exit serialized = stdin.read() request = CodeGeneratorRequest()