Chromium Code Reviews| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 orig_file = archive_file | 295 orig_file = archive_file |
| 296 | 296 |
| 297 compressed_archive_file_path = os.path.join(options.output_dir, | 297 compressed_archive_file_path = os.path.join(options.output_dir, |
| 298 compressed_archive_file) | 298 compressed_archive_file) |
| 299 CompressUsingLZMA(options.build_dir, compressed_archive_file_path, orig_file, | 299 CompressUsingLZMA(options.build_dir, compressed_archive_file_path, orig_file, |
| 300 options.verbose) | 300 options.verbose) |
| 301 | 301 |
| 302 return compressed_archive_file | 302 return compressed_archive_file |
| 303 | 303 |
| 304 | 304 |
| 305 def CompressUsingMakecab(input_file, output_dir, verbose=False): | |
| 306 """ Compress |input_file| with makecab.exe and put the compressed file in | |
| 307 |output_dir|, returns the basename of this file. | |
| 308 """ | |
| 309 cmd = ['makecab.exe', | |
| 310 '/D', 'CompressionType=LZX', | |
| 311 '/V1', | |
| 312 '/L', output_dir, | |
| 313 input_file,] | |
| 314 RunSystemCommand(cmd, verbose) | |
| 315 return os.path.basename(input_file)[:-1] + "_" | |
| 316 | |
| 317 | |
| 305 def PrepareSetupExec(options, current_version, prev_version): | 318 def PrepareSetupExec(options, current_version, prev_version): |
| 306 """Prepares setup.exe for bundling in mini_installer based on options.""" | 319 """Prepares setup.exe for bundling in mini_installer based on options.""" |
| 307 if options.setup_exe_format == "FULL": | 320 if options.setup_exe_format == "FULL": |
| 308 setup_file = SETUP_EXEC | 321 setup_file = SETUP_EXEC |
| 309 elif options.setup_exe_format == "DIFF": | 322 elif options.setup_exe_format == "DIFF": |
| 310 if not options.last_chrome_installer: | 323 if not options.last_chrome_installer: |
| 311 raise Exception( | 324 raise Exception( |
| 312 "To use DIFF for setup.exe, --last_chrome_installer is needed.") | 325 "To use DIFF for setup.exe, --last_chrome_installer is needed.") |
| 313 prev_setup_file = os.path.join(options.last_chrome_installer, SETUP_EXEC) | 326 prev_setup_file = os.path.join(options.last_chrome_installer, SETUP_EXEC) |
| 314 new_setup_file = os.path.join(options.build_dir, SETUP_EXEC) | 327 new_setup_file = os.path.join(options.build_dir, SETUP_EXEC) |
| 315 patch_file = os.path.join(options.build_dir, SETUP_PATCH_FILE_PREFIX + | 328 patch_file = os.path.join(options.build_dir, SETUP_PATCH_FILE_PREFIX + |
| 316 PATCH_FILE_EXT) | 329 PATCH_FILE_EXT) |
| 317 GenerateDiffPatch(options, prev_setup_file, new_setup_file, patch_file) | 330 GenerateDiffPatch(options, prev_setup_file, new_setup_file, patch_file) |
| 318 setup_file = SETUP_PATCH_FILE_PREFIX + '_' + current_version + \ | 331 setup_file = SETUP_PATCH_FILE_PREFIX + '_' + current_version + \ |
| 319 '_from_' + prev_version + COMPRESSED_FILE_EXT | 332 '_from_' + prev_version + COMPRESSED_FILE_EXT |
| 320 setup_file_path = os.path.join(options.build_dir, setup_file) | 333 setup_file_path = os.path.join(options.build_dir, setup_file) |
| 321 CompressUsingLZMA(options.build_dir, setup_file_path, patch_file, | 334 CompressUsingLZMA(options.build_dir, setup_file_path, patch_file, |
| 322 options.verbose) | 335 options.verbose) |
| 323 else: | 336 else: |
| 324 cmd = ['makecab.exe', | 337 setup_file = CompressUsingMakecab( |
| 325 '/D', 'CompressionType=LZX', | 338 os.path.join(options.build_dir, SETUP_EXEC), |
|
grt (UTC plus 2)
2017/04/20 09:30:50
in my checkout, i find that this is compressing th
| |
| 326 '/V1', | 339 options.output_dir, |
| 327 '/L', options.output_dir, | 340 options.verbose) |
| 328 os.path.join(options.build_dir, SETUP_EXEC),] | |
| 329 RunSystemCommand(cmd, options.verbose) | |
| 330 setup_file = SETUP_EXEC[:-1] + "_" | |
| 331 return setup_file | 341 return setup_file |
| 332 | 342 |
| 333 | 343 |
| 334 _RESOURCE_FILE_HEADER = """\ | 344 _RESOURCE_FILE_HEADER = """\ |
| 335 // This file is automatically generated by create_installer_archive.py. | 345 // This file is automatically generated by create_installer_archive.py. |
| 336 // It contains the resource entries that are going to be linked inside | 346 // It contains the resource entries that are going to be linked inside |
| 337 // mini_installer.exe. For each file to be linked there should be two | 347 // mini_installer.exe. For each file to be linked there should be two |
| 338 // lines: | 348 // lines: |
| 339 // - The first line contains the output filename (without path) and the | 349 // - The first line contains the output filename (without path) and the |
| 340 // type of the resource ('BN' - not compressed , 'BL' - LZ compressed, | 350 // type of the resource ('BN' - not compressed , 'BL' - LZ compressed, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 359 setup_resource_type = "B7" | 369 setup_resource_type = "B7" |
| 360 | 370 |
| 361 # An array of (file, type, path) tuples of the files to be included. | 371 # An array of (file, type, path) tuples of the files to be included. |
| 362 resources = [] | 372 resources = [] |
| 363 resources.append((setup_file, setup_resource_type, | 373 resources.append((setup_file, setup_resource_type, |
| 364 os.path.join(output_dir, setup_file))) | 374 os.path.join(output_dir, setup_file))) |
| 365 resources.append((archive_file, 'B7', | 375 resources.append((archive_file, 'B7', |
| 366 os.path.join(output_dir, archive_file))) | 376 os.path.join(output_dir, archive_file))) |
| 367 # Include all files needed to run setup.exe (these are copied into the | 377 # Include all files needed to run setup.exe (these are copied into the |
| 368 # 'Installer' dir by DoComponentBuildTasks). | 378 # 'Installer' dir by DoComponentBuildTasks). |
| 369 if component_build: | 379 installer_dir = os.path.join(staging_dir, CHROME_DIR, current_version, |
| 370 installer_dir = os.path.join(staging_dir, CHROME_DIR, current_version, | 380 'Installer') |
| 371 'Installer') | 381 for file in os.listdir(installer_dir): |
| 372 for file in os.listdir(installer_dir): | 382 if component_build: |
| 373 resources.append((file, 'BN', os.path.join(installer_dir, file))) | 383 resources.append((file, 'BN', os.path.join(installer_dir, file))) |
| 384 else: | |
| 385 resources.append((file, 'BL', os.path.join(installer_dir, file))) | |
| 374 | 386 |
| 375 with open(resource_file_path, 'w') as f: | 387 with open(resource_file_path, 'w') as f: |
| 376 f.write(_RESOURCE_FILE_HEADER) | 388 f.write(_RESOURCE_FILE_HEADER) |
| 377 for (file, type, path) in resources: | 389 for (file, type, path) in resources: |
| 378 f.write('\n%s %s\n "%s"\n' % (file, type, path.replace("\\","/"))) | 390 f.write('\n%s %s\n "%s"\n' % (file, type, path.replace("\\","/"))) |
| 379 | 391 |
| 380 | 392 |
| 381 # Reads |manifest_name| from |build_dir| and writes |manifest_name| to | 393 # Reads |manifest_name| from |build_dir| and writes |manifest_name| to |
| 382 # |output_dir| with the same content plus |inserted_string| added just before | 394 # |output_dir| with the same content plus |inserted_string| added just before |
| 383 # |insert_before|. | 395 # |insert_before|. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 def ParseDLLsFromDeps(build_dir, runtime_deps_file): | 473 def ParseDLLsFromDeps(build_dir, runtime_deps_file): |
| 462 """Parses the runtime_deps file and returns the set of DLLs in it, relative | 474 """Parses the runtime_deps file and returns the set of DLLs in it, relative |
| 463 to build_dir.""" | 475 to build_dir.""" |
| 464 build_dlls = set() | 476 build_dlls = set() |
| 465 args = open(runtime_deps_file).read() | 477 args = open(runtime_deps_file).read() |
| 466 for l in args.splitlines(): | 478 for l in args.splitlines(): |
| 467 if os.path.splitext(l)[1] == ".dll": | 479 if os.path.splitext(l)[1] == ".dll": |
| 468 build_dlls.add(os.path.join(build_dir, l)) | 480 build_dlls.add(os.path.join(build_dir, l)) |
| 469 return build_dlls | 481 return build_dlls |
| 470 | 482 |
| 483 | |
| 484 def CopySetupRuntimeDeps(build_dir, setup_runtime_deps, version_dir, | |
| 485 component_build): | |
| 486 """Copy the setup.exe runtime dependencies to the installer's directory.""" | |
| 487 installer_dir = os.path.join(version_dir, 'Installer') | |
| 488 # |installer_dir| is technically only created post-install, but we need it | |
| 489 # now to add setup.exe's config and manifest to the archive. | |
| 490 if not os.path.exists(installer_dir): | |
| 491 os.mkdir(installer_dir) | |
| 492 | |
| 493 setup_component_dlls = ParseDLLsFromDeps(build_dir, setup_runtime_deps) | |
| 494 for setup_component_dll in setup_component_dlls: | |
| 495 if component_build: | |
| 496 input_name = setup_component_dll | |
| 497 shutil.copy(input_name, installer_dir) | |
| 498 else: | |
| 499 input_name = CompressUsingMakecab(setup_component_dll, installer_dir) | |
| 500 g_archive_inputs.append(input_name) | |
| 501 | |
| 502 | |
| 471 # Copies component build DLLs and generates required config files and manifests | 503 # Copies component build DLLs and generates required config files and manifests |
| 472 # in order for chrome.exe and setup.exe to be able to find those DLLs at | 504 # in order for chrome.exe and setup.exe to be able to find those DLLs at |
| 473 # run-time. | 505 # run-time. |
| 474 # This is meant for developer builds only and should never be used to package | 506 # This is meant for developer builds only and should never be used to package |
| 475 # an official build. | 507 # an official build. |
| 476 def DoComponentBuildTasks(staging_dir, build_dir, target_arch, | 508 def DoComponentBuildTasks(staging_dir, build_dir, target_arch, |
| 477 setup_runtime_deps, chrome_runtime_deps, | 509 setup_runtime_deps, chrome_runtime_deps, |
| 478 current_version): | 510 current_version): |
| 479 # Get the required directories for the upcoming operations. | 511 # Get the required directories for the upcoming operations. |
| 480 chrome_dir = os.path.join(staging_dir, CHROME_DIR) | 512 chrome_dir = os.path.join(staging_dir, CHROME_DIR) |
| 481 version_dir = os.path.join(chrome_dir, current_version) | 513 version_dir = os.path.join(chrome_dir, current_version) |
| 482 installer_dir = os.path.join(version_dir, 'Installer') | |
| 483 # |installer_dir| is technically only created post-install, but we need it | |
| 484 # now to add setup.exe's config and manifest to the archive. | |
| 485 if not os.path.exists(installer_dir): | |
| 486 os.mkdir(installer_dir) | |
| 487 | 514 |
| 488 setup_component_dlls = ParseDLLsFromDeps(build_dir, setup_runtime_deps) | 515 CopySetupRuntimeDeps(build_dir, setup_runtime_deps, version_dir, True) |
| 489 | |
| 490 for setup_component_dll in setup_component_dlls: | |
| 491 g_archive_inputs.append(setup_component_dll) | |
| 492 shutil.copy(setup_component_dll, installer_dir) | |
| 493 | 516 |
| 494 # Stage all the component DLLs to the |version_dir| (for | 517 # Stage all the component DLLs to the |version_dir| (for |
| 495 # the version assembly to be able to refer to them below and make sure | 518 # the version assembly to be able to refer to them below and make sure |
| 496 # chrome.exe can find them at runtime), except the ones that are already | 519 # chrome.exe can find them at runtime), except the ones that are already |
| 497 # staged (i.e. non-component DLLs). | 520 # staged (i.e. non-component DLLs). |
| 498 build_dlls = ParseDLLsFromDeps(build_dir, chrome_runtime_deps) | 521 build_dlls = ParseDLLsFromDeps(build_dir, chrome_runtime_deps) |
| 499 staged_dll_basenames = [os.path.basename(staged_dll) for staged_dll in \ | 522 staged_dll_basenames = [os.path.basename(staged_dll) for staged_dll in \ |
| 500 glob.glob(os.path.join(version_dir, '*.dll'))] | 523 glob.glob(os.path.join(version_dir, '*.dll'))] |
| 501 component_dll_filenames = [] | 524 component_dll_filenames = [] |
| 502 for component_dll in [dll for dll in build_dlls if \ | 525 for component_dll in [dll for dll in build_dlls if \ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 | 565 |
| 543 # Now copy the remainder of the files from the build dir. | 566 # Now copy the remainder of the files from the build dir. |
| 544 CopyAllFilesToStagingDir(config, options.distribution, | 567 CopyAllFilesToStagingDir(config, options.distribution, |
| 545 staging_dir, options.build_dir, | 568 staging_dir, options.build_dir, |
| 546 options.enable_hidpi) | 569 options.enable_hidpi) |
| 547 | 570 |
| 548 if options.component_build == '1': | 571 if options.component_build == '1': |
| 549 DoComponentBuildTasks(staging_dir, options.build_dir, | 572 DoComponentBuildTasks(staging_dir, options.build_dir, |
| 550 options.target_arch, options.setup_runtime_deps, | 573 options.target_arch, options.setup_runtime_deps, |
| 551 options.chrome_runtime_deps, current_version) | 574 options.chrome_runtime_deps, current_version) |
| 575 elif options.setup_runtime_deps: | |
| 576 CopySetupRuntimeDeps(options.build_dir, options.setup_runtime_deps, | |
| 577 os.path.join(staging_dir, CHROME_DIR, current_version), | |
| 578 options.component_build=='1') | |
| 552 | 579 |
| 553 version_numbers = current_version.split('.') | 580 version_numbers = current_version.split('.') |
| 554 current_build_number = version_numbers[2] + '.' + version_numbers[3] | 581 current_build_number = version_numbers[2] + '.' + version_numbers[3] |
| 555 prev_build_number = '' | 582 prev_build_number = '' |
| 556 if prev_version: | 583 if prev_version: |
| 557 version_numbers = prev_version.split('.') | 584 version_numbers = prev_version.split('.') |
| 558 prev_build_number = version_numbers[2] + '.' + version_numbers[3] | 585 prev_build_number = version_numbers[2] + '.' + version_numbers[3] |
| 559 | 586 |
| 560 # Name of the archive file built (for example - chrome.7z or | 587 # Name of the archive file built (for example - chrome.7z or |
| 561 # patch-<old_version>-<new_version>.7z or patch-<new_version>.7z | 588 # patch-<old_version>-<new_version>.7z or patch-<new_version>.7z |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 MINI_INSTALLER_INPUT_FILE) | 677 MINI_INSTALLER_INPUT_FILE) |
| 651 | 678 |
| 652 return options | 679 return options |
| 653 | 680 |
| 654 | 681 |
| 655 if '__main__' == __name__: | 682 if '__main__' == __name__: |
| 656 options = _ParseOptions() | 683 options = _ParseOptions() |
| 657 if options.verbose: | 684 if options.verbose: |
| 658 print sys.argv | 685 print sys.argv |
| 659 sys.exit(main(options)) | 686 sys.exit(main(options)) |
| OLD | NEW |