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

Side by Side Diff: tools/gn/bin/gyp_flag_compare.py

Issue 533413002: Group flag comparison output by file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Given the output of -t commands from a ninja build for a gyp and GN generated 7 """Given the output of -t commands from a ninja build for a gyp and GN generated
8 build, report on differences between the command lines.""" 8 build, report on differences between the command lines."""
9 9
10 10
11 import sys 11 import sys
12 12
13 13
14 def FindAndRemoveArgWithValue(command_line, argname): 14 def FindAndRemoveArgWithValue(command_line, argname):
15 """Given a command line as a list, remove and return the value of an option 15 """Given a command line as a list, remove and return the value of an option
16 that takes a value as a separate entry. 16 that takes a value as a separate entry.
17 17
18 Modifies |command_line| in place. 18 Modifies |command_line| in place.
19 """ 19 """
20 if argname not in command_line:
21 return ''
20 location = command_line.index(argname) 22 location = command_line.index(argname)
21 value = command_line[location + 1] 23 value = command_line[location + 1]
22 command_line[location:location + 2] = [] 24 command_line[location:location + 2] = []
23 return value 25 return value
24 26
25 27
26 def MergeSpacedArgs(command_line, argname): 28 def MergeSpacedArgs(command_line, argname):
27 """Combine all arguments |argname| with their values, separated by a space.""" 29 """Combine all arguments |argname| with their values, separated by a space."""
28 i = 0 30 i = 0
29 result = [] 31 result = []
(...skipping 21 matching lines...) Expand all
51 53
52 output_name = FindAndRemoveArgWithValue(command_line, '-o') 54 output_name = FindAndRemoveArgWithValue(command_line, '-o')
53 dep_name = FindAndRemoveArgWithValue(command_line, '-MF') 55 dep_name = FindAndRemoveArgWithValue(command_line, '-MF')
54 56
55 command_line = MergeSpacedArgs(command_line, '-Xclang') 57 command_line = MergeSpacedArgs(command_line, '-Xclang')
56 58
57 defines = [x for x in command_line if x.startswith('-D')] 59 defines = [x for x in command_line if x.startswith('-D')]
58 include_dirs = [x for x in command_line if x.startswith('-I')] 60 include_dirs = [x for x in command_line if x.startswith('-I')]
59 dash_f = [x for x in command_line if x.startswith('-f')] 61 dash_f = [x for x in command_line if x.startswith('-f')]
60 warnings = [x for x in command_line if x.startswith('-W')] 62 warnings = [x for x in command_line if x.startswith('-W')]
61 cc_file = [x for x in command_line if x.endswith('.cc') or x.endswith('.c')] 63 cc_file = [x for x in command_line if x.endswith('.cc') or
64 x.endswith('.c') or
65 x.endswith('.cpp')]
66 if len(cc_file) != 1:
67 print 'Skipping %s' % command_line
68 continue
62 assert len(cc_file) == 1 69 assert len(cc_file) == 1
63 others = [x for x in command_line if x not in defines and \ 70 others = [x for x in command_line if x not in defines and \
64 x not in include_dirs and \ 71 x not in include_dirs and \
65 x not in dash_f and \ 72 x not in dash_f and \
66 x not in warnings and \ 73 x not in warnings and \
67 x not in cc_file] 74 x not in cc_file]
68 flags_by_output[cc_file[0]] = { 75 flags_by_output[cc_file[0]] = {
69 'output': output_name, 76 'output': output_name,
70 'depname': dep_name, 77 'depname': dep_name,
71 'defines': sorted(defines), 78 'defines': sorted(defines),
72 'include_dirs': sorted(include_dirs), # TODO(scottmg): This is wrong. 79 'include_dirs': sorted(include_dirs), # TODO(scottmg): This is wrong.
73 'dash_f': sorted(dash_f), 80 'dash_f': sorted(dash_f),
74 'warnings': sorted(warnings), 81 'warnings': sorted(warnings),
75 'other': sorted(others), 82 'other': sorted(others),
76 } 83 }
77 return flags_by_output 84 return flags_by_output
78 85
79 86
80 def CompareLists(gyp, gn, name, dont_care=None): 87 def CompareLists(gyp, gn, name, dont_care=None):
81 """Output any differences between to lists, ignoring anything in 88 """Return a report of any differences between two lists, ignoring anything
82 |dont_care|.""" 89 in |dont_care|."""
83 if not dont_care: 90 if not dont_care:
84 dont_care = [] 91 dont_care = []
92 output = ''
85 if gyp[name] != gn[name]: 93 if gyp[name] != gn[name]:
86 print ' %s differ:' % name 94 output += ' %s differ:\n' % name
87 gyp_set = set(gyp[name]) - set(dont_care) 95 gyp_set = set(gyp[name]) - set(dont_care)
88 gn_set = set(gn[name]) - set(dont_care) 96 gn_set = set(gn[name]) - set(dont_care)
89 print ' In gyp, but not in GN:\n %s' % '\n '.join( 97 output += ' In gyp, but not in GN:\n %s' % '\n '.join(
90 sorted(gyp_set - gn_set)) 98 sorted(gyp_set - gn_set)) + '\n'
91 print ' In GN, but not in gyp:\n %s' % '\n '.join( 99 output += ' In GN, but not in gyp:\n %s' % '\n '.join(
92 sorted(gn_set - gyp_set)) 100 sorted(gn_set - gyp_set)) + '\n\n'
93 print 101 return output
94 return True
95 return False
96 102
97 103
98 def main(): 104 def main():
99 if len(sys.argv) != 3: 105 if len(sys.argv) != 3:
100 print 'usage: %s gyp_commands.txt gn_commands.txt' % __file__ 106 print 'usage: %s gyp_commands.txt gn_commands.txt' % __file__
101 return 1 107 return 1
102 with open(sys.argv[1], 'rb') as f: 108 with open(sys.argv[1], 'rb') as f:
103 gyp = f.readlines() 109 gyp = f.readlines()
104 with open(sys.argv[2], 'rb') as f: 110 with open(sys.argv[2], 'rb') as f:
105 gn = f.readlines() 111 gn = f.readlines()
106 all_gyp_flags = GetFlags(gyp) 112 all_gyp_flags = GetFlags(gyp)
107 all_gn_flags = GetFlags(gn) 113 all_gn_flags = GetFlags(gn)
108 gyp_files = set(all_gyp_flags.keys()) 114 gyp_files = set(all_gyp_flags.keys())
109 gn_files = set(all_gn_flags.keys()) 115 gn_files = set(all_gn_flags.keys())
110 differences = False 116 different_source_list = gyp_files != gn_files
111 if gyp_files != gn_files: 117 if different_source_list:
112 print 'Different set of sources files:' 118 print 'Different set of sources files:'
113 print ' In gyp, not in GN:\n %s' % '\n '.join( 119 print ' In gyp, not in GN:\n %s' % '\n '.join(
114 sorted(gyp_files - gn_files)) 120 sorted(gyp_files - gn_files))
115 print ' In GN, not in gyp:\n %s' % '\n '.join( 121 print ' In GN, not in gyp:\n %s' % '\n '.join(
116 sorted(gn_files - gyp_files)) 122 sorted(gn_files - gyp_files))
117 print '\nNote that flags will only be compared for files in both sets.\n' 123 print '\nNote that flags will only be compared for files in both sets.\n'
118 differences |= True
119 file_list = gyp_files & gn_files 124 file_list = gyp_files & gn_files
125 files_with_given_differences = {}
120 for filename in sorted(file_list): 126 for filename in sorted(file_list):
121 gyp_flags = all_gyp_flags[filename] 127 gyp_flags = all_gyp_flags[filename]
122 gn_flags = all_gn_flags[filename] 128 gn_flags = all_gn_flags[filename]
123 print filename 129 differences = CompareLists(gyp_flags, gn_flags, 'dash_f')
124 differences |= CompareLists(gyp_flags, gn_flags, 'dash_f') 130 differences += CompareLists(gyp_flags, gn_flags, 'defines', dont_care=[
125 differences |= CompareLists(gyp_flags, gn_flags, 'defines', dont_care=[
126 '-DENABLE_PRE_SYNC_BACKUP', 131 '-DENABLE_PRE_SYNC_BACKUP',
127 '-DENABLE_WEBRTC=1', 132 '-DENABLE_WEBRTC=1',
128 '-DUSE_LIBJPEG_TURBO=1', 133 '-DUSE_LIBJPEG_TURBO=1',
129 '-DUSE_PANGO=1', 134 '-DUSE_PANGO=1',
130 '-DUSE_SYMBOLIZE', 135 '-DUSE_SYMBOLIZE',
131 ]) 136 ])
132 differences |= CompareLists(gyp_flags, gn_flags, 'include_dirs') 137 differences += CompareLists(gyp_flags, gn_flags, 'include_dirs')
133 differences |= CompareLists(gyp_flags, gn_flags, 'warnings') 138 differences += CompareLists(gyp_flags, gn_flags, 'warnings')
134 differences |= CompareLists(gyp_flags, gn_flags, 'other') 139 differences += CompareLists(gyp_flags, gn_flags, 'other')
135 return 1 if differences else 0 140 if differences:
141 files_with_given_differences.setdefault(differences, []).append(filename)
142
143 for diff, files in files_with_given_differences.iteritems():
144 print '\n'.join(sorted(files))
145 print diff
146
147 return 1 if files_with_given_differences or different_source_list else 0
136 148
137 149
138 if __name__ == '__main__': 150 if __name__ == '__main__':
139 sys.exit(main()) 151 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698