Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: gpu/config/process_json.py

Issue 2812003006: Move gpu jason file data generation to build time. (Closed)
Patch Set: remove git-format from build time generated files Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2017 The Chromium Authors. All rights reserved. 2 # Copyright 2017 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import os 7 import os
8 import platform 8 import platform
9 import sys 9 import sys
10 from optparse import OptionParser
10 from subprocess import call 11 from subprocess import call
11 12
12 """Generate data struct from GPU blacklist and driver bug workarounds json.""" 13 """Generate data struct from GPU blacklist and driver bug workarounds json."""
13 14
14 _LICENSE = """// Copyright 2017 The Chromium Authors. All rights reserved. 15 _LICENSE = """// Copyright 2017 The Chromium Authors. All rights reserved.
15 // Use of this source code is governed by a BSD-style license that can be 16 // Use of this source code is governed by a BSD-style license that can be
16 // found in the LICENSE file. 17 // found in the LICENSE file.
17 18
18 """ 19 """
19 20
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 571
571 def write_header_file_guard(file, filename, path, begin): 572 def write_header_file_guard(file, filename, path, begin):
572 token = (path.upper().replace('/', '_') + '_' + 573 token = (path.upper().replace('/', '_') + '_' +
573 filename.upper().replace('.', '_') + '_') 574 filename.upper().replace('.', '_') + '_')
574 if begin: 575 if begin:
575 file.write('#ifndef %s\n#define %s\n\n' % (token, token)) 576 file.write('#ifndef %s\n#define %s\n\n' % (token, token))
576 else: 577 else:
577 file.write('\n#endif // %s\n' % token) 578 file.write('\n#endif // %s\n' % token)
578 579
579 580
580 def process_json_file(json_filename, list_tag, 581 def process_json_file(json_filepath, list_tag,
581 feature_header_filename, total_features, feature_tag, 582 feature_header_filename, total_features, feature_tag,
582 output_header_filename, output_data_filename, 583 output_header_filepath, output_data_filepath,
583 output_helper_filename, output_exception_filename, path, 584 output_helper_filepath, output_exception_filepath, path,
584 export_tag): 585 export_tag, git_format):
585 current_dir = os.getcwd() 586 output_header_filename = os.path.basename(output_header_filepath)
586 os.chdir('../../' + path) # assume python script is under gpu/config 587 output_helper_filename = os.path.basename(output_helper_filepath)
587 588 output_exception_filename = os.path.basename(output_exception_filepath)
588 json_file = open(json_filename, 'rb') 589 json_file = open(json_filepath, 'rb')
589 json_data = json.load(json_file) 590 json_data = json.load(json_file)
590 json_file.close() 591 json_file.close()
591 data_file = open(output_data_filename, 'wb') 592 data_file = open(output_data_filepath, 'wb')
592 data_file.write(_LICENSE) 593 data_file.write(_LICENSE)
593 data_file.write(_DO_NOT_EDIT_WARNING) 594 data_file.write(_DO_NOT_EDIT_WARNING)
594 data_file.write('#include "%s/%s"\n\n' % (path, output_header_filename)) 595 data_file.write('#include "%s/%s"\n\n' % (path, output_header_filename))
595 data_file.write('#include "%s/%s"\n' % (path, output_helper_filename)) 596 data_file.write('#include "%s/%s"\n' % (path, output_helper_filename))
596 data_file.write('#include "%s/%s"\n\n' % (path, output_exception_filename)) 597 data_file.write('#include "%s/%s"\n\n' % (path, output_exception_filename))
597 data_helper_file = open(output_helper_filename, 'wb') 598 data_helper_file = open(output_helper_filepath, 'wb')
598 data_helper_file.write(_LICENSE) 599 data_helper_file.write(_LICENSE)
599 data_helper_file.write(_DO_NOT_EDIT_WARNING) 600 data_helper_file.write(_DO_NOT_EDIT_WARNING)
600 write_header_file_guard(data_helper_file, output_helper_filename, path, True) 601 write_header_file_guard(data_helper_file, output_helper_filename, path, True)
601 data_helper_file.write('#include "gpu/config/%s"\n\n' % 602 data_helper_file.write('#include "gpu/config/%s"\n\n' %
602 feature_header_filename) 603 feature_header_filename)
603 data_helper_file.write('namespace gpu {\n') 604 data_helper_file.write('namespace gpu {\n')
604 data_exception_file = open(output_exception_filename, 'wb') 605 data_exception_file = open(output_exception_filepath, 'wb')
605 data_exception_file.write(_LICENSE) 606 data_exception_file.write(_LICENSE)
606 data_exception_file.write(_DO_NOT_EDIT_WARNING) 607 data_exception_file.write(_DO_NOT_EDIT_WARNING)
607 write_header_file_guard(data_exception_file, output_exception_filename, path, 608 write_header_file_guard(data_exception_file, output_exception_filename, path,
608 True) 609 True)
609 data_exception_file.write('namespace gpu {\n') 610 data_exception_file.write('namespace gpu {\n')
610 data_file.write('namespace gpu {\n\n') 611 data_file.write('namespace gpu {\n\n')
611 data_file.write('const char k%sVersion[] = "%s";\n\n' % 612 data_file.write('const char k%sVersion[] = "%s";\n\n' %
612 (list_tag, json_data['version'])) 613 (list_tag, json_data['version']))
613 entry_count = len(json_data['entries']) 614 entry_count = len(json_data['entries'])
614 data_file.write('const size_t k%sEntryCount = %d;\n' % 615 data_file.write('const size_t k%sEntryCount = %d;\n' %
(...skipping 11 matching lines...) Expand all
626 data_file.write('};\n') 627 data_file.write('};\n')
627 data_file.write('} // namespace gpu\n') 628 data_file.write('} // namespace gpu\n')
628 data_file.close() 629 data_file.close()
629 data_helper_file.write('} // namespace gpu\n') 630 data_helper_file.write('} // namespace gpu\n')
630 write_header_file_guard(data_helper_file, output_helper_filename, path, False) 631 write_header_file_guard(data_helper_file, output_helper_filename, path, False)
631 data_helper_file.close() 632 data_helper_file.close()
632 data_exception_file.write('} // namespace gpu\n') 633 data_exception_file.write('} // namespace gpu\n')
633 write_header_file_guard(data_exception_file, output_exception_filename, path, 634 write_header_file_guard(data_exception_file, output_exception_filename, path,
634 False) 635 False)
635 data_exception_file.close() 636 data_exception_file.close()
636 data_header_file = open(output_header_filename, 'wb') 637 data_header_file = open(output_header_filepath, 'wb')
637 data_header_file.write(_LICENSE) 638 data_header_file.write(_LICENSE)
638 data_header_file.write(_DO_NOT_EDIT_WARNING) 639 data_header_file.write(_DO_NOT_EDIT_WARNING)
639 write_header_file_guard(data_header_file, output_header_filename, path, True) 640 write_header_file_guard(data_header_file, output_header_filename, path, True)
640 if export_tag == 'CONTENT_EXPORT ': 641 if export_tag == 'CONTENT_EXPORT ':
641 data_header_file.write('#include "content/common/content_export.h"\n') 642 data_header_file.write('#include "content/common/content_export.h"\n')
642 data_header_file.write('#include "gpu/config/gpu_control_list.h"\n\n') 643 data_header_file.write('#include "gpu/config/gpu_control_list.h"\n\n')
643 data_header_file.write('\n') 644 data_header_file.write('\n')
644 data_header_file.write('namespace gpu {\n') 645 data_header_file.write('namespace gpu {\n')
645 data_header_file.write('%sextern const char k%sVersion[];\n' % 646 data_header_file.write('%sextern const char k%sVersion[];\n' %
646 (export_tag, list_tag)) 647 (export_tag, list_tag))
647 data_header_file.write('%sextern const size_t k%sEntryCount;\n' % 648 data_header_file.write('%sextern const size_t k%sEntryCount;\n' %
648 (export_tag, list_tag)) 649 (export_tag, list_tag))
649 data_header_file.write( 650 data_header_file.write(
650 '%sextern const GpuControlList::Entry k%sEntries[];\n' % 651 '%sextern const GpuControlList::Entry k%sEntries[];\n' %
651 (export_tag, list_tag)) 652 (export_tag, list_tag))
652 data_header_file.write('} // namespace gpu\n') 653 data_header_file.write('} // namespace gpu\n')
653 write_header_file_guard(data_header_file, output_header_filename, path, False) 654 write_header_file_guard(data_header_file, output_header_filename, path, False)
654 data_header_file.close() 655 data_header_file.close()
655 format_files([output_header_filename, output_data_filename, 656 if git_format:
656 output_helper_filename, output_exception_filename]) 657 format_files([output_header_filepath, output_data_filepath,
657 658 output_helper_filepath, output_exception_filepath])
658 os.chdir(current_dir)
659 659
660 660
661 def process_software_rendering_list(): 661 def process_software_rendering_list(script_dir, output_dir):
662 total_features = load_software_rendering_list_features('gpu_feature_type.h') 662 total_features = load_software_rendering_list_features(
663 process_json_file('software_rendering_list.json', 'SoftwareRenderingList', 663 os.path.join(script_dir, 'gpu_feature_type.h'))
664 'gpu_feature_type.h', total_features, 'GPU_FEATURE_TYPE_', 664 process_json_file(
665 'software_rendering_list_autogen.h', 665 os.path.join(script_dir, 'software_rendering_list.json'),
666 'software_rendering_list_autogen.cc', 666 'SoftwareRenderingList',
667 'software_rendering_list_arrays_and_structs_autogen.h', 667 'gpu_feature_type.h',
668 'software_rendering_list_exceptions_autogen.h', 668 total_features,
669 'gpu/config', 'GPU_EXPORT ') 669 'GPU_FEATURE_TYPE_',
670 os.path.join(output_dir, 'software_rendering_list_autogen.h'),
671 os.path.join(output_dir, 'software_rendering_list_autogen.cc'),
672 os.path.join(output_dir,
673 'software_rendering_list_arrays_and_structs_autogen.h'),
674 os.path.join(output_dir, 'software_rendering_list_exceptions_autogen.h'),
675 'gpu/config',
676 'GPU_EXPORT ',
677 False)
670 678
671 679
672 def process_gpu_driver_bug_list(): 680 def process_gpu_driver_bug_list(script_dir, output_dir):
673 total_features = load_gpu_driver_bug_workarounds( 681 total_features = load_gpu_driver_bug_workarounds(
674 'gpu_driver_bug_workaround_type.h') 682 os.path.join(script_dir, 'gpu_driver_bug_workaround_type.h'))
675 process_json_file('gpu_driver_bug_list.json', 'GpuDriverBugList', 683 process_json_file(
676 'gpu_driver_bug_workaround_type.h', total_features, '', 684 os.path.join(script_dir, 'gpu_driver_bug_list.json'),
677 'gpu_driver_bug_list_autogen.h', 685 'GpuDriverBugList',
678 'gpu_driver_bug_list_autogen.cc', 686 'gpu_driver_bug_workaround_type.h',
679 'gpu_driver_bug_list_arrays_and_structs_autogen.h', 687 total_features,
680 'gpu_driver_bug_list_exceptions_autogen.h', 688 '',
681 'gpu/config', 'GPU_EXPORT ') 689 os.path.join(output_dir, 'gpu_driver_bug_list_autogen.h'),
690 os.path.join(output_dir, 'gpu_driver_bug_list_autogen.cc'),
691 os.path.join(output_dir,
692 'gpu_driver_bug_list_arrays_and_structs_autogen.h'),
693 os.path.join(output_dir, 'gpu_driver_bug_list_exceptions_autogen.h'),
694 'gpu/config',
695 'GPU_EXPORT ',
696 False)
682 697
683 698
684 def process_gpu_control_list_testing(): 699 def process_gpu_control_list_testing(script_dir, output_dir):
685 total_features = ['test_feature_0', 'test_feature_1', 'test_feature_2'] 700 total_features = ['test_feature_0', 'test_feature_1', 'test_feature_2']
686 process_json_file('gpu_control_list_testing.json', 'GpuControlListTesting', 701 process_json_file(
687 'gpu_control_list_testing_data.h', total_features, '', 702 os.path.join(script_dir, 'gpu_control_list_testing.json'),
688 'gpu_control_list_testing_autogen.h', 703 'GpuControlListTesting',
689 'gpu_control_list_testing_autogen.cc', 704 'gpu_control_list_testing_data.h',
690 'gpu_control_list_testing_arrays_and_structs_autogen.h', 705 total_features,
691 'gpu_control_list_testing_exceptions_autogen.h', 706 '',
692 'gpu/config', '') 707 os.path.join(output_dir, 'gpu_control_list_testing_autogen.h'),
708 os.path.join(output_dir, 'gpu_control_list_testing_autogen.cc'),
709 os.path.join(output_dir,
710 'gpu_control_list_testing_arrays_and_structs_autogen.h'),
711 os.path.join(output_dir, 'gpu_control_list_testing_exceptions_autogen.h'),
712 'gpu/config',
713 '',
714 True)
693 715
694 716
695 def process_gpu_data_manager_testing(): 717 def process_gpu_data_manager_testing(script_dir, output_dir):
696 total_features = load_software_rendering_list_features('gpu_feature_type.h') 718 total_features = load_software_rendering_list_features(
697 process_json_file('gpu_data_manager_testing.json', 'GpuDataManagerTesting', 719 os.path.join(script_dir, 'gpu_feature_type.h'))
698 'gpu_feature_type.h', total_features, 'GPU_FEATURE_TYPE_', 720 process_json_file(
699 'gpu_data_manager_testing_autogen.h', 721 os.path.join(output_dir, 'gpu_data_manager_testing.json'),
700 'gpu_data_manager_testing_autogen.cc', 722 'GpuDataManagerTesting',
701 'gpu_data_manager_testing_arrays_and_structs_autogen.h', 723 'gpu_feature_type.h',
702 'gpu_data_manager_testing_exceptions_autogen.h', 724 total_features,
703 'content/browser/gpu', '') 725 'GPU_FEATURE_TYPE_',
726 os.path.join(output_dir, 'gpu_data_manager_testing_autogen.h'),
727 os.path.join(output_dir, 'gpu_data_manager_testing_autogen.cc'),
728 os.path.join(output_dir,
729 'gpu_data_manager_testing_arrays_and_structs_autogen.h'),
730 os.path.join(output_dir, 'gpu_data_manager_testing_exceptions_autogen.h'),
731 'content/browser/gpu',
732 '',
733 True)
704 734
705 735
706 def write_test_entry_enums(input_json_filename, output_entry_enums_filename, 736 def write_test_entry_enums(input_json_filepath, output_entry_enums_filepath,
707 path, list_tag): 737 path, list_tag):
708 current_dir = os.getcwd() 738 json_file = open(input_json_filepath, 'rb')
709 os.chdir('../../' + path) # assume python script is under gou/config
710
711 json_file = open(input_json_filename, 'rb')
712 json_data = json.load(json_file) 739 json_data = json.load(json_file)
713 json_file.close() 740 json_file.close()
714 741
715 enum_file = open(output_entry_enums_filename, 'wb') 742 output_entry_enums_filename = os.path.basename(output_entry_enums_filepath)
743 enum_file = open(output_entry_enums_filepath, 'wb')
716 enum_file.write(_LICENSE) 744 enum_file.write(_LICENSE)
717 enum_file.write(_DO_NOT_EDIT_WARNING) 745 enum_file.write(_DO_NOT_EDIT_WARNING)
718 write_header_file_guard(enum_file, output_entry_enums_filename, path, True) 746 write_header_file_guard(enum_file, output_entry_enums_filename, path, True)
719 enum_file.write('namespace gpu {\n') 747 enum_file.write('namespace gpu {\n')
720 enum_file.write('enum %sEntryEnum {\n' % list_tag) 748 enum_file.write('enum %sEntryEnum {\n' % list_tag)
721 entry_count = len(json_data['entries']) 749 entry_count = len(json_data['entries'])
722 for index in range(entry_count): 750 for index in range(entry_count):
723 entry = json_data['entries'][index] 751 entry = json_data['entries'][index]
724 entry_id = entry['id'] 752 entry_id = entry['id']
725 description = entry['description'] 753 description = entry['description']
726 assert(index + 1 == int(entry_id)) 754 assert(index + 1 == int(entry_id))
727 description = 'k' + description 755 description = 'k' + description
728 description = description.replace('.', '_') 756 description = description.replace('.', '_')
729 enum_file.write(' %s = %d,\n' % (description, index)) 757 enum_file.write(' %s = %d,\n' % (description, index))
730 enum_file.write('};\n') 758 enum_file.write('};\n')
731 enum_file.write('} // namespace gpu\n') 759 enum_file.write('} // namespace gpu\n')
732 write_header_file_guard(enum_file, output_entry_enums_filename, path, False) 760 write_header_file_guard(enum_file, output_entry_enums_filename, path, False)
733 enum_file.close() 761 enum_file.close()
734 format_files([output_entry_enums_filename]) 762 format_files([output_entry_enums_filepath])
735
736 os.chdir(current_dir)
737 763
738 764
739 def main(): 765 def main(argv):
740 dir_path = os.path.dirname(os.path.realpath(__file__)) 766 parser = OptionParser()
741 os.chdir(dir_path) 767 parser.add_option("--output-dir",
742 process_software_rendering_list() 768 help="output directory for SoftwareRenderingList and "
743 process_gpu_driver_bug_list() 769 "GpuDriverBugList data files. "
744 process_gpu_control_list_testing() 770 "If unspecified, these files are not generated.")
745 write_test_entry_enums('gpu_control_list_testing.json', 771 parser.add_option("--skip-testing-data", action="store_false",
746 'gpu_control_list_testing_entry_enums_autogen.h', 772 dest="generate_testing_data", default=True,
747 'gpu/config', 773 help="skip testing data generation.")
748 'GpuControlListTesting') 774 (options, args) = parser.parse_args(args=argv)
749 process_gpu_data_manager_testing() 775
750 write_test_entry_enums('gpu_data_manager_testing.json', 776 script_dir = os.path.dirname(os.path.realpath(__file__))
751 'gpu_data_manager_testing_entry_enums_autogen.h', 777
752 'content/browser/gpu', 778 if options.output_dir != None:
753 'GpuDataManagerTesting') 779 process_software_rendering_list(script_dir, options.output_dir)
780 process_gpu_driver_bug_list(script_dir, options.output_dir)
781
782 if options.generate_testing_data:
783 # Testing data files are generated by calling the script manually.
784 process_gpu_control_list_testing(script_dir, script_dir)
785 write_test_entry_enums(
786 os.path.join(script_dir, 'gpu_control_list_testing.json'),
787 os.path.join(script_dir,
788 'gpu_control_list_testing_entry_enums_autogen.h'),
789 'gpu/config',
790 'GpuControlListTesting')
791 chrome_root_dir = os.path.abspath(os.path.join(script_dir, '../../'))
792 gpu_data_manager_dir = os.path.join(chrome_root_dir, 'content/browser/gpu')
793 process_gpu_data_manager_testing(script_dir, gpu_data_manager_dir)
794 write_test_entry_enums(
795 os.path.join(gpu_data_manager_dir, 'gpu_data_manager_testing.json'),
796 os.path.join(gpu_data_manager_dir,
797 'gpu_data_manager_testing_entry_enums_autogen.h'),
798 'content/browser/gpu',
799 'GpuDataManagerTesting')
754 800
755 801
756 if __name__ == '__main__': 802 if __name__ == '__main__':
757 sys.exit(main()) 803 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « gpu/config/gpu_driver_bug_list_exceptions_autogen.h ('k') | gpu/config/software_rendering_list_arrays_and_structs_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698