From: Jason Ekstrand Date: Tue, 19 May 2015 17:44:59 +0000 (-0700) Subject: vk/glsl_scraper: Don't open files until needed X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=15739131948f44a5c7226bb83e80138056affa02;p=mesa.git vk/glsl_scraper: Don't open files until needed This prevents us from writing an empty file when the compile failed. --- diff --git a/src/vulkan/glsl_scraper.py b/src/vulkan/glsl_scraper.py index 4b99ae0a3e2..fa62daf5a2b 100644 --- a/src/vulkan/glsl_scraper.py +++ b/src/vulkan/glsl_scraper.py @@ -186,8 +186,8 @@ def open_file(name, mode): else: return open(name, mode) -infile = None -outfile = sys.stdout +infname = None +outfname = '-' glslang = 'glslangValidator' arg_idx = 1 @@ -196,19 +196,20 @@ while arg_idx < len(sys.argv): 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. @@ -225,12 +226,13 @@ try: 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 """) -for shader in parser.shaders: - shader.dump_c_code(outfile) + for shader in parser.shaders: + shader.dump_c_code(outfile)