else:
return open(name, mode)
-infile = None
-outfile = sys.stdout
+infname = None
+outfname = '-'
glslang = 'glslangValidator'
arg_idx = 1
print_usage(0)
elif sys.argv[arg_idx] == '-o':
arg_idx += 1
- outfile = open_file(sys.argv[arg_idx], 'w')
+ outfname = sys.argv[arg_idx]
elif sys.argv[arg_idx].startswith('--with-glslang='):
glslang = sys.argv[arg_idx][len('--with-glslang='):]
else:
- infile = open_file(sys.argv[arg_idx], 'r')
+ infname = sys.argv[arg_idx]
break
arg_idx += 1
-if arg_idx < len(sys.argv) - 1 or not infile or not outfile:
+if arg_idx < len(sys.argv) - 1 or not infname or not outfname:
print_usage(1)
-parser = Parser(infile)
-parser.run()
+with open_file(infname, 'r') as infile:
+ parser = Parser(infile)
+ parser.run()
# glslangValidator has an absolutely *insane* interface. We pretty much
# have to run in a temporary directory. Sad day.
finally:
shutil.rmtree(tmpdir)
-outfile.write("""\
+with open_file(outfname, 'w') as outfile:
+ outfile.write("""\
/* =========================== DO NOT EDIT! ===========================
* This file is autogenerated by glsl_scraper.py.
*/
#include <stdint.h>""")
-for shader in parser.shaders:
- shader.dump_c_code(outfile)
+ for shader in parser.shaders:
+ shader.dump_c_code(outfile)