From 53027fc3d3d2fc9a640f7578f012d289ddeb8d2a Mon Sep 17 00:00:00 2001 From: Marc Slemko Date: Thu, 17 Aug 2006 01:12:11 +0000 Subject: [PATCH] Python installer for thrift idl compiler git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664760 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/setup.py | 13 ++++++++++ compiler/src/cpp_generator.py | 6 ++--- compiler/src/thrift.py | 47 +++++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 compiler/setup.py diff --git a/compiler/setup.py b/compiler/setup.py new file mode 100644 index 00000000..d5bbae86 --- /dev/null +++ b/compiler/setup.py @@ -0,0 +1,13 @@ +from distutils.core import setup + +setup(name='Thrift', + version='1.0', + description='Thrift IDL compiler', + author =['Mark Slee', 'Marc Kwiatkowski'], + author_email= ['mcslee@facebook.com', 'marc@facebook.com'], + url='http://code.facebook.com/thrift', + package_dir={'thrift' : 'src'}, + py_modules = ['thrift.parser', 'thrift.cpp_generator', 'thrift.generator'], + scripts = ['src/thrift'] + ) + diff --git a/compiler/src/cpp_generator.py b/compiler/src/cpp_generator.py index fd25e17c..f1bf84c0 100644 --- a/compiler/src/cpp_generator.py +++ b/compiler/src/cpp_generator.py @@ -2,8 +2,8 @@ import time import os import os.path from string import Template -from parser import * -from generator import * +from thrift.parser import * +from thrift.generator import * HEADER_COMMENT = """/** * Autogenerated by Thrift @@ -529,7 +529,7 @@ def toServerServiceDefinition(service, debugp=None): result+= toServerFunctionDefinition(service.name, function, debugp) - callProcessSwitch = " if"+string.join(["(name.compare(\""+function.name+"\") == 0) { process_"+function.name+"(seqid, itrans, otrans);\n}" for function in service.functionList], "\n else if")+" else {throw "+CPP_EXCEPTION+"(\"Unknown function name \\\"\"+name+\"\\\"\");}" + callProcessSwitch = " if"+string.join(["(name.compare(\""+function.name+"\") == 0) {\n process_"+function.name+"(seqid, itrans, otrans);\n }" for function in service.functionList], " else if")+" else {\n throw "+CPP_EXCEPTION+"(\"Unknown function name \\\"\"+name+\"\\\"\");\n }" result+= CPP_SERVER_PROCESS_DEFINITION.substitute(service=service.name, callProcessSwitch=callProcessSwitch) diff --git a/compiler/src/thrift.py b/compiler/src/thrift.py index 9282620c..39bdb162 100644 --- a/compiler/src/thrift.py +++ b/compiler/src/thrift.py @@ -1,18 +1,41 @@ +#!python import sys -import generator -import cpp_generator -import parser +from thrift import cpp_generator +from thrift import generator +from thrift import parser -if __name__ == '__main__': - - args = sys.argv[1:] +def thrift(source, cpp=False, perl=False, php=False, python=False, java=False, ruby=False, debug=False): generators = [] + if cpp: + generators.append(cpp_generator.CPPGenerator()) + + p = parser.Parser(debug=debug) + + p.parse(source, False) + + for generator in generators: + generator(p.program, source) + + if len(p.errors): + return -1 + else: + return 0 + +def main(args): + + cpp = False + perl = False + php = False + python = False + java = False + ruby = False + debug = False if "--cpp" in args: - generators.append(cpp_generator.CPPGenerator()) + cpp = True args.remove("--cpp") if "--debug" in args: debug = True @@ -20,12 +43,10 @@ if __name__ == '__main__': filename = args[-1] - p = parser.Parser(debug=debug) - - p.parse(filename, False) + result = thrift(filename, cpp, java, perl, php, python, ruby, debug) - if len(p.errors): - sys.exit(-1) + sys.exit(result) - [g(p.program, filename) for g in generators] +if __name__ == '__main__': + main(sys.argv) -- 2.17.1