Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 Google Inc. All rights reserved. | 2 # Copyright (c) 2012 Google Inc. 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 """Utility functions to perform Xcode-style build steps. | 6 """Utility functions to perform Xcode-style build steps. |
| 7 | 7 |
| 8 These functions are executed via gyp-mac-tool when using the Makefile generator. | 8 These functions are executed via gyp-mac-tool when using the Makefile generator. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 method = "Exec%s" % self._CommandifyName(args[0]) | 42 method = "Exec%s" % self._CommandifyName(args[0]) |
| 43 return getattr(self, method)(*args[1:]) | 43 return getattr(self, method)(*args[1:]) |
| 44 | 44 |
| 45 def _CommandifyName(self, name_string): | 45 def _CommandifyName(self, name_string): |
| 46 """Transforms a tool name like copy-info-plist to CopyInfoPlist""" | 46 """Transforms a tool name like copy-info-plist to CopyInfoPlist""" |
| 47 return name_string.title().replace('-', '') | 47 return name_string.title().replace('-', '') |
| 48 | 48 |
| 49 def ExecCopyBundleResource(self, source, dest, convert_to_binary): | 49 def ExecCopyBundleResource(self, source, dest, convert_to_binary): |
| 50 """Copies a resource file to the bundle/Resources directory, performing any | 50 """Copies a resource file to the bundle/Resources directory, performing any |
| 51 necessary compilation on each resource.""" | 51 necessary compilation on each resource.""" |
| 52 convert_to_binary = convert_to_binary == 'True' | |
| 52 extension = os.path.splitext(source)[1].lower() | 53 extension = os.path.splitext(source)[1].lower() |
| 53 if os.path.isdir(source): | 54 if os.path.isdir(source): |
| 54 # Copy tree. | 55 # Copy tree. |
| 55 # TODO(thakis): This copies file attributes like mtime, while the | 56 # TODO(thakis): This copies file attributes like mtime, while the |
| 56 # single-file branch below doesn't. This should probably be changed to | 57 # single-file branch below doesn't. This should probably be changed to |
| 57 # be consistent with the single-file branch. | 58 # be consistent with the single-file branch. |
| 58 if os.path.exists(dest): | 59 if os.path.exists(dest): |
| 59 shutil.rmtree(dest) | 60 shutil.rmtree(dest) |
| 60 shutil.copytree(source, dest) | 61 shutil.copytree(source, dest) |
| 61 elif extension == '.xib': | 62 elif extension == '.xib': |
| 62 return self._CopyXIBFile(source, dest) | 63 return self._CopyXIBFile(source, dest) |
| 63 elif extension == '.storyboard': | 64 elif extension == '.storyboard': |
| 64 return self._CopyXIBFile(source, dest) | 65 return self._CopyXIBFile(source, dest) |
| 65 elif extension == '.strings': | 66 elif extension == '.strings' and not convert_to_binary: |
| 66 self._CopyStringsFile(source, dest) | 67 self._CopyStringsFile(source, dest) |
| 67 else: | 68 else: |
| 68 if os.path.exists(dest): | 69 if os.path.exists(dest): |
| 69 os.unlink(dest) | 70 os.unlink(dest) |
| 70 shutil.copy(source, dest) | 71 shutil.copy(source, dest) |
|
sdefresne
2016/07/05 16:52:14
The file is copied here (i.e. in the else clause).
justincohen
2016/07/06 09:18:05
Will this create a lot of churn? I wonder why we d
sdefresne
2016/07/06 09:28:06
I don't know why we do not delete first for the ot
| |
| 71 | 72 |
| 72 if extension in ('.plist', '.strings') and convert_to_binary == 'True': | 73 if convert_to_binary and extension in ('.plist', '.strings'): |
| 73 self._ConvertToBinary(dest) | 74 self._ConvertToBinary(dest) |
| 74 | 75 |
| 75 def _CopyXIBFile(self, source, dest): | 76 def _CopyXIBFile(self, source, dest): |
| 76 """Compiles a XIB file with ibtool into a binary plist in the bundle.""" | 77 """Compiles a XIB file with ibtool into a binary plist in the bundle.""" |
| 77 | 78 |
| 78 # ibtool sometimes crashes with relative paths. See crbug.com/314728. | 79 # ibtool sometimes crashes with relative paths. See crbug.com/314728. |
| 79 base = os.path.dirname(os.path.realpath(__file__)) | 80 base = os.path.dirname(os.path.realpath(__file__)) |
| 80 if os.path.relpath(source): | 81 if os.path.relpath(source): |
| 81 source = os.path.join(base, source) | 82 source = os.path.join(base, source) |
| 82 if os.path.relpath(dest): | 83 if os.path.relpath(dest): |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 out.write(struct.pack('<s', '\0')) | 703 out.write(struct.pack('<s', '\0')) |
| 703 base = os.path.dirname(path) + os.sep | 704 base = os.path.dirname(path) + os.sep |
| 704 out.write(struct.pack('<%ds' % len(base), base)) | 705 out.write(struct.pack('<%ds' % len(base), base)) |
| 705 out.write(struct.pack('<s', '\0')) | 706 out.write(struct.pack('<s', '\0')) |
| 706 path = os.path.basename(path) | 707 path = os.path.basename(path) |
| 707 out.write(struct.pack('<%ds' % len(path), path)) | 708 out.write(struct.pack('<%ds' % len(path), path)) |
| 708 out.write(struct.pack('<s', '\0')) | 709 out.write(struct.pack('<s', '\0')) |
| 709 | 710 |
| 710 if __name__ == '__main__': | 711 if __name__ == '__main__': |
| 711 sys.exit(main(sys.argv[1:])) | 712 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |