| 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 """Creates a zip archive for the Chrome Remote Desktop Host installer. | 6 """Creates a zip archive for the Chrome Remote Desktop Host installer. |
| 7 | 7 |
| 8 This script builds a zip file that contains all the files needed to build an | 8 This script builds a zip file that contains all the files needed to build an |
| 9 installer for Chrome Remote Desktop Host. | 9 installer for Chrome Remote Desktop Host. |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 dst_root: Target directory where files are copied. | 95 dst_root: Target directory where files are copied. |
| 96 src_roots: Array of path prefixes which will be stripped of |src_file| | 96 src_roots: Array of path prefixes which will be stripped of |src_file| |
| 97 (if they match) before appending it to the |dst_root|. | 97 (if they match) before appending it to the |dst_root|. |
| 98 src_file: Source file to be copied. | 98 src_file: Source file to be copied. |
| 99 Returns: | 99 Returns: |
| 100 Full path to destination file in |dst_root|. | 100 Full path to destination file in |dst_root|. |
| 101 """ | 101 """ |
| 102 # Strip of directory prefix. | 102 # Strip of directory prefix. |
| 103 found_root = False | 103 found_root = False |
| 104 for root in src_roots: | 104 for root in src_roots: |
| 105 if src_file.startswith(root): | 105 root = os.path.normpath(root) |
| 106 src_file = src_file[len(root):] | 106 src_file = os.path.normpath(src_file) |
| 107 if os.path.commonprefix([root, src_file]) == root: |
| 108 src_file = os.path.relpath(src_file, root) |
| 107 found_root = True | 109 found_root = True |
| 108 break | 110 break |
| 109 | 111 |
| 110 if not found_root: | 112 if not found_root: |
| 111 error('Unable to match prefix for %s' % src_file) | 113 error('Unable to match prefix for %s' % src_file) |
| 112 | 114 |
| 113 dst_file = os.path.join(dst_root, src_file) | 115 dst_file = os.path.join(dst_root, src_file) |
| 114 # Make sure target directory exists. | 116 # Make sure target directory exists. |
| 115 dst_dir = os.path.dirname(dst_file) | 117 dst_dir = os.path.dirname(dst_file) |
| 116 if not os.path.exists(dst_dir): | 118 if not os.path.exists(dst_dir): |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 defs: Dictionary of variable definitions. | 185 defs: Dictionary of variable definitions. |
| 184 """ | 186 """ |
| 185 cleanDir(temp_dir) | 187 cleanDir(temp_dir) |
| 186 | 188 |
| 187 for f in source_files: | 189 for f in source_files: |
| 188 dst_file = remapSrcFile(temp_dir, source_file_roots, f) | 190 dst_file = remapSrcFile(temp_dir, source_file_roots, f) |
| 189 base_file = os.path.basename(f) | 191 base_file = os.path.basename(f) |
| 190 (base, ext) = os.path.splitext(f) | 192 (base, ext) = os.path.splitext(f) |
| 191 if ext == '.zip': | 193 if ext == '.zip': |
| 192 copyZipIntoArchive(temp_dir, source_file_roots, f) | 194 copyZipIntoArchive(temp_dir, source_file_roots, f) |
| 193 elif ext in ['.packproj', '.pkgproj', '.plist', '.props', '.sh']: | 195 elif ext in ['.packproj', '.pkgproj', '.plist', '.props', '.sh', '.json']: |
| 194 copyFileWithDefs(f, dst_file, defs) | 196 copyFileWithDefs(f, dst_file, defs) |
| 195 else: | 197 else: |
| 196 shutil.copy2(f, dst_file) | 198 shutil.copy2(f, dst_file) |
| 197 | 199 |
| 198 for bs, bd in zip(gen_files, gen_files_dst): | 200 for bs, bd in zip(gen_files, gen_files_dst): |
| 199 dst_file = os.path.join(temp_dir, bd) | 201 dst_file = os.path.join(temp_dir, bd) |
| 202 if not os.path.exists(os.path.dirname(dst_file)): |
| 203 os.makedirs(os.path.dirname(dst_file)) |
| 200 if os.path.isdir(bs): | 204 if os.path.isdir(bs): |
| 201 shutil.copytree(bs, dst_file) | 205 shutil.copytree(bs, dst_file) |
| 202 else: | 206 else: |
| 203 shutil.copy2(bs, dst_file) | 207 shutil.copy2(bs, dst_file) |
| 204 | 208 |
| 205 createZip(zip_path, temp_dir) | 209 createZip(zip_path, temp_dir) |
| 206 | 210 |
| 207 | 211 |
| 208 def error(msg): | 212 def error(msg): |
| 209 sys.stderr.write('ERROR: %s\n' % msg) | 213 sys.stderr.write('ERROR: %s\n' % msg) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 elif arg_mode == 'defs': | 263 elif arg_mode == 'defs': |
| 260 definitions.append(arg) | 264 definitions.append(arg) |
| 261 else: | 265 else: |
| 262 usage() | 266 usage() |
| 263 error('Expected --source-files') | 267 error('Expected --source-files') |
| 264 | 268 |
| 265 # Make sure at least one file was specified. | 269 # Make sure at least one file was specified. |
| 266 if len(source_files) == 0 and len(generated_files) == 0: | 270 if len(source_files) == 0 and len(generated_files) == 0: |
| 267 error('At least one input file must be specified.') | 271 error('At least one input file must be specified.') |
| 268 | 272 |
| 269 # Ensure that each path in source_file_roots ends with a directory separator. | |
| 270 for root in source_file_roots: | |
| 271 if root[-1:] != os.sep: | |
| 272 error('Each source-file-root should end with a "\": %s' % root) | |
| 273 | |
| 274 # Sort roots to ensure the longest one is first. See comment in remapSrcFile | 273 # Sort roots to ensure the longest one is first. See comment in remapSrcFile |
| 275 # for why this is necessary. | 274 # for why this is necessary. |
| 275 source_file_roots = map(os.path.normpath, source_file_roots) |
| 276 source_file_roots.sort(key=len, reverse=True) | 276 source_file_roots.sort(key=len, reverse=True) |
| 277 | 277 |
| 278 # Verify that the 2 generated_files arrays have the same number of elements. | 278 # Verify that the 2 generated_files arrays have the same number of elements. |
| 279 if len(generated_files) != len(generated_files_dst): | 279 if len(generated_files) != len(generated_files_dst): |
| 280 error('len(--generated-files) != len(--generated-files-dst)') | 280 error('len(--generated-files) != len(--generated-files-dst)') |
| 281 | 281 |
| 282 defs = buildDefDictionary(definitions) | 282 defs = buildDefDictionary(definitions) |
| 283 | 283 |
| 284 result = buildHostArchive(temp_dir, zip_path, source_file_roots, | 284 result = buildHostArchive(temp_dir, zip_path, source_file_roots, |
| 285 source_files, generated_files, generated_files_dst, | 285 source_files, generated_files, generated_files_dst, |
| 286 defs) | 286 defs) |
| 287 | 287 |
| 288 return 0 | 288 return 0 |
| 289 | 289 |
| 290 | 290 |
| 291 if __name__ == '__main__': | 291 if __name__ == '__main__': |
| 292 sys.exit(main()) | 292 sys.exit(main()) |
| OLD | NEW |