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

Side by Side Diff: tools/gyp_flag_compare.py

Issue 2320873003: A more useful gyp_flag_compare script (Closed)
Patch Set: Use parentheses instead of \ Created 4 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 (c) 2016 The WebRTC project authors. All Rights Reserved. 3 # Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license 5 # Use of this source code is governed by a BSD-style license
6 # that can be found in the LICENSE file in the root of the source 6 # that can be found in the LICENSE file in the root of the source
7 # tree. An additional intellectual property rights grant can be found 7 # tree. An additional intellectual property rights grant can be found
8 # in the file PATENTS. All contributing project authors may 8 # in the file PATENTS. All contributing project authors may
9 # be found in the AUTHORS file in the root of the source tree. 9 # be found in the AUTHORS file in the root of the source tree.
10 10
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 class Comparison(object): 116 class Comparison(object):
117 """A comparison of the currently-configured build for a target.""" 117 """A comparison of the currently-configured build for a target."""
118 118
119 def __init__(self, gyp_target="", gn_target=None, gyp_dir=_DEFAULT_GYP_DIR, 119 def __init__(self, gyp_target="", gn_target=None, gyp_dir=_DEFAULT_GYP_DIR,
120 gn_dir=_DEFAULT_GN_DIR): 120 gn_dir=_DEFAULT_GN_DIR):
121 """Creates a comparison of a GN and GYP target. If the target names differ 121 """Creates a comparison of a GN and GYP target. If the target names differ
122 between the two build systems, then two names may be passed. 122 between the two build systems, then two names may be passed.
123 """ 123 """
124 if gn_target is None: 124 if gn_target is None:
125 gn_target = gyp_target 125 gn_target = gyp_target
126
126 self._gyp_target = gyp_target 127 self._gyp_target = gyp_target
127 self._gn_target = gn_target 128 self._gn_target = gn_target
128 129
129 self._gyp_dir = gyp_dir 130 self._gyp_dir = gyp_dir
130 self._gn_dir = gn_dir 131 self._gn_dir = gn_dir
131 132
132 self._skipped = [] 133 self._skipped = []
133 134
134 self._total_diffs = 0 135 self._total_diffs = 0
135 136
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 self._gn_flags = dict((FilterChromium(filename), value) 210 self._gn_flags = dict((FilterChromium(filename), value)
210 for filename, value in self._gn_flags.iteritems()) 211 for filename, value in self._gn_flags.iteritems())
211 self._gyp_flags = dict((FilterChromium(filename), value) 212 self._gyp_flags = dict((FilterChromium(filename), value)
212 for filename, value in self._gyp_flags.iteritems()) 213 for filename, value in self._gyp_flags.iteritems())
213 214
214 all_files = sorted(self.gn_files & self.gyp_files) 215 all_files = sorted(self.gn_files & self.gyp_files)
215 for filename in all_files: 216 for filename in all_files:
216 gyp_flags = self._gyp_flags[filename] 217 gyp_flags = self._gyp_flags[filename]
217 gn_flags = self._gn_flags[filename] 218 gn_flags = self._gn_flags[filename]
218 self._CompareLists(filename, gyp_flags, gn_flags, 'dash_f') 219 self._CompareLists(filename, gyp_flags, gn_flags, 'dash_f')
219 self._CompareLists(filename, gyp_flags, gn_flags, 'defines') 220 self._CompareLists(filename, gyp_flags, gn_flags, 'defines',
221 # These defines are not used by WebRTC
222 dont_care_gyp=[
223 '-DENABLE_WEBVR',
224 '-DUSE_EXTERNAL_POPUP_MENU',
225 '-DUSE_LIBJPEG_TURBO=1',
226 '-DUSE_MINIKIN_HYPHENATION=1',
227 '-DV8_USE_EXTERNAL_STARTUP_DATA',
228 '-DCR_CLANG_REVISION=280106-1',
229 '-DUSE_LIBPCI=1'
230 ],
231 dont_care_gn=[
232 '-DUSE_EXTERNAL_POPUP_MENU=1'
233 ])
220 self._CompareLists(filename, gyp_flags, gn_flags, 'include_dirs') 234 self._CompareLists(filename, gyp_flags, gn_flags, 'include_dirs')
221 self._CompareLists(filename, gyp_flags, gn_flags, 'warnings', 235 self._CompareLists(filename, gyp_flags, gn_flags, 'warnings',
222 # More conservative warnings in GN we consider to be OK. 236 # More conservative warnings in GN we consider to be OK.
223 dont_care_gyp=[ 237 dont_care_gyp=[
224 '/wd4091', # 'keyword' : ignored on left of 'type' when no variable 238 '/wd4091', # 'keyword' : ignored on left of 'type' when no variable
225 # is declared. 239 # is declared.
226 '/wd4456', # Declaration hides previous local declaration. 240 '/wd4456', # Declaration hides previous local declaration.
227 '/wd4457', # Declaration hides function parameter. 241 '/wd4457', # Declaration hides function parameter.
228 '/wd4458', # Declaration hides class member. 242 '/wd4458', # Declaration hides class member.
229 '/wd4459', # Declaration hides global declaration. 243 '/wd4459', # Declaration hides global declaration.
230 '/wd4702', # Unreachable code. 244 '/wd4702', # Unreachable code.
231 '/wd4800', # Forcing value to bool 'true' or 'false'. 245 '/wd4800', # Forcing value to bool 'true' or 'false'.
232 '/wd4838', # Conversion from 'type' to 'type' requires a narrowing 246 '/wd4838', # Conversion from 'type' to 'type' requires a narrowing
233 # conversion. 247 # conversion.
234 ] if sys.platform == 'win32' else None, 248 ] if sys.platform == 'win32' else None,
235 dont_care_gn=[ 249 dont_care_gn=[
236 '-Wendif-labels', 250 '-Wendif-labels',
237 '-Wextra', 251 '-Wextra',
238 '-Wsign-compare', 252 '-Wsign-compare',
239 ] if not sys.platform == 'win32' else None) 253 ] if not sys.platform == 'win32' else None)
240 self._CompareLists(filename, gyp_flags, gn_flags, 'other') 254 self._CompareLists(filename, gyp_flags, gn_flags, 'other',
255 dont_care_gyp=['-g'], dont_care_gn=['-g2'])
241 256
242 def _CompareLists(self, filename, gyp, gn, name, 257 def _CompareLists(self, filename, gyp, gn, name,
243 dont_care_gyp=None, dont_care_gn=None): 258 dont_care_gyp=None, dont_care_gn=None):
244 """Return a report of any differences between gyp and gn lists, ignoring 259 """Return a report of any differences between gyp and gn lists, ignoring
245 anything in |dont_care_{gyp|gn}| respectively.""" 260 anything in |dont_care_{gyp|gn}| respectively."""
246 if gyp[name] == gn[name]: 261 if gyp[name] == gn[name]:
247 return 262 return
248 if not dont_care_gyp: 263 if not dont_care_gyp:
249 dont_care_gyp = [] 264 dont_care_gyp = []
250 if not dont_care_gn: 265 if not dont_care_gn:
(...skipping 17 matching lines...) Expand all
268 .setdefault(m, []).append(filename) 283 .setdefault(m, []).append(filename)
269 self._total_diffs += 1 284 self._total_diffs += 1
270 self._missing_gn_files.setdefault(filename, {}) \ 285 self._missing_gn_files.setdefault(filename, {}) \
271 .setdefault(name, set()).update(missing_in_gn) 286 .setdefault(name, set()).update(missing_in_gn)
272 287
273 def _GetFlags(self, lines, build_dir): 288 def _GetFlags(self, lines, build_dir):
274 """Turn a list of command lines into a semi-structured dict.""" 289 """Turn a list of command lines into a semi-structured dict."""
275 is_win = sys.platform == 'win32' 290 is_win = sys.platform == 'win32'
276 flags_by_output = {} 291 flags_by_output = {}
277 for line in lines: 292 for line in lines:
293 line = FilterChromium(line)
294 line = line.replace(os.getcwd(), '../../')
295 line = line.replace('//', '/')
278 command_line = shlex.split(line.strip(), posix=not is_win)[1:] 296 command_line = shlex.split(line.strip(), posix=not is_win)[1:]
279 297
280 output_name = _FindAndRemoveArgWithValue(command_line, '-o') 298 output_name = _FindAndRemoveArgWithValue(command_line, '-o')
281 dep_name = _FindAndRemoveArgWithValue(command_line, '-MF') 299 dep_name = _FindAndRemoveArgWithValue(command_line, '-MF')
282 300
283 command_line = _MergeSpacedArgs(command_line, '-Xclang') 301 command_line = _MergeSpacedArgs(command_line, '-Xclang')
284 302
285 cc_file = [x for x in command_line if x.endswith('.cc') or 303 cc_file = [x for x in command_line if x.endswith('.cc') or
286 x.endswith('.c') or 304 x.endswith('.c') or
287 x.endswith('.cpp') or 305 x.endswith('.cpp') or
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if len(sys.argv) > 3: 424 if len(sys.argv) > 3:
407 gyp_target = sys.argv[3] 425 gyp_target = sys.argv[3]
408 if len(sys.argv) > 4: 426 if len(sys.argv) > 4:
409 gn_target = sys.argv[4] 427 gn_target = sys.argv[4]
410 428
411 print 'GYP output directory is %s' % gyp_dir 429 print 'GYP output directory is %s' % gyp_dir
412 print 'GN output directory is %s' % gn_dir 430 print 'GN output directory is %s' % gn_dir
413 431
414 comparison = Comparison(gyp_target, gn_target, gyp_dir, gn_dir) 432 comparison = Comparison(gyp_target, gn_target, gyp_dir, gn_dir)
415 433
416 gyp_files = comparison.gyp_files
417 gn_files = comparison.gn_files
418 different_source_list = comparison.gyp_files != comparison.gn_files
419 if different_source_list:
420 print 'Different set of sources files:'
421 print ' In gyp, not in GN:\n %s' % '\n '.join(
422 sorted(gyp_files - gn_files))
423 print ' In GN, not in gyp:\n %s' % '\n '.join(
424 sorted(gn_files - gyp_files))
425 print '\nNote that flags will only be compared for files in both sets.\n'
426
427 differing_files = set(comparison.missing_in_gn_by_file.keys()) & \ 434 differing_files = set(comparison.missing_in_gn_by_file.keys()) & \
428 set(comparison.missing_in_gyp_by_file.keys()) 435 set(comparison.missing_in_gyp_by_file.keys())
429 files_with_given_differences = {} 436 files_with_given_differences = {}
430 for filename in differing_files: 437 for filename in differing_files:
431 output = '' 438 output = ''
432 missing_in_gyp = comparison.missing_in_gyp_by_file.get(filename, {}) 439 missing_in_gyp = comparison.missing_in_gyp_by_file.get(filename, {})
433 missing_in_gn = comparison.missing_in_gn_by_file.get(filename, {}) 440 missing_in_gn = comparison.missing_in_gn_by_file.get(filename, {})
434 difference_types = sorted(set(missing_in_gyp.keys() + missing_in_gn.keys())) 441 difference_types = sorted(set(missing_in_gyp.keys() + missing_in_gn.keys()))
435 for difference_type in difference_types: 442 for difference_type in difference_types:
443 if (len(missing_in_gyp[difference_type]) == 0 and
444 len(missing_in_gn[difference_type]) == 0):
445 continue
436 output += ' %s differ:\n' % difference_type 446 output += ' %s differ:\n' % difference_type
437 if difference_type in missing_in_gyp: 447 if (difference_type in missing_in_gyp and
448 len(missing_in_gyp[difference_type])):
438 output += ' In gyp, but not in GN:\n %s' % '\n '.join( 449 output += ' In gyp, but not in GN:\n %s' % '\n '.join(
439 sorted(missing_in_gyp[difference_type])) + '\n' 450 sorted(missing_in_gyp[difference_type])) + '\n'
440 if difference_type in missing_in_gn: 451 if (difference_type in missing_in_gn and
452 len(missing_in_gn[difference_type])):
441 output += ' In GN, but not in gyp:\n %s' % '\n '.join( 453 output += ' In GN, but not in gyp:\n %s' % '\n '.join(
442 sorted(missing_in_gn[difference_type])) + '\n' 454 sorted(missing_in_gn[difference_type])) + '\n'
443 if output: 455 if output:
444 files_with_given_differences.setdefault(output, []).append(filename) 456 files_with_given_differences.setdefault(output, []).append(filename)
445 457
446 for diff, files in files_with_given_differences.iteritems(): 458 for diff, files in files_with_given_differences.iteritems():
447 print '\n'.join(sorted(files)) 459 print '\n'.join(sorted(files))
448 print diff 460 print diff
449 461
450 print 'Total differences:', comparison.total_differences 462 print 'Total differences:', comparison.total_differences
451 # TODO(scottmg): Return failure on difference once we're closer to identical. 463 # TODO(scottmg): Return failure on difference once we're closer to identical.
452 return 0 464 return 0
453 465
454 466
455 if __name__ == '__main__': 467 if __name__ == '__main__':
456 sys.exit(main()) 468 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