Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions gen_plugin_pb2.py
Original file line number Diff line number Diff line change
@@ -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 <protubuf project dir>\n")
sys.exit(1)
gen_plugin_pb2(os.path.expanduser(sys.argv[1]))
8 changes: 4 additions & 4 deletions lua_protobuf/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ 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>' % package.replace('.', '/'),
'#include <%s.pb.h>' % filename[:-len('.proto')],
'',
'#ifdef __cplusplus',
'extern "C" {',
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions protoc-gen-lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down