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 """Script to create Chrome Installer archive. | 6 """Script to create Chrome Installer archive. |
7 | 7 |
8 This script is used to create an archive of all the files required for a | 8 This script is used to create an archive of all the files required for a |
9 Chrome install in appropriate directory structure. It reads chrome.release | 9 Chrome install in appropriate directory structure. It reads chrome.release |
10 file as input, creates chrome.7z archive, compresses setup.exe and | 10 file as input, creates chrome.7z archive, compresses setup.exe and |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 'archive_file': archive_file, | 305 'archive_file': archive_file, |
306 'archive_file_path': | 306 'archive_file_path': |
307 os.path.join(output_dir, archive_file).replace("\\","/"), | 307 os.path.join(output_dir, archive_file).replace("\\","/"), |
308 } | 308 } |
309 resource_file = _RESOURCE_FILE_TEMPLATE % args | 309 resource_file = _RESOURCE_FILE_TEMPLATE % args |
310 | 310 |
311 with open(resource_file_path, 'w') as f: | 311 with open(resource_file_path, 'w') as f: |
312 f.write(resource_file) | 312 f.write(resource_file) |
313 | 313 |
314 | 314 |
315 # Copies component build DLLs and generates required config files and manifests | |
316 # in order for chrome.exe and setup.exe to be able to find those DLLs at | |
317 # run-time. | |
318 # This is meant for developer builds only and should never be used to package | |
319 # an official build. | |
320 def DoComponentBuildTasks(staging_dir, build_dir, current_version): | |
321 # Get the required directories for the upcoming operations. | |
322 chrome_dir = os.path.join(staging_dir, CHROME_DIR) | |
323 version_dir = os.path.join(chrome_dir, current_version) | |
324 installer_dir = os.path.join(version_dir, 'Installer') | |
325 # |installer_dir| is technically only created post-install, but we need it | |
326 # now to add setup.exe's config and manifest to the archive. | |
327 if not os.path.exists(installer_dir): | |
328 os.mkdir(installer_dir) | |
329 | |
330 # Copy all the DLLs in |build_dir| to the version directory. | |
331 dlls = glob.glob(os.path.join(build_dir, '*.dll')) | |
332 for dll in dlls: | |
333 shutil.copy(dll, version_dir) | |
334 | |
335 exe_config = ( | |
336 "<configuration>\n" | |
337 " <windows>\n" | |
338 " <assemblyBinding xmlns='urn:schemas-microsoft-com:asm.v1'>\n" | |
339 " <probing privatePath='{rel_path}'/>\n" | |
340 " </assemblyBinding>\n" | |
341 " </windows>\n" | |
342 "</configuration>") | |
343 | |
344 # Write chrome.exe.config to point to the version directory. | |
345 chrome_exe_config_file = open( | |
346 os.path.join(chrome_dir, 'chrome.exe.config'), 'w') | |
347 chrome_exe_config_file.write(exe_config.format(rel_path=current_version)) | |
348 chrome_exe_config_file.close() | |
349 | |
350 # Write setup.exe.config to point to the version directory (which is under it | |
robertshield
2012/05/15 02:42:50
"under it" -> "one level up from setup.exe"?
gab
2012/05/15 03:01:40
Done.
| |
351 # post-install). | |
352 setup_exe_config_file = open( | |
353 os.path.join(installer_dir, 'setup.exe.config'), 'w') | |
354 setup_exe_config_file.write(exe_config.format(rel_path='..')) | |
355 setup_exe_config_file.close() | |
356 | |
357 # Build a list containing the name of each DLL found in |build_dir|. | |
358 dll_names = [] | |
359 for dll in dlls: | |
360 dll_names.append(os.path.splitext(os.path.basename(dll))[0]) | |
361 | |
362 # Build the manifests for chrome.exe and setup.exe in which we list all the | |
363 # DLLs as side by side assembly dependencies. | |
364 # TODO (gab): These extra properties should be merged with the existing | |
365 # chrome/app/chrome.exe.manifest and | |
366 # chrome/installer/setup/setup.exe.manifest. | |
367 exe_manifest_parts = [ | |
368 "<assembly\n" | |
369 " xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>\n" | |
370 " <trustInfo xmlns='urn:schemas-microsoft-com:asm.v3'>\n" | |
371 " <security>\n" | |
372 " <requestedPrivileges>\n" | |
373 " <requestedExecutionLevel level='asInvoker' uiAccess='false'/>\n" | |
374 " </requestedPrivileges>\n" | |
375 " </security>\n" | |
376 " </trustInfo>\n"] | |
377 | |
378 for name in dll_names: | |
379 exe_manifest_parts.append( | |
380 " <dependency>\n" | |
381 " <dependentAssembly>\n" | |
382 " <assemblyIdentity type='win32' name='chrome.{dll_basename}'\n" | |
383 " version='0.0.0.0' processorArchitecture='x86'\n" | |
384 " language='*'/>\n" | |
385 " </dependentAssembly>\n" | |
386 " </dependency>\n".format(dll_basename=name)) | |
387 | |
388 exe_manifest_parts.append("</assembly>") | |
389 exe_manifest = ''.join(exe_manifest_parts) | |
390 | |
391 # Write chrome.exe.manifest beside chrome.exe. | |
392 chrome_exe_manifest_file = open( | |
393 os.path.join(chrome_dir, 'chrome.exe.manifest'), 'w') | |
394 chrome_exe_manifest_file.write(exe_manifest) | |
395 chrome_exe_manifest_file.close() | |
396 | |
397 # Write setup.exe.manifest beside setup.exe in |version_dir|/Installer. | |
398 setup_exe_manifest_file = open( | |
399 os.path.join(installer_dir, 'setup.exe.manifest'), 'w') | |
400 setup_exe_manifest_file.write(exe_manifest) | |
401 setup_exe_manifest_file.close() | |
402 | |
403 # Write chrome.{dllname}.manifest in the version directory for each DLL list | |
robertshield
2012/05/15 02:42:50
list -> listed
gab
2012/05/15 03:01:40
Done.
| |
404 # as a dependency in the previous step. | |
405 # TODO (gab): The properties should probably be merged with the existing | |
406 # chrome/app/chrome.dll.manifest which could be duplicated for every extra | |
407 # DLL in the component build. | |
408 for name in dll_names: | |
409 dll_manifest = ( | |
410 "<assembly\n" | |
411 " xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>\n" | |
412 " <assemblyIdentity name='chrome.{dll_basename}' version='0.0.0.0'\n" | |
413 " type='win32' processorArchitecture='x86'/>\n" | |
414 " <file name='{dll_basename}.dll'/>\n" | |
415 "</assembly>".format(dll_basename=name)) | |
416 | |
417 dll_manifest_file = open(os.path.join( | |
418 version_dir, | |
419 "chrome.{dll_basename}.manifest".format(dll_basename=name)), 'w') | |
420 dll_manifest_file.write(dll_manifest) | |
421 dll_manifest_file.close() | |
422 | |
423 | |
315 def main(options): | 424 def main(options): |
316 """Main method that reads input file, creates archive file and write | 425 """Main method that reads input file, creates archive file and write |
317 resource input file. | 426 resource input file. |
318 """ | 427 """ |
319 current_version = BuildVersion(options.build_dir) | 428 current_version = BuildVersion(options.build_dir) |
320 | 429 |
321 config = Readconfig(options.build_dir, options.input_file, current_version) | 430 config = Readconfig(options.build_dir, options.input_file, current_version) |
322 | 431 |
323 (staging_dir, temp_dir) = MakeStagingDirectories(options.staging_dir) | 432 (staging_dir, temp_dir) = MakeStagingDirectories(options.staging_dir) |
324 | 433 |
325 prev_version = GetPrevVersion(options.build_dir, temp_dir, | 434 prev_version = GetPrevVersion(options.build_dir, temp_dir, |
326 options.last_chrome_installer) | 435 options.last_chrome_installer) |
327 | 436 |
328 # Preferentially copy the files we can find from the output_dir, as | 437 # Preferentially copy the files we can find from the output_dir, as |
329 # this is where we'll find the Syzygy-optimized executables when | 438 # this is where we'll find the Syzygy-optimized executables when |
330 # building the optimized mini_installer. | 439 # building the optimized mini_installer. |
331 if options.build_dir != options.output_dir: | 440 if options.build_dir != options.output_dir: |
332 CopyAllFilesToStagingDir(config, options.distribution, | 441 CopyAllFilesToStagingDir(config, options.distribution, |
333 staging_dir, options.output_dir, | 442 staging_dir, options.output_dir, |
334 options.enable_hidpi, options.enable_metro) | 443 options.enable_hidpi, options.enable_metro) |
335 | 444 |
336 # Now copy the remainder of the files from the build dir. | 445 # Now copy the remainder of the files from the build dir. |
337 CopyAllFilesToStagingDir(config, options.distribution, | 446 CopyAllFilesToStagingDir(config, options.distribution, |
338 staging_dir, options.build_dir, | 447 staging_dir, options.build_dir, |
339 options.enable_hidpi, options.enable_metro) | 448 options.enable_hidpi, options.enable_metro) |
340 | 449 |
450 if options.component_build == '1': | |
451 DoComponentBuildTasks(staging_dir, options.build_dir, current_version) | |
452 | |
341 version_numbers = current_version.split('.') | 453 version_numbers = current_version.split('.') |
342 current_build_number = version_numbers[2] + '.' + version_numbers[3] | 454 current_build_number = version_numbers[2] + '.' + version_numbers[3] |
343 prev_build_number = '' | 455 prev_build_number = '' |
344 if prev_version: | 456 if prev_version: |
345 version_numbers = prev_version.split('.') | 457 version_numbers = prev_version.split('.') |
346 prev_build_number = version_numbers[2] + '.' + version_numbers[3] | 458 prev_build_number = version_numbers[2] + '.' + version_numbers[3] |
347 | 459 |
348 # Name of the archive file built (for example - chrome.7z or | 460 # Name of the archive file built (for example - chrome.7z or |
349 # patch-<old_version>-<new_version>.7z or patch-<new_version>.7z | 461 # patch-<old_version>-<new_version>.7z or patch-<new_version>.7z |
350 archive_file = CreateArchiveFile(options, staging_dir, | 462 archive_file = CreateArchiveFile(options, staging_dir, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 parser.add_option('-a', '--diff_algorithm', default='BSDIFF', | 498 parser.add_option('-a', '--diff_algorithm', default='BSDIFF', |
387 help='Diff algorithm to use when generating differential patches ' | 499 help='Diff algorithm to use when generating differential patches ' |
388 '{BSDIFF|COURGETTE}.') | 500 '{BSDIFF|COURGETTE}.') |
389 parser.add_option('-n', '--output_name', default='chrome', | 501 parser.add_option('-n', '--output_name', default='chrome', |
390 help='Name used to prefix names of generated archives.') | 502 help='Name used to prefix names of generated archives.') |
391 parser.add_option('--enable_hidpi', default='0', | 503 parser.add_option('--enable_hidpi', default='0', |
392 help='Whether to include HiDPI resource files.') | 504 help='Whether to include HiDPI resource files.') |
393 parser.add_option('--enable_metro', default='0', | 505 parser.add_option('--enable_metro', default='0', |
394 help='Whether to include resource files from the "METRO" section of the ' | 506 help='Whether to include resource files from the "METRO" section of the ' |
395 'input file.') | 507 'input file.') |
508 parser.add_option('--component_build', default='0', | |
509 help='Whether this archive is packaging a component build.') | |
396 | 510 |
397 options, args = parser.parse_args() | 511 options, args = parser.parse_args() |
398 if not options.build_dir: | 512 if not options.build_dir: |
399 parser.error('You must provide a build dir.') | 513 parser.error('You must provide a build dir.') |
400 | 514 |
401 if not options.staging_dir: | 515 if not options.staging_dir: |
402 parser.error('You must provide a staging dir.') | 516 parser.error('You must provide a staging dir.') |
403 | 517 |
518 if not options.input_file: | |
519 parser.error('You must provide an input file') | |
520 | |
404 if not options.output_dir: | 521 if not options.output_dir: |
405 options.output_dir = options.build_dir | 522 options.output_dir = options.build_dir |
406 | 523 |
407 if not options.resource_file_path: | 524 if not options.resource_file_path: |
408 options.options.resource_file_path = os.path.join(options.build_dir, | 525 options.resource_file_path = os.path.join(options.build_dir, |
409 MINI_INSTALLER_INPUT_FILE) | 526 MINI_INSTALLER_INPUT_FILE) |
410 | 527 |
411 return options | 528 return options |
412 | 529 |
413 | 530 |
414 if '__main__' == __name__: | 531 if '__main__' == __name__: |
415 print sys.argv | 532 print sys.argv |
416 sys.exit(main(_ParseOptions())) | 533 sys.exit(main(_ParseOptions())) |
OLD | NEW |