CORD-1334: Support multiple input files
Change-Id: I5ffbb4fdc0f4c44a14cd5066c0e80e5a8cd8fece
diff --git a/xos/genx/tool/Makefile b/xos/genx/tool/Makefile
index 0d94772..9222614 100644
--- a/xos/genx/tool/Makefile
+++ b/xos/genx/tool/Makefile
@@ -8,7 +8,7 @@
# Rule to compile Python files
%.py: %.xproto
- $(XOSGEN) --attic attic --input $< --target $(DJANGO_TARGET) --output $@
+ $(XOSGEN) --attic attic --target $(DJANGO_TARGET) --output $@ $<
# Rule to produce test results
%.ok: %.py
@@ -26,7 +26,7 @@
__init__.py: $(xprotos)
cat $(xprotos) > $(XPROTOS_TMP)
- $(XOSGEN) --attic attic --input $(XPROTOS_TMP) --target $(INIT_TARGET) --output $@ | awk '!seen[$$0]++' > __init__.py
+ $(XOSGEN) --attic attic --target $(INIT_TARGET) --output $@ $(XPROTOS_TMP) | awk '!seen[$$0]++' > __init__.py
tests: $(oks)
diff --git a/xos/genx/tool/generator.py b/xos/genx/tool/generator.py
index 293dc87..d91b6dd 100755
--- a/xos/genx/tool/generator.py
+++ b/xos/genx/tool/generator.py
@@ -21,12 +21,20 @@
def file_exists(self):
def file_exists2(name):
- return (os.path.exists(self.args.attic+'/'+name))
+ try:
+ path = self.args.attic+'/'+name
+ except TypeError:
+ path = name
+ return (os.path.exists(path))
return file_exists2
def include_file(self):
def include_file2(name):
- return open(self.args.attic+'/'+name).read()
+ try:
+ path = self.args.attic+'/'+name
+ except TypeError:
+ path = name
+ return open(path).read()
return include_file2
# FIXME: Support templates in the future
#return jinja2.Markup(loader.get_source(env, name)[0])
@@ -34,7 +42,7 @@
def generate(self):
try:
parser = plyproto.ProtobufAnalyzer()
- input = open(self.args.input).read()
+ input = self.input
ast = parser.parse_string(input,debug=0)
if (self.args.rev):
@@ -117,7 +125,7 @@
except Exception as e:
- print " Error occurred! file[%s]" % (self.args.input), e
+ print " Error occurred! file[%s]" % (self.args.inputs), e
print '-'*60
traceback.print_exc(file=sys.stdout)
print '-'*60
diff --git a/xos/genx/tool/xosgen b/xos/genx/tool/xosgen
index 6528b09..cd63a2e 100755
--- a/xos/genx/tool/xosgen
+++ b/xos/genx/tool/xosgen
@@ -9,16 +9,22 @@
parse = argparse.ArgumentParser(description='XOS code generator')
parse.add_argument('--rev', dest='rev', action='store_true',default=False, help='Convert proto to xproto')
-parse.add_argument('--input', dest='input', action='store',default=None, help='Filename in Protobufs')
-parse.add_argument('--target', dest='target', action='store',default=None, help='Output format, corresponding to <output>.yaml file')
+parse.add_argument('--target', dest='target', action='store',default=None, help='Output format, corresponding to <output>.yaml file', required=True)
parse.add_argument('--output', dest='output', action='store',default=None, help='Destination path')
parse.add_argument('--attic', dest='attic', action='store',default=None, help='The location at which static files are stored')
parse.add_argument('--kvpairs', dest='kv', action='store',default=None, help='Key value pairs to make available to the target')
+parse.add_argument('inputs', metavar='<input file>', nargs='+', action='store', help='xproto files to compile')
args = parse.parse_args()
def main():
+ input = ''
+ for fname in args.inputs:
+ with open(fname) as infile:
+ input+=infile.read()
+
generator = XOSGenerator(args)
+ generator.input = input
generator.generate()
if __name__=='__main__':
diff --git a/xos/genx/tool/xproto_test_base.py b/xos/genx/tool/xproto_test_base.py
index 2315eaf..4d05197 100644
--- a/xos/genx/tool/xproto_test_base.py
+++ b/xos/genx/tool/xproto_test_base.py
@@ -54,10 +54,11 @@
args.rev = rev
args.kv = kv
args.attic = XPROTO_DIR
- args.input = XPROTO_PATH
+ args.inputs = [XPROTO_PATH]
args.output = OUTPUT_PATH
args.target = TARGET_FILE
g = XOSGenerator(args)
+ g.input = open(XPROTO_PATH).read()
g.generate()
def get_output(self):