OLD | NEW |
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 |
11 """Given the output of -t commands from a ninja build for a gyp and GN generated | 11 """Given the output of -t commands from a ninja build for a gyp and GN generated |
12 build, report on differences between the command lines. | 12 build, report on differences between the command lines. |
13 | 13 |
14 | 14 |
15 When invoked from the command line, this script assumes that the GN and GYP | 15 When invoked from the command line, this script assumes that the GN and GYP |
16 targets have been generated in the specified folders. It is meant to be used as | 16 targets have been generated in the specified folders. It is meant to be used as |
17 follows: | 17 follows: |
18 $ python tools/gyp_flag_compare.py gyp_dir gn_dir target | 18 $ python tools/gyp_flag_compare.py gyp_dir gn_dir target |
19 | 19 |
20 When the GN and GYP target names differ, it should be called invoked as follows: | 20 When the GN and GYP target names differ, it should be called invoked as follows: |
21 $ python tools/gyp_flag_compare.py gyp_dir gn_dir gyp_target gn_target | 21 $ python tools/gyp_flag_compare.py gyp_dir gn_dir gyp_target gn_target |
22 | 22 |
| 23 When all targets want to be compared, it should be called without a target name, |
| 24 i.e.: |
| 25 $ python tools/gyp_flag_compare.py gyp_dir gn_dir |
23 | 26 |
24 This script can also be used interactively. Then ConfigureBuild can optionally | 27 This script can also be used interactively. Then ConfigureBuild can optionally |
25 be used to generate ninja files with GYP and GN. | 28 be used to generate ninja files with GYP and GN. |
26 Here's an example setup. Note that the current working directory must be the | 29 Here's an example setup. Note that the current working directory must be the |
27 project root: | 30 project root: |
28 $ PYTHONPATH=tools python | 31 $ PYTHONPATH=tools python |
29 >>> import sys | 32 >>> import sys |
30 >>> import pprint | 33 >>> import pprint |
31 >>> sys.displayhook = pprint.pprint | 34 >>> sys.displayhook = pprint.pprint |
32 >>> import gyp_flag_compare as fc | 35 >>> import gyp_flag_compare as fc |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 for path in dict_of_list: | 109 for path in dict_of_list: |
107 dirname = os.path.dirname(path) | 110 dirname = os.path.dirname(path) |
108 r.setdefault(dirname, 0) | 111 r.setdefault(dirname, 0) |
109 r[dirname] += 1 | 112 r[dirname] += 1 |
110 return r | 113 return r |
111 | 114 |
112 | 115 |
113 class Comparison(object): | 116 class Comparison(object): |
114 """A comparison of the currently-configured build for a target.""" | 117 """A comparison of the currently-configured build for a target.""" |
115 | 118 |
116 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, |
117 gn_dir=_DEFAULT_GN_DIR): | 120 gn_dir=_DEFAULT_GN_DIR): |
118 """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 |
119 between the two build systems, then two names may be passed. | 122 between the two build systems, then two names may be passed. |
120 """ | 123 """ |
121 if gn_target is None: | 124 if gn_target is None: |
122 gn_target = gyp_target | 125 gn_target = gyp_target |
123 self._gyp_target = gyp_target | 126 self._gyp_target = gyp_target |
124 self._gn_target = gn_target | 127 self._gn_target = gn_target |
125 | 128 |
126 self._gyp_dir = gyp_dir | 129 self._gyp_dir = gyp_dir |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 return result | 385 return result |
383 | 386 |
384 | 387 |
385 def Run(command_line): | 388 def Run(command_line): |
386 """Run |command_line| as a subprocess and return stdout. Raises on error.""" | 389 """Run |command_line| as a subprocess and return stdout. Raises on error.""" |
387 print >> sys.stderr, command_line | 390 print >> sys.stderr, command_line |
388 return subprocess.check_output(command_line, shell=True) | 391 return subprocess.check_output(command_line, shell=True) |
389 | 392 |
390 | 393 |
391 def main(): | 394 def main(): |
392 if len(sys.argv) < 4: | 395 if len(sys.argv) < 3: |
393 print 'usage: %s gyp_dir gn_dir target' % __file__ | 396 print 'usage: %s gyp_dir gn_dir' % __file__ |
| 397 print ' or: %s gyp_dir gn_dir target' % __file__ |
394 print ' or: %s gyp_dir gn_dir gyp_target gn_target' % __file__ | 398 print ' or: %s gyp_dir gn_dir gyp_target gn_target' % __file__ |
395 return 1 | 399 return 1 |
396 | 400 |
397 gyp_dir = sys.argv[1] | 401 gyp_dir = sys.argv[1] |
398 gn_dir = sys.argv[2] | 402 gn_dir = sys.argv[2] |
399 | 403 |
400 gyp_target = sys.argv[3] | 404 gyp_target = gn_target = "" |
401 if len(sys.argv) == 4: | 405 |
402 gn_target = gyp_target | 406 if len(sys.argv) > 3: |
403 else: | 407 gyp_target = sys.argv[3] |
| 408 if len(sys.argv) > 4: |
404 gn_target = sys.argv[4] | 409 gn_target = sys.argv[4] |
405 | 410 |
406 print 'GYP output directory is %s' % gyp_dir | 411 print 'GYP output directory is %s' % gyp_dir |
407 print 'GN output directory is %s' % gn_dir | 412 print 'GN output directory is %s' % gn_dir |
408 | 413 |
409 comparison = Comparison(gyp_target, gn_target, gyp_dir, gn_dir) | 414 comparison = Comparison(gyp_target, gn_target, gyp_dir, gn_dir) |
410 | 415 |
411 gyp_files = comparison.gyp_files | 416 gyp_files = comparison.gyp_files |
412 gn_files = comparison.gn_files | 417 gn_files = comparison.gn_files |
413 different_source_list = comparison.gyp_files != comparison.gn_files | 418 different_source_list = comparison.gyp_files != comparison.gn_files |
(...skipping 28 matching lines...) Expand all Loading... |
442 print '\n'.join(sorted(files)) | 447 print '\n'.join(sorted(files)) |
443 print diff | 448 print diff |
444 | 449 |
445 print 'Total differences:', comparison.total_differences | 450 print 'Total differences:', comparison.total_differences |
446 # TODO(scottmg): Return failure on difference once we're closer to identical. | 451 # TODO(scottmg): Return failure on difference once we're closer to identical. |
447 return 0 | 452 return 0 |
448 | 453 |
449 | 454 |
450 if __name__ == '__main__': | 455 if __name__ == '__main__': |
451 sys.exit(main()) | 456 sys.exit(main()) |
OLD | NEW |