From: David Neto Date: Tue, 12 Apr 2016 20:09:13 +0000 (-0400) Subject: Make paths to grammar output files X-Git-Tag: upstream/2018.6~1276 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=469f0e8fd53b527ad410c46bf18eee327c9256a3;p=platform%2Fupstream%2FSPIRV-Tools.git Make paths to grammar output files The directory for a grammar output file will be created if it doesn't already exist. This is required to make the Android.mk build work. --- diff --git a/utils/generate_grammar_tables.py b/utils/generate_grammar_tables.py index 0046083..0cbe969 100755 --- a/utils/generate_grammar_tables.py +++ b/utils/generate_grammar_tables.py @@ -5,6 +5,7 @@ from __future__ import print_function import functools import json +import os.path import re # Prefix for all C variables generated by this script. @@ -13,6 +14,18 @@ PYGEN_VARIABLE_PREFIX = 'pygen_variable' CAPABILITY_BIT_MAPPING = {} +def make_path_to_file(f): + """Makes all ancestor directories to the given file, if they + don't yet exist. + + Arguments: + f: The file whose ancestor directories are to be created. + """ + dir = os.path.dirname(os.path.abspath(f)) + if not os.path.isdir(dir): + os.makedirs(dir) + + def populate_capability_bit_mapping_dict(cap_dict): """Populates CAPABILITY_BIT_MAPPING. @@ -361,6 +374,8 @@ def main(): populate_capability_bit_mapping_dict(cap_dict[0]) if args.core_insts_output is not None: + make_path_to_file(args.core_insts_output) + make_path_to_file(args.operand_kinds_output) print(generate_instruction_table(grammar['instructions'], False), file=open(args.core_insts_output, 'w')) print(generate_operand_kind_table(grammar['operand_kinds']), @@ -369,12 +384,14 @@ def main(): if args.extinst_glsl_grammar is not None: with open(args.extinst_glsl_grammar) as json_file: grammar = json.loads(json_file.read()) + make_path_to_file(args.glsl_insts_output) print(generate_instruction_table(grammar['instructions'], True), file=open(args.glsl_insts_output, 'w')) if args.extinst_opencl_grammar is not None: with open(args.extinst_opencl_grammar) as json_file: grammar = json.loads(json_file.read()) + make_path_to_file(args.opencl_insts_output) print(generate_instruction_table(grammar['instructions'], True), file=open(args.opencl_insts_output, 'w'))