diff options
author | George Kyriazis <george.kyriazis@intel.com> | 2016-11-18 11:38:30 -0600 |
---|---|---|
committer | Tim Rowley <timothy.o.rowley@intel.com> | 2016-11-21 12:44:47 -0600 |
commit | 9e4e1f519084346b08b26b4ded635d44711e8014 (patch) | |
tree | eb6357a1ee5f4070c771f68b002e7f6bb745db95 | |
parent | 9085f1a9ccdfdfbdd470c871335edf360cf56c58 (diff) |
swr: Modify gen_knobs.{cpp|h} creation script
Modify gen_knobs.py so that each invocation creates a single generated
file. This is more similar to how the other generators behave.
v5: remove Scoscript edits from this commit; moved to commit that first
adds SConscript
Acked-by: Emil Velikov <emil.velikov@collabora.com>
-rw-r--r-- | src/gallium/drivers/swr/Makefile.am | 14 | ||||
-rw-r--r-- | src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py | 51 |
2 files changed, 39 insertions, 26 deletions
diff --git a/src/gallium/drivers/swr/Makefile.am b/src/gallium/drivers/swr/Makefile.am index dd1c2e6a78a..4cd1c33fc9c 100644 --- a/src/gallium/drivers/swr/Makefile.am +++ b/src/gallium/drivers/swr/Makefile.am @@ -71,11 +71,21 @@ swr_context_llvm.h: rasterizer/jitter/scripts/gen_llvm_types.py swr_context.h --input $(srcdir)/swr_context.h \ --output swr_context_llvm.h -rasterizer/scripts/gen_knobs.cpp rasterizer/scripts/gen_knobs.h: rasterizer/scripts/gen_knobs.py rasterizer/scripts/knob_defs.py rasterizer/scripts/templates/knobs.template +rasterizer/scripts/gen_knobs.cpp: rasterizer/scripts/gen_knobs.py rasterizer/scripts/knob_defs.py rasterizer/scripts/templates/knobs.template $(MKDIR_GEN) $(PYTHON_GEN) \ $(srcdir)/rasterizer/scripts/gen_knobs.py \ - rasterizer/scripts + --input $(srcdir)/rasterizer/scripts/templates/knobs.template \ + --output rasterizer/scripts/gen_knobs.cpp \ + --gen_cpp + +rasterizer/scripts/gen_knobs.h: rasterizer/scripts/gen_knobs.py rasterizer/scripts/knob_defs.py rasterizer/scripts/templates/knobs.template + $(MKDIR_GEN) + $(PYTHON_GEN) \ + $(srcdir)/rasterizer/scripts/gen_knobs.py \ + --input $(srcdir)/rasterizer/scripts/templates/knobs.template \ + --output rasterizer/scripts/gen_knobs.h \ + --gen_h rasterizer/jitter/state_llvm.h: rasterizer/jitter/scripts/gen_llvm_types.py rasterizer/core/state.h $(MKDIR_GEN) diff --git a/src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py b/src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py index 3d003fb4a33..225082e7882 100644 --- a/src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py +++ b/src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py @@ -23,13 +23,14 @@ from __future__ import print_function import os import sys +import argparse import knob_defs from mako.template import Template from mako.exceptions import RichTraceback def write_template_to_string(template_filename, **kwargs): try: - template = Template(filename=template_filename) + template = Template(filename=os.path.abspath(template_filename)) # Split + Join fixes line-endings for whatever platform you are using return '\n'.join(template.render(**kwargs).splitlines()) except: @@ -40,37 +41,39 @@ def write_template_to_string(template_filename, **kwargs): print("%s: %s" % (str(traceback.error.__class__.__name__), traceback.error)) def write_template_to_file(template_filename, output_filename, **kwargs): + output_dirname = os.path.dirname(output_filename) + if not os.path.exists(output_dirname): + os.makedirs(output_dirname) with open(output_filename, "w") as outfile: print(write_template_to_string(template_filename, **kwargs), file=outfile) def main(args=sys.argv[1:]): - if len(args) != 1: - print('Usage:', sys.argv[0], '<output_directory>', file=sys.stderr) - return 1 - output_dir = args[0] - if not os.path.isdir(output_dir): - if os.path.exists(output_dir): - print('ERROR: Invalid output directory:', output_dir, file=sys.stderr) - return 1 + # parse args + parser = argparse.ArgumentParser() + parser.add_argument("--input", "-i", help="Path to knobs.template", required=True) + parser.add_argument("--output", "-o", help="Path to output file", required=True) + parser.add_argument("--gen_h", "-gen_h", help="Generate gen_knobs.h", action="store_true", default=False) + parser.add_argument("--gen_cpp", "-gen_cpp", help="Generate gen_knobs.cpp", action="store_true", required=False) - try: - os.makedirs(output_dir) - except: - print('ERROR: Could not create output directory:', output_dir, file=sys.stderr) - return 1 + args = parser.parse_args() - # Output path exists, now just run the template - template_file = os.sep.join([sys.path[0], 'templates', 'knobs.template']) - output_file = os.sep.join([output_dir, 'gen_knobs.cpp']) - output_header = os.sep.join([output_dir, 'gen_knobs.h']) + if args.input: + if args.gen_h: + write_template_to_file(args.input, + args.output, + filename='gen_knobs', + knobs=knob_defs.KNOBS, + includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'], + gen_header=True) - for f in [output_header, output_file]: - write_template_to_file(template_file, f, - filename='gen_knobs', - knobs=knob_defs.KNOBS, - includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'], - gen_header=True if f == output_header else False) + if args.gen_cpp: + write_template_to_file(args.input, + args.output, + filename='gen_knobs', + knobs=knob_defs.KNOBS, + includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'], + gen_header=False) return 0 |