swr/rast: Cleanup and generalize gen_archrast
Update meson.build to accomodate Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
This commit is contained in:
parent
0bd45f96b9
commit
93cd9905c8
|
@ -116,37 +116,17 @@ def main():
|
||||||
|
|
||||||
# Parse args...
|
# Parse args...
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
parser.add_argument('--proto', '-p', help='Path to proto file', required=True)
|
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('--proto_private', '-pp', help='Path to private proto file', 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')
|
||||||
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)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
proto_filename = args.proto
|
if not os.path.exists(args.output_dir):
|
||||||
proto_private_filename = args.proto_private
|
MakeDir(args.output_dir)
|
||||||
|
|
||||||
(output_dir, output_filename) = os.path.split(args.output)
|
for f in args.protos:
|
||||||
|
if not os.path.exists(f):
|
||||||
if not output_dir:
|
print('Error: Could not find proto file %s' % f, file=sys.stderr)
|
||||||
output_dir = '.'
|
return 1
|
||||||
|
|
||||||
#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')
|
|
||||||
|
|
||||||
protos = {}
|
protos = {}
|
||||||
protos['events'] = {} # event dictionary containing events with their fields
|
protos['events'] = {} # event dictionary containing events with their fields
|
||||||
|
@ -154,66 +134,48 @@ def main():
|
||||||
protos['enums'] = {}
|
protos['enums'] = {}
|
||||||
protos['enum_names'] = []
|
protos['enum_names'] = []
|
||||||
|
|
||||||
parse_protos(protos, proto_filename)
|
# Parse each proto file and add to protos container
|
||||||
parse_protos(protos, proto_private_filename)
|
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
|
rval = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Generate event header
|
# Delete existing files
|
||||||
if args.gen_event_hpp:
|
for f in files:
|
||||||
curdir = os.path.dirname(os.path.abspath(__file__))
|
filename = f[0]
|
||||||
template_file = os.sep.join([curdir, 'templates', 'gen_ar_event.hpp'])
|
output_fullpath = os.path.join(args.output_dir, filename)
|
||||||
output_fullpath = os.sep.join([output_dir, output_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.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,
|
MakoTemplateWriter.to_file(template_file, output_fullpath,
|
||||||
cmdline=sys.argv,
|
cmdline=sys.argv,
|
||||||
filename=output_filename,
|
filename=filename,
|
||||||
protos=protos)
|
protos=protos,
|
||||||
|
event_header=event_header)
|
||||||
|
|
||||||
# Generate event implementation
|
except Exception as e:
|
||||||
if args.gen_event_cpp:
|
print(e)
|
||||||
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:
|
|
||||||
rval = 1
|
rval = 1
|
||||||
|
|
||||||
finally:
|
|
||||||
DeleteDirTree(output_dir)
|
|
||||||
|
|
||||||
return rval
|
return rval
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -72,10 +72,8 @@ foreach x : [['gen_ar_event.hpp', '--gen_event_hpp'],
|
||||||
command : [
|
command : [
|
||||||
prog_python,
|
prog_python,
|
||||||
'@INPUT0@',
|
'@INPUT0@',
|
||||||
'--proto', '@INPUT1@',
|
'--proto', '@INPUT1@', '@INPUT2@',
|
||||||
'--proto_private', '@INPUT2@',
|
'--output-dir', 'src/gallium/drivers/swr/rasterizer/codegen'
|
||||||
'--output', '@OUTPUT@',
|
|
||||||
x[1],
|
|
||||||
],
|
],
|
||||||
depend_files : files(
|
depend_files : files(
|
||||||
join_paths('templates', x[0]),
|
join_paths('templates', x[0]),
|
||||||
|
|
Loading…
Reference in New Issue