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

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

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « tools/clang/scripts/update.sh ('k') | tools/valgrind/asan/asan_symbolize.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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 parts = re.split(r"[/\\]", path, 1) 112 parts = re.split(r"[/\\]", path, 1)
113 if len(parts) == 2: 113 if len(parts) == 2:
114 return parts[1] 114 return parts[1]
115 else: 115 else:
116 return parts[0] 116 return parts[0]
117 mffr.MultiFileFindReplace( 117 mffr.MultiFileFindReplace(
118 r'([\'"])%s([\'"])' % re.escape(PathMinusFirstComponent(from_path)), 118 r'([\'"])%s([\'"])' % re.escape(PathMinusFirstComponent(from_path)),
119 r'\1%s\2' % PathMinusFirstComponent(to_path), 119 r'\1%s\2' % PathMinusFirstComponent(to_path),
120 ['*.gyp*']) 120 ['*.gyp*'])
121 121
122 # Update references in BUILD.gn files.
123 #
124 # Unlike .gyp(i) files, BUILD.gn files can be placed in any directories,
125 # and paths in a BUILD.gn file are relative to the directory where the
126 # BUILD.gn file is placed.
127 #
128 # For instance, "chrome/browser/chromeos/device_uma.h" is listed as
129 # "browser/chromeos/device_uma.h" in "chrome/chrome_browser_chromeos.gypi",
130 # but it's listed as "device_uma.h" in "chrome/browser/chromeos/BUILD.gn".
131 #
132 # To handle this, the code here will visit directories from the top level
133 # src directory to the directory of |from_path| and try to update BUILD.gn
134 # in each directory.
135 #
136 # The code only handles files moved/renamed within the same BUILD.gn
137 # file. If files are moved beyond the same BUILD.gn file, the affected
138 # BUILD.gn files should be fixed manually.
139 def SplitByFirstComponent(path):
140 """'foo/bar/baz' -> ('foo', 'bar/baz')
141 'bar' -> ('bar', '')
142 '' -> ('', '')
143 """
144 parts = re.split(r"[/\\]", path, 1)
145 if len(parts) == 2:
146 return (parts[0], parts[1])
147 else:
148 return (parts[0], '')
149
150 visiting_directory = ''
151 from_rest = from_path
152 to_rest = to_path
153 while True:
154 mffr.MultiFileFindReplace(
155 r'([\'"])%s([\'"])' % from_rest,
156 r'\1%s\2' % to_rest,
157 [os.path.join(visiting_directory, 'BUILD.gn')])
158 from_first, from_rest = SplitByFirstComponent(from_rest)
159 to_first, to_rest = SplitByFirstComponent(to_rest)
160 visiting_directory = os.path.join(visiting_directory, from_first)
161 if not from_rest or not to_rest:
162 break
163
122 164
123 def MakeIncludeGuardName(path_from_root): 165 def MakeIncludeGuardName(path_from_root):
124 """Returns an include guard name given a path from root.""" 166 """Returns an include guard name given a path from root."""
125 guard = path_from_root.replace('/', '_') 167 guard = path_from_root.replace('/', '_')
126 guard = guard.replace('\\', '_') 168 guard = guard.replace('\\', '_')
127 guard = guard.replace('.', '_') 169 guard = guard.replace('.', '_')
128 guard += '_' 170 guard += '_'
129 return guard.upper() 171 return guard.upper()
130 172
131 173
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 continue 231 continue
190 to_path = MakeDestinationPath(from_path, orig_to_path) 232 to_path = MakeDestinationPath(from_path, orig_to_path)
191 if not opts.already_moved: 233 if not opts.already_moved:
192 MoveFile(from_path, to_path) 234 MoveFile(from_path, to_path)
193 UpdatePostMove(from_path, to_path) 235 UpdatePostMove(from_path, to_path)
194 return 0 236 return 0
195 237
196 238
197 if __name__ == '__main__': 239 if __name__ == '__main__':
198 sys.exit(main()) 240 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/clang/scripts/update.sh ('k') | tools/valgrind/asan/asan_symbolize.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698