OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 """MB - the Meta-Build wrapper around GYP and GN | 6 """MB - the Meta-Build wrapper around GYP and GN |
7 | 7 |
8 MB is a wrapper script for GYP and GN that can be used to generate build files | 8 MB is a wrapper script for GYP and GN that can be used to generate build files |
9 for sets of canned configurations and analyze them. | 9 for sets of canned configurations and analyze them. |
10 """ | 10 """ |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 path = self.args.path[0] | 613 path = self.args.path[0] |
614 | 614 |
615 output_dir = self.ParseGYPConfigPath(path) | 615 output_dir = self.ParseGYPConfigPath(path) |
616 cmd, env = self.GYPCmd(output_dir, vals) | 616 cmd, env = self.GYPCmd(output_dir, vals) |
617 ret, _, _ = self.Run(cmd, env=env) | 617 ret, _, _ = self.Run(cmd, env=env) |
618 return ret | 618 return ret |
619 | 619 |
620 def RunGYPAnalyze(self, vals): | 620 def RunGYPAnalyze(self, vals): |
621 output_dir = self.ParseGYPConfigPath(self.args.path[0]) | 621 output_dir = self.ParseGYPConfigPath(self.args.path[0]) |
622 if self.args.verbose: | 622 if self.args.verbose: |
623 inp = self.ReadInputJSON(['files']) | 623 inp = self.ReadInputJSON(['files', 'test_targets', |
| 624 'additional_compile_targets']) |
624 self.Print() | 625 self.Print() |
625 self.Print('analyze input:') | 626 self.Print('analyze input:') |
626 self.PrintJSON(inp) | 627 self.PrintJSON(inp) |
627 self.Print() | 628 self.Print() |
628 | 629 |
629 cmd, env = self.GYPCmd(output_dir, vals) | 630 cmd, env = self.GYPCmd(output_dir, vals) |
630 cmd.extend(['-f', 'analyzer', | 631 cmd.extend(['-f', 'analyzer', |
631 '-G', 'config_path=%s' % self.args.input_path[0], | 632 '-G', 'config_path=%s' % self.args.input_path[0], |
632 '-G', 'analyzer_output_path=%s' % self.args.output_path[0]]) | 633 '-G', 'analyzer_output_path=%s' % self.args.output_path[0]]) |
633 ret, _, _ = self.Run(cmd, env=env) | 634 ret, _, _ = self.Run(cmd, env=env) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 env['GYP_CROSSCOMPILE'] = '1' | 767 env['GYP_CROSSCOMPILE'] = '1' |
767 return cmd, env | 768 return cmd, env |
768 | 769 |
769 def RunGNAnalyze(self, vals): | 770 def RunGNAnalyze(self, vals): |
770 # analyze runs before 'gn gen' now, so we need to run gn gen | 771 # analyze runs before 'gn gen' now, so we need to run gn gen |
771 # in order to ensure that we have a build directory. | 772 # in order to ensure that we have a build directory. |
772 ret = self.RunGNGen(vals) | 773 ret = self.RunGNGen(vals) |
773 if ret: | 774 if ret: |
774 return ret | 775 return ret |
775 | 776 |
776 # TODO(dpranke): add 'test_targets' and 'additional_compile_targets' | 777 inp = self.ReadInputJSON(['files', 'test_targets', |
777 # as required keys once the recipe has been converted over. | 778 'additional_compile_targets']) |
778 # See crbug.com/552146. | |
779 inp = self.ReadInputJSON(['files']) | |
780 if self.args.verbose: | 779 if self.args.verbose: |
781 self.Print() | 780 self.Print() |
782 self.Print('analyze input:') | 781 self.Print('analyze input:') |
783 self.PrintJSON(inp) | 782 self.PrintJSON(inp) |
784 self.Print() | 783 self.Print() |
785 | 784 |
786 use_new_logic = ('test_targets' in inp and | 785 # TODO(crbug.com/555273) - currently GN treats targets and |
787 'additional_compile_targets' in inp) | 786 # additional_compile_targets identically since we can't tell the |
788 if use_new_logic: | 787 # difference between a target that is a group in GN and one that isn't. |
789 # TODO(crbug.com/555273) - currently GN treats targets and | 788 # We should eventually fix this and treat the two types differently. |
790 # additional_compile_targets identically since we can't tell the | 789 targets = (set(inp['test_targets']) | |
791 # difference between a target that is a group in GN and one that isn't. | 790 set(inp['additional_compile_targets'])) |
792 # We should eventually fix this and treat the two types differently. | |
793 targets = (set(inp['test_targets']) | | |
794 set(inp['additional_compile_targets'])) | |
795 else: | |
796 targets = set(inp['targets']) | |
797 | 791 |
798 output_path = self.args.output_path[0] | 792 output_path = self.args.output_path[0] |
799 | 793 |
800 # Bail out early if a GN file was modified, since 'gn refs' won't know | 794 # Bail out early if a GN file was modified, since 'gn refs' won't know |
801 # what to do about it. Also, bail out early if 'all' was asked for, | 795 # what to do about it. Also, bail out early if 'all' was asked for, |
802 # since we can't deal with it yet. | 796 # since we can't deal with it yet. |
803 if (any(f.endswith('.gn') or f.endswith('.gni') for f in inp['files']) or | 797 if (any(f.endswith('.gn') or f.endswith('.gni') for f in inp['files']) or |
804 'all' in targets): | 798 'all' in targets): |
805 if use_new_logic: | 799 self.WriteJSON({ |
806 self.WriteJSON({ | 800 'status': 'Found dependency (all)', |
807 'status': 'Found dependency (all)', | 801 'compile_targets': sorted(targets), |
808 'compile_targets': sorted(targets), | 802 'test_targets': sorted(targets & set(inp['test_targets'])), |
809 'test_targets': sorted(targets & set(inp['test_targets'])), | 803 }, output_path) |
810 }, output_path) | |
811 else: | |
812 self.WriteJSON({'status': 'Found dependency (all)'}, output_path) | |
813 return 0 | 804 return 0 |
814 | 805 |
815 # This shouldn't normally happen, but could due to unusual race conditions, | 806 # This shouldn't normally happen, but could due to unusual race conditions, |
816 # like a try job that gets scheduled before a patch lands but runs after | 807 # like a try job that gets scheduled before a patch lands but runs after |
817 # the patch has landed. | 808 # the patch has landed. |
818 if not inp['files']: | 809 if not inp['files']: |
819 self.Print('Warning: No files modified in patch, bailing out early.') | 810 self.Print('Warning: No files modified in patch, bailing out early.') |
820 if use_new_logic: | 811 self.WriteJSON({ |
821 self.WriteJSON({ | 812 'status': 'No dependency', |
822 'status': 'No dependency', | 813 'compile_targets': [], |
823 'compile_targets': [], | 814 'test_targets': [], |
824 'test_targets': [], | 815 }, output_path) |
825 }, output_path) | |
826 else: | |
827 self.WriteJSON({ | |
828 'status': 'No dependency', | |
829 'targets': [], | |
830 'build_targets': [], | |
831 }, output_path) | |
832 return 0 | 816 return 0 |
833 | 817 |
834 ret = 0 | 818 ret = 0 |
835 response_file = self.TempFile() | 819 response_file = self.TempFile() |
836 response_file.write('\n'.join(inp['files']) + '\n') | 820 response_file.write('\n'.join(inp['files']) + '\n') |
837 response_file.close() | 821 response_file.close() |
838 | 822 |
839 matching_targets = set() | 823 matching_targets = set() |
840 try: | 824 try: |
841 cmd = self.GNCmd('refs', self.args.path[0]) + [ | 825 cmd = self.GNCmd('refs', self.args.path[0]) + [ |
(...skipping 20 matching lines...) Expand all Loading... |
862 # just 'chrome_public_apk'. This may result in too many targets | 846 # just 'chrome_public_apk'. This may result in too many targets |
863 # getting built, but we can adjust that later if need be. | 847 # getting built, but we can adjust that later if need be. |
864 for input_target in targets: | 848 for input_target in targets: |
865 if (input_target == build_target or | 849 if (input_target == build_target or |
866 build_target.endswith(':' + input_target)): | 850 build_target.endswith(':' + input_target)): |
867 matching_targets.add(input_target) | 851 matching_targets.add(input_target) |
868 finally: | 852 finally: |
869 self.RemoveFile(response_file.name) | 853 self.RemoveFile(response_file.name) |
870 | 854 |
871 if matching_targets: | 855 if matching_targets: |
872 if use_new_logic: | 856 self.WriteJSON({ |
873 self.WriteJSON({ | |
874 'status': 'Found dependency', | |
875 'compile_targets': sorted(matching_targets), | |
876 'test_targets': sorted(matching_targets & | |
877 set(inp['test_targets'])), | |
878 }, output_path) | |
879 else: | |
880 self.WriteJSON({ | |
881 'status': 'Found dependency', | 857 'status': 'Found dependency', |
882 'targets': sorted(matching_targets), | 858 'compile_targets': sorted(matching_targets), |
883 'build_targets': sorted(matching_targets), | 859 'test_targets': sorted(matching_targets & |
884 }, output_path) | 860 set(inp['test_targets'])), |
| 861 }, output_path) |
885 else: | 862 else: |
886 if use_new_logic: | 863 self.WriteJSON({ |
887 self.WriteJSON({ | 864 'status': 'No dependency', |
888 'status': 'No dependency', | 865 'compile_targets': [], |
889 'compile_targets': [], | 866 'test_targets': [], |
890 'test_targets': [], | 867 }, output_path) |
891 }, output_path) | |
892 else: | |
893 self.WriteJSON({ | |
894 'status': 'No dependency', | |
895 'targets': [], | |
896 'build_targets': [], | |
897 }, output_path) | |
898 | 868 |
899 if self.args.verbose: | 869 if self.args.verbose: |
900 outp = json.loads(self.ReadFile(output_path)) | 870 outp = json.loads(self.ReadFile(output_path)) |
901 self.Print() | 871 self.Print() |
902 self.Print('analyze output:') | 872 self.Print('analyze output:') |
903 self.PrintJSON(outp) | 873 self.PrintJSON(outp) |
904 self.Print() | 874 self.Print() |
905 | 875 |
906 return 0 | 876 return 0 |
907 | 877 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 | 1060 |
1091 if __name__ == '__main__': | 1061 if __name__ == '__main__': |
1092 try: | 1062 try: |
1093 sys.exit(main(sys.argv[1:])) | 1063 sys.exit(main(sys.argv[1:])) |
1094 except MBErr as e: | 1064 except MBErr as e: |
1095 print(e) | 1065 print(e) |
1096 sys.exit(1) | 1066 sys.exit(1) |
1097 except KeyboardInterrupt: | 1067 except KeyboardInterrupt: |
1098 print("interrupted, exiting", stream=sys.stderr) | 1068 print("interrupted, exiting", stream=sys.stderr) |
1099 sys.exit(130) | 1069 sys.exit(130) |
OLD | NEW |