diff options
author | Alok Hota <[email protected]> | 2018-08-31 12:13:56 -0500 |
---|---|---|
committer | Alok Hota <[email protected]> | 2019-05-01 15:11:30 +0000 |
commit | 396831adf8ebca26008f4d9e6e4dea28cdbb9005 (patch) | |
tree | a3dc6c390290636019d6180c744d0e0ae820e4e5 /src/gallium/drivers/swr | |
parent | 47f419d0b37721776785a54005783ef6fe836d66 (diff) |
swr/rast: Cleanup and generalize gen_archrast
- Update meson.build
- Includes current_build_dir() fix
meson/swr: replace hard-coded path with current_build_dir()
Fixes: 93cd9905c8fbb98985ae "swr/rast: Cleanup and generalize gen_archrast"
Signed-off-by: Eric Engestrom <[email protected]>
Reviewed-by: Alok Hota <[email protected]>
Reviewed-by: Dylan Baker <[email protected]>
- Clean up meson.build (remove foreach loop, replace with single call)
- Update SConscript
- use `$SOURCES` to call `CodeGenerate` with multiple source files
Reviewed-by: Bruce Cherniak <[email protected]>
Diffstat (limited to 'src/gallium/drivers/swr')
-rw-r--r-- | src/gallium/drivers/swr/SConscript | 32 | ||||
-rw-r--r-- | src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py | 116 | ||||
-rw-r--r-- | src/gallium/drivers/swr/rasterizer/codegen/meson.build | 32 |
3 files changed, 57 insertions, 123 deletions
diff --git a/src/gallium/drivers/swr/SConscript b/src/gallium/drivers/swr/SConscript index a89d02c5db0..b0bead242f7 100644 --- a/src/gallium/drivers/swr/SConscript +++ b/src/gallium/drivers/swr/SConscript @@ -103,44 +103,26 @@ Depends('rasterizer/jitter/gen_state_llvm.h', swrroot + 'rasterizer/codegen/templates/gen_llvm.hpp') env.CodeGenerate( - target = 'rasterizer/archrast/gen_ar_event.hpp', script = swrroot + 'rasterizer/codegen/gen_archrast.py', - source = 'rasterizer/archrast/events.proto', - command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_event_hpp' -) + target = ['rasterizer/archrast/gen_ar_event.hpp', + 'rasterizer/archrast/gen_ar_event.cpp', + 'rasterizer/archrast/gen_ar_eventhandler.hpp', + 'rasterizer/archrast/gen_ar_eventhandlerfile.hpp'], + source = [srcroot + '/rasterizer/archrast/events.proto', + srcroot + '/rasterizer/archrast/events_private.proto'], + command = python_cmd + ' $SCRIPT --proto $SOURCES --output-dir ' + bldroot + '/rasterizer/archrast') Depends('rasterizer/archrast/gen_ar_event.hpp', swrroot + 'rasterizer/archrast/events_private.proto') Depends('rasterizer/jitter/gen_state_llvm.h', swrroot + 'rasterizer/codegen/templates/gen_ar_event.hpp') - -env.CodeGenerate( - target = 'rasterizer/archrast/gen_ar_event.cpp', - script = swrroot + 'rasterizer/codegen/gen_archrast.py', - source = 'rasterizer/archrast/events.proto', - command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_event_cpp' -) Depends('rasterizer/archrast/gen_ar_event.cpp', swrroot + 'rasterizer/archrast/events_private.proto') Depends('rasterizer/jitter/gen_state_llvm.h', swrroot + 'rasterizer/codegen/templates/gen_ar_event.cpp') - -env.CodeGenerate( - target = 'rasterizer/archrast/gen_ar_eventhandler.hpp', - script = swrroot + 'rasterizer/codegen/gen_archrast.py', - source = 'rasterizer/archrast/events.proto', - command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_eventhandler_hpp' -) Depends('rasterizer/archrast/gen_ar_eventhandler.hpp', swrroot + 'rasterizer/archrast/events_private.proto') Depends('rasterizer/jitter/gen_state_llvm.h', swrroot + 'rasterizer/codegen/templates/gen_ar_eventhandler.hpp') - -env.CodeGenerate( - target = 'rasterizer/archrast/gen_ar_eventhandlerfile.hpp', - script = swrroot + 'rasterizer/codegen/gen_archrast.py', - source = 'rasterizer/archrast/events.proto', - command = python_cmd + ' $SCRIPT --proto $SOURCE --proto_private ' + srcroot + '/rasterizer/archrast/events_private.proto --output $TARGET --gen_eventhandlerfile_hpp' -) Depends('rasterizer/archrast/gen_ar_eventhandlerfile.hpp', swrroot + 'rasterizer/archrast/events_private.proto') Depends('rasterizer/jitter/gen_state_llvm.h', diff --git a/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py b/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py index c5842aa48d2..7c953801a91 100644 --- a/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py +++ b/src/gallium/drivers/swr/rasterizer/codegen/gen_archrast.py @@ -116,37 +116,17 @@ def main(): # Parse args... parser = ArgumentParser() - parser.add_argument('--proto', '-p', help='Path to proto file', required=True) - parser.add_argument('--proto_private', '-pp', help='Path to private proto file', required=True) - parser.add_argument('--output', '-o', help='Output filename (i.e. event.hpp)', required=True) - parser.add_argument('--gen_event_hpp', help='Generate event header', action='store_true', default=False) - parser.add_argument('--gen_event_cpp', help='Generate event cpp', action='store_true', default=False) - parser.add_argument('--gen_eventhandler_hpp', help='Generate eventhandler header', action='store_true', default=False) - parser.add_argument('--gen_eventhandlerfile_hpp', help='Generate eventhandler header for writing to files', action='store_true', default=False) + parser.add_argument('--proto', '-p', dest="protos", nargs='+', help='Path to all proto file(s) to process. Accepts one or more paths (i.e. events.proto and events_private.proto)', required=True) + parser.add_argument('--output-dir', help='Output dir (defaults to ./codegen). Will create folder if it does not exist.', required=False, default='codegen') args = parser.parse_args() - proto_filename = args.proto - proto_private_filename = args.proto_private + if not os.path.exists(args.output_dir): + MakeDir(args.output_dir) - (output_dir, output_filename) = os.path.split(args.output) - - if not output_dir: - output_dir = '.' - - #print('output_dir = %s' % output_dir, file=sys.stderr) - #print('output_filename = %s' % output_filename, file=sys.stderr) - - if not os.path.exists(proto_filename): - print('Error: Could not find proto file %s' % proto_filename, file=sys.stderr) - return 1 - - if not os.path.exists(proto_private_filename): - print('Error: Could not find private proto file %s' % proto_private_filename, file=sys.stderr) - return 1 - - final_output_dir = output_dir - MakeDir(final_output_dir) - output_dir = MakeTmpDir('_codegen') + for f in args.protos: + if not os.path.exists(f): + print('Error: Could not find proto file %s' % f, file=sys.stderr) + return 1 protos = {} protos['events'] = {} # event dictionary containing events with their fields @@ -154,66 +134,48 @@ def main(): protos['enums'] = {} protos['enum_names'] = [] - parse_protos(protos, proto_filename) - parse_protos(protos, proto_private_filename) + # Parse each proto file and add to protos container + for f in args.protos: + print("Parsing proto file: %s" % os.path.normpath(f)) + parse_protos(protos, f) + + files = [ + ["gen_ar_event.hpp", ""], + ["gen_ar_event.cpp", ""], + ["gen_ar_eventhandler.hpp", "gen_ar_event.hpp"], + ["gen_ar_eventhandlerfile.hpp", "gen_ar_eventhandler.hpp"] + ] rval = 0 try: - # Generate event header - if args.gen_event_hpp: + # Delete existing files + for f in files: + filename = f[0] + output_fullpath = os.path.join(args.output_dir, filename) + if os.path.exists(output_fullpath): + print("Deleting existing file: %s" % output_fullpath) + os.remove(output_fullpath) + + # Generate files from templates + for f in files: + filename = f[0] + event_header = f[1] curdir = os.path.dirname(os.path.abspath(__file__)) - template_file = os.sep.join([curdir, 'templates', 'gen_ar_event.hpp']) - output_fullpath = os.sep.join([output_dir, output_filename]) + template_file = os.path.join(curdir, 'templates', filename) + output_fullpath = os.path.join(args.output_dir, filename) + print("Generating: %s" % output_fullpath) MakoTemplateWriter.to_file(template_file, output_fullpath, cmdline=sys.argv, - filename=output_filename, - protos=protos) + filename=filename, + protos=protos, + event_header=event_header) - # Generate event implementation - if args.gen_event_cpp: - curdir = os.path.dirname(os.path.abspath(__file__)) - template_file = os.sep.join([curdir, 'templates', 'gen_ar_event.cpp']) - output_fullpath = os.sep.join([output_dir, output_filename]) - - MakoTemplateWriter.to_file(template_file, output_fullpath, - cmdline=sys.argv, - filename=output_filename, - protos=protos) - - # Generate event handler header - if args.gen_eventhandler_hpp: - curdir = os.path.dirname(os.path.abspath(__file__)) - template_file = os.sep.join([curdir, 'templates', 'gen_ar_eventhandler.hpp']) - output_fullpath = os.sep.join([output_dir, output_filename]) - - MakoTemplateWriter.to_file(template_file, output_fullpath, - cmdline=sys.argv, - filename=output_filename, - event_header='gen_ar_event.hpp', - protos=protos) - - # Generate event handler header - if args.gen_eventhandlerfile_hpp: - curdir = os.path.dirname(os.path.abspath(__file__)) - template_file = os.sep.join([curdir, 'templates', 'gen_ar_eventhandlerfile.hpp']) - output_fullpath = os.sep.join([output_dir, output_filename]) - - MakoTemplateWriter.to_file(template_file, output_fullpath, - cmdline=sys.argv, - filename=output_filename, - event_header='gen_ar_eventhandler.hpp', - protos=protos) - - rval = CopyDirFilesIfDifferent(output_dir, final_output_dir) - - except: + except Exception as e: + print(e) rval = 1 - finally: - DeleteDirTree(output_dir) - return rval if __name__ == '__main__': diff --git a/src/gallium/drivers/swr/rasterizer/codegen/meson.build b/src/gallium/drivers/swr/rasterizer/codegen/meson.build index 28275176022..98da7d3fc61 100644 --- a/src/gallium/drivers/swr/rasterizer/codegen/meson.build +++ b/src/gallium/drivers/swr/rasterizer/codegen/meson.build @@ -61,26 +61,16 @@ foreach x : [[swr_context_files, 'gen_swr_context_llvm.h'], ) endforeach -foreach x : [['gen_ar_event.hpp', '--gen_event_hpp'], - ['gen_ar_event.cpp', '--gen_event_cpp'], - ['gen_ar_eventhandler.hpp', '--gen_eventhandler_h'], - ['gen_ar_eventhandlerfile.hpp', '--gen_eventhandlerfile_h']] - files_swr_common += custom_target( - x[0], - input : ['gen_archrast.py', swr_event_proto_files, swr_event_pproto_files], - output : x[0], - command : [ - prog_python, - '@INPUT0@', - '--proto', '@INPUT1@', - '--proto_private', '@INPUT2@', - '--output', '@OUTPUT@', - x[1], - ], - depend_files : files( - join_paths('templates', x[0]), - 'gen_common.py', - ), - ) +ar_output_filenames = ['gen_ar_event.hpp', 'gen_ar_event.cpp', 'gen_ar_eventhandler.hpp', 'gen_ar_eventhandlerfile.hpp'] +ar_template_filenames = [] +foreach fname : ar_output_filenames + ar_template_filenames += join_paths('templates', fname) endforeach +files_swr_common += custom_target( + 'gen_archrast', + input : ['gen_archrast.py', swr_event_proto_files, swr_event_pproto_files], + output : ar_output_filenames, + command : [prog_python, '@INPUT0@', '--proto', '@INPUT1@', '@INPUT2@', '--output-dir', meson.current_build_dir()], + depend_files : files('gen_common.py', ar_template_filenames) +) |