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

Side by Side Diff: tools/git/move_source_file.py

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 | « tools/clang/scripts/run_tool.py ('k') | tools/idl_parser/idl_parser.py » ('j') | 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 # 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 """Moves C++ files to a new location, updating any include paths that point 6 """Moves C++ files to a new location, updating any include paths that point
7 to them, and re-ordering headers as needed. If multiple source files are 7 to them, and re-ordering headers as needed. If multiple source files are
8 specified, the destination must be a directory. Updates include guards in 8 specified, the destination must be a directory. Updates include guards in
9 moved header files. Assumes Chromium coding style. 9 moved header files. Assumes Chromium coding style.
10 10
(...skipping 15 matching lines...) Expand all
26 26
27 import mffr 27 import mffr
28 28
29 if __name__ == '__main__': 29 if __name__ == '__main__':
30 # Need to add the directory containing sort-headers.py to the Python 30 # Need to add the directory containing sort-headers.py to the Python
31 # classpath. 31 # classpath.
32 sys.path.append(os.path.abspath(os.path.join(sys.path[0], '..'))) 32 sys.path.append(os.path.abspath(os.path.join(sys.path[0], '..')))
33 sort_headers = __import__('sort-headers') 33 sort_headers = __import__('sort-headers')
34 34
35 35
36 HANDLED_EXTENSIONS = ['.cc', '.mm', '.h', '.hh'] 36 HANDLED_EXTENSIONS = ['.cc', '.mm', '.h', '.hh', '.cpp']
37 37
38 38
39 def IsHandledFile(path): 39 def IsHandledFile(path):
40 return os.path.splitext(path)[1] in HANDLED_EXTENSIONS 40 return os.path.splitext(path)[1] in HANDLED_EXTENSIONS
41 41
42 42
43 def MakeDestinationPath(from_path, to_path): 43 def MakeDestinationPath(from_path, to_path):
44 """Given the from and to paths, return a correct destination path. 44 """Given the from and to paths, return a correct destination path.
45 45
46 The initial destination path may either a full path or a directory. 46 The initial destination path may either a full path or a directory.
(...skipping 30 matching lines...) Expand all
77 from_path = from_path.replace('\\', '/') 77 from_path = from_path.replace('\\', '/')
78 to_path = to_path.replace('\\', '/') 78 to_path = to_path.replace('\\', '/')
79 79
80 if os.path.splitext(from_path)[1] in ['.h', '.hh']: 80 if os.path.splitext(from_path)[1] in ['.h', '.hh']:
81 UpdateIncludeGuard(from_path, to_path) 81 UpdateIncludeGuard(from_path, to_path)
82 82
83 # Update include/import references. 83 # Update include/import references.
84 files_with_changed_includes = mffr.MultiFileFindReplace( 84 files_with_changed_includes = mffr.MultiFileFindReplace(
85 r'(#(include|import)\s*["<])%s([>"])' % re.escape(from_path), 85 r'(#(include|import)\s*["<])%s([>"])' % re.escape(from_path),
86 r'\1%s\3' % to_path, 86 r'\1%s\3' % to_path,
87 ['*.cc', '*.h', '*.m', '*.mm']) 87 ['*.cc', '*.h', '*.m', '*.mm', '*.cpp'])
88 88
89 # Reorder headers in files that changed. 89 # Reorder headers in files that changed.
90 for changed_file in files_with_changed_includes: 90 for changed_file in files_with_changed_includes:
91 def AlwaysConfirm(a, b): return True 91 def AlwaysConfirm(a, b): return True
92 sort_headers.FixFileWithConfirmFunction(changed_file, AlwaysConfirm, True) 92 sort_headers.FixFileWithConfirmFunction(changed_file, AlwaysConfirm, True)
93 93
94 # Update comments; only supports // comments, which are primarily 94 # Update comments; only supports // comments, which are primarily
95 # used in our code. 95 # used in our code.
96 # 96 #
97 # This work takes a bit of time. If this script starts feeling too 97 # This work takes a bit of time. If this script starts feeling too
98 # slow, one good way to speed it up is to make the comment handling 98 # slow, one good way to speed it up is to make the comment handling
99 # optional under a flag. 99 # optional under a flag.
100 mffr.MultiFileFindReplace( 100 mffr.MultiFileFindReplace(
101 r'(//.*)%s' % re.escape(from_path), 101 r'(//.*)%s' % re.escape(from_path),
102 r'\1%s' % to_path, 102 r'\1%s' % to_path,
103 ['*.cc', '*.h', '*.m', '*.mm']) 103 ['*.cc', '*.h', '*.m', '*.mm', '*.cpp'])
104 104
105 # Update references in .gyp(i) files. 105 # Update references in .gyp(i) files.
106 def PathMinusFirstComponent(path): 106 def PathMinusFirstComponent(path):
107 """foo/bar/baz -> bar/baz""" 107 """foo/bar/baz -> bar/baz"""
108 parts = re.split(r"[/\\]", path, 1) 108 parts = re.split(r"[/\\]", path, 1)
109 if len(parts) == 2: 109 if len(parts) == 2:
110 return parts[1] 110 return parts[1]
111 else: 111 else:
112 return parts[0] 112 return parts[0]
113 mffr.MultiFileFindReplace( 113 mffr.MultiFileFindReplace(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 continue 185 continue
186 to_path = MakeDestinationPath(from_path, orig_to_path) 186 to_path = MakeDestinationPath(from_path, orig_to_path)
187 if not opts.already_moved: 187 if not opts.already_moved:
188 MoveFile(from_path, to_path) 188 MoveFile(from_path, to_path)
189 UpdatePostMove(from_path, to_path) 189 UpdatePostMove(from_path, to_path)
190 return 0 190 return 0
191 191
192 192
193 if __name__ == '__main__': 193 if __name__ == '__main__':
194 sys.exit(main()) 194 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/clang/scripts/run_tool.py ('k') | tools/idl_parser/idl_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698