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

Side by Side Diff: build/toolchain/mac/copy_bundle_data.py

Issue 2072713005: [Mac/iOS/GN] Use rsync in copy_bundle_data instead of shutil.copytree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import argparse 5 import argparse
6 import errno
6 import os 7 import os
7 import shutil 8 import shutil
8 import sys 9 import sys
10 import subprocess
9 11
10 12
11 def DetectEncoding(data, default_encoding='UTF-8'): 13 def DetectEncoding(data, default_encoding='UTF-8'):
12 """Detects the encoding used by |data| from the Byte-Order-Mark if present. 14 """Detects the encoding used by |data| from the Byte-Order-Mark if present.
13 15
14 Args: 16 Args:
15 data: string whose encoding needs to be detected 17 data: string whose encoding needs to be detected
16 default_encoding: encoding returned if no BOM is found. 18 default_encoding: encoding returned if no BOM is found.
17 19
18 Returns: 20 Returns:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 dest_file.write(data) 75 dest_file.write(data)
74 76
75 77
76 def CopyFile(source, dest, strings_format): 78 def CopyFile(source, dest, strings_format):
77 """Copies a file or directory from |source| to |dest|. 79 """Copies a file or directory from |source| to |dest|.
78 80
79 Args: 81 Args:
80 source: string, path to the source file 82 source: string, path to the source file
81 dest: string, path to the destination file 83 dest: string, path to the destination file
82 """ 84 """
83 if os.path.isdir(source): 85 try:
84 if os.path.exists(dest): 86 shutil.rmtree(dest)
85 shutil.rmtree(dest) 87 except OSError as e:
86 # Copy tree. 88 if e.errno == errno.ENOENT:
87 # TODO(thakis): This copies file attributes like mtime, while the 89 pass
88 # single-file branch below doesn't. This should probably be changed to 90 elif e.errno == errno.ENOTDIR:
89 # be consistent with the single-file branch. 91 os.unlink(dest)
90 shutil.copytree(source, dest, symlinks=True) 92 else:
91 return 93 raise
92
93 if os.path.exists(dest):
94 os.unlink(dest)
95 94
96 _, extension = os.path.splitext(source) 95 _, extension = os.path.splitext(source)
97 if extension == '.strings': 96 if extension == '.strings':
98 CopyStringsFile(source, dest, strings_format) 97 CopyStringsFile(source, dest, strings_format)
99 return 98 return
100 99
101 shutil.copy(source, dest) 100 # Strip trailing slashes on the source so rsync copies the source as a
101 # directory.
102 source = source.rstrip('/')
103
104 subprocess.check_call(
sdefresne 2016/06/17 17:17:28 I'm not sure this is correct, see my (long) commen
Robert Sesek 2016/06/17 23:11:26 It was not correct. I mixed up how the destination
105 ['rsync', '--recursive', '--perms', '--links', source, dest])
102 106
103 107
104 def Main(): 108 def Main():
105 parser = argparse.ArgumentParser( 109 parser = argparse.ArgumentParser(
106 description='copy source to destination for the creation of a bundle') 110 description='copy source to destination for the creation of a bundle')
107 parser.add_argument('--strings-format', 111 parser.add_argument('--strings-format',
108 choices=('xml1', 'binary1', 'legacy'), default='legacy', 112 choices=('xml1', 'binary1', 'legacy'), default='legacy',
109 help='convert .strings file to format (default: %(default)s)') 113 help='convert .strings file to format (default: %(default)s)')
110 parser.add_argument('source', help='path to source file or directory') 114 parser.add_argument('source', help='path to source file or directory')
111 parser.add_argument('dest', help='path to destination') 115 parser.add_argument('dest', help='path to destination')
112 args = parser.parse_args() 116 args = parser.parse_args()
113 117
114 CopyFile(args.source, args.dest, args.strings_format) 118 CopyFile(args.source, args.dest, args.strings_format)
115 119
116 if __name__ == '__main__': 120 if __name__ == '__main__':
117 sys.exit(Main()) 121 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