OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
9 | 9 |
10 from __future__ import print_function | 10 from __future__ import print_function |
(...skipping 4965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4976 stdout = RunCommand(command, cwd=top_dir) | 4976 stdout = RunCommand(command, cwd=top_dir) |
4977 if opts.dry_run and stdout: | 4977 if opts.dry_run and stdout: |
4978 return_value = 2 | 4978 return_value = 2 |
4979 except dart_format.NotFoundError as e: | 4979 except dart_format.NotFoundError as e: |
4980 print('Warning: Unable to check Dart code formatting. Dart SDK not ' | 4980 print('Warning: Unable to check Dart code formatting. Dart SDK not ' |
4981 'found in this checkout. Files in other languages are still ' | 4981 'found in this checkout. Files in other languages are still ' |
4982 'formatted.') | 4982 'formatted.') |
4983 | 4983 |
4984 # Format GN build files. Always run on full build files for canonical form. | 4984 # Format GN build files. Always run on full build files for canonical form. |
4985 if gn_diff_files: | 4985 if gn_diff_files: |
4986 cmd = ['gn', 'format'] | 4986 cmd = ['gn', 'format' ] |
4987 if not opts.dry_run and not opts.diff: | 4987 if opts.dry_run or opts.diff: |
4988 cmd.append('--in-place') | 4988 cmd.append('--dry-run') |
4989 for gn_diff_file in gn_diff_files: | 4989 for gn_diff_file in gn_diff_files: |
4990 stdout = RunCommand(cmd + [gn_diff_file], | 4990 gn_ret = subprocess2.call(cmd + [gn_diff_file], |
4991 shell=sys.platform == 'win32', | 4991 shell=sys.platform == 'win32', |
4992 cwd=top_dir) | 4992 cwd=top_dir) |
4993 if opts.diff: | 4993 if opts.dry_run and gn_ret == 2: |
4994 sys.stdout.write(stdout) | 4994 return_value = 2 # Not formatted. |
| 4995 elif opts.diff and gn_ret == 2: |
| 4996 # TODO this should compute and print the actual diff. |
| 4997 print("This change has GN build file diff for " + gn_diff_file) |
| 4998 elif gn_ret != 0: |
| 4999 # For non-dry run cases (and non-2 return values for dry-run), a |
| 5000 # nonzero error code indicates a failure, probably because the file |
| 5001 # doesn't parse. |
| 5002 DieWithError("gn format failed on " + gn_diff_file + |
| 5003 "\nTry running 'gn format' on this file manually.") |
4995 | 5004 |
4996 return return_value | 5005 return return_value |
4997 | 5006 |
4998 | 5007 |
4999 @subcommand.usage('<codereview url or issue id>') | 5008 @subcommand.usage('<codereview url or issue id>') |
5000 def CMDcheckout(parser, args): | 5009 def CMDcheckout(parser, args): |
5001 """Checks out a branch associated with a given Rietveld or Gerrit issue.""" | 5010 """Checks out a branch associated with a given Rietveld or Gerrit issue.""" |
5002 _, args = parser.parse_args(args) | 5011 _, args = parser.parse_args(args) |
5003 | 5012 |
5004 if len(args) != 1: | 5013 if len(args) != 1: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5095 if __name__ == '__main__': | 5104 if __name__ == '__main__': |
5096 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5105 # These affect sys.stdout so do it outside of main() to simplify mocks in |
5097 # unit testing. | 5106 # unit testing. |
5098 fix_encoding.fix_encoding() | 5107 fix_encoding.fix_encoding() |
5099 setup_color.init() | 5108 setup_color.init() |
5100 try: | 5109 try: |
5101 sys.exit(main(sys.argv[1:])) | 5110 sys.exit(main(sys.argv[1:])) |
5102 except KeyboardInterrupt: | 5111 except KeyboardInterrupt: |
5103 sys.stderr.write('interrupted\n') | 5112 sys.stderr.write('interrupted\n') |
5104 sys.exit(1) | 5113 sys.exit(1) |
OLD | NEW |