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

Side by Side Diff: chrome/tools/build/win/create_installer_archive.py

Issue 1372303003: Make create_installer_archive.py operate silently by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better stdout/stderr capture Created 5 years, 2 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 | « chrome/installer/mini_installer/BUILD.gn ('k') | 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 #!/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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 major = line[6:] 59 major = line[6:]
60 elif line.startswith('MINOR='): 60 elif line.startswith('MINOR='):
61 minor = line[6:] 61 minor = line[6:]
62 elif line.startswith('BUILD='): 62 elif line.startswith('BUILD='):
63 build = line[6:] 63 build = line[6:]
64 elif line.startswith('PATCH='): 64 elif line.startswith('PATCH='):
65 patch = line[6:] 65 patch = line[6:]
66 return '%s.%s.%s.%s' % (major, minor, build, patch) 66 return '%s.%s.%s.%s' % (major, minor, build, patch)
67 67
68 68
69 def CompressUsingLZMA(build_dir, compressed_file, input_file): 69 def CompressUsingLZMA(build_dir, compressed_file, input_file, verbose):
70 lzma_exec = GetLZMAExec(build_dir) 70 lzma_exec = GetLZMAExec(build_dir)
71 cmd = [lzma_exec, 71 cmd = [lzma_exec,
72 'a', '-t7z', 72 'a', '-t7z',
73 # Flags equivalent to -mx9 (ultra) but with the bcj2 turned on (exe 73 # Flags equivalent to -mx9 (ultra) but with the bcj2 turned on (exe
74 # pre-filter). This results in a ~2.3MB decrease in installer size on 74 # pre-filter). This results in a ~2.3MB decrease in installer size on
75 # a 24MB installer. 75 # a 24MB installer.
76 # Additionally, these settings reflect a 7zip 4.42 and up change in 76 # Additionally, these settings reflect a 7zip 4.42 and up change in
77 # the definition of -mx9, increasting the dicionary size moving to 77 # the definition of -mx9, increasting the dicionary size moving to
78 # 26bit = 64MB. This results in an additional ~3.5MB decrease. 78 # 26bit = 64MB. This results in an additional ~3.5MB decrease.
79 # Older 7zip versions can support these settings, as these changes 79 # Older 7zip versions can support these settings, as these changes
80 # rely on existing functionality in the lzma format. 80 # rely on existing functionality in the lzma format.
81 '-m0=BCJ2', 81 '-m0=BCJ2',
82 '-m1=LZMA:d27:fb128', 82 '-m1=LZMA:d27:fb128',
83 '-m2=LZMA:d22:fb128:mf=bt2', 83 '-m2=LZMA:d22:fb128:mf=bt2',
84 '-m3=LZMA:d22:fb128:mf=bt2', 84 '-m3=LZMA:d22:fb128:mf=bt2',
85 '-mb0:1', 85 '-mb0:1',
86 '-mb0s1:2', 86 '-mb0s1:2',
87 '-mb0s2:3', 87 '-mb0s2:3',
88 compressed_file, 88 compressed_file,
89 input_file,] 89 input_file,]
90 if os.path.exists(compressed_file): 90 if os.path.exists(compressed_file):
91 os.remove(compressed_file) 91 os.remove(compressed_file)
92 RunSystemCommand(cmd) 92 RunSystemCommand(cmd, verbose)
93 93
94 94
95 def CopyAllFilesToStagingDir(config, distribution, staging_dir, build_dir, 95 def CopyAllFilesToStagingDir(config, distribution, staging_dir, build_dir,
96 enable_hidpi): 96 enable_hidpi):
97 """Copies the files required for installer archive. 97 """Copies the files required for installer archive.
98 Copies all common files required for various distributions of Chromium and 98 Copies all common files required for various distributions of Chromium and
99 also files for the specific Chromium build specified by distribution. 99 also files for the specific Chromium build specified by distribution.
100 """ 100 """
101 CopySectionFilesToStagingDir(config, 'GENERAL', staging_dir, build_dir) 101 CopySectionFilesToStagingDir(config, 'GENERAL', staging_dir, build_dir)
102 if distribution: 102 if distribution:
(...skipping 24 matching lines...) Expand all
127 g_archive_inputs.append(src_path) 127 g_archive_inputs.append(src_path)
128 shutil.copy(src_path, dst_dir) 128 shutil.copy(src_path, dst_dir)
129 129
130 def GenerateDiffPatch(options, orig_file, new_file, patch_file): 130 def GenerateDiffPatch(options, orig_file, new_file, patch_file):
131 if (options.diff_algorithm == "COURGETTE"): 131 if (options.diff_algorithm == "COURGETTE"):
132 exe_file = os.path.join(options.last_chrome_installer, COURGETTE_EXEC) 132 exe_file = os.path.join(options.last_chrome_installer, COURGETTE_EXEC)
133 cmd = '%s -gen "%s" "%s" "%s"' % (exe_file, orig_file, new_file, patch_file) 133 cmd = '%s -gen "%s" "%s" "%s"' % (exe_file, orig_file, new_file, patch_file)
134 else: 134 else:
135 exe_file = os.path.join(options.build_dir, BSDIFF_EXEC) 135 exe_file = os.path.join(options.build_dir, BSDIFF_EXEC)
136 cmd = [exe_file, orig_file, new_file, patch_file,] 136 cmd = [exe_file, orig_file, new_file, patch_file,]
137 RunSystemCommand(cmd) 137 RunSystemCommand(cmd, options.verbose)
138 138
139 def GetLZMAExec(build_dir): 139 def GetLZMAExec(build_dir):
140 lzma_exec = os.path.join(build_dir, "..", "..", "third_party", 140 lzma_exec = os.path.join(build_dir, "..", "..", "third_party",
141 "lzma_sdk", "Executable", "7za.exe") 141 "lzma_sdk", "Executable", "7za.exe")
142 return lzma_exec 142 return lzma_exec
143 143
144 def GetPrevVersion(build_dir, temp_dir, last_chrome_installer, output_name): 144 def GetPrevVersion(build_dir, temp_dir, last_chrome_installer, output_name):
145 if not last_chrome_installer: 145 if not last_chrome_installer:
146 return '' 146 return ''
147 147
148 lzma_exec = GetLZMAExec(build_dir) 148 lzma_exec = GetLZMAExec(build_dir)
149 prev_archive_file = os.path.join(last_chrome_installer, 149 prev_archive_file = os.path.join(last_chrome_installer,
150 output_name + ARCHIVE_SUFFIX) 150 output_name + ARCHIVE_SUFFIX)
151 cmd = [lzma_exec, 151 cmd = [lzma_exec,
152 'x', 152 'x',
153 '-o"%s"' % temp_dir, 153 '-o"%s"' % temp_dir,
154 prev_archive_file, 154 prev_archive_file,
155 'Chrome-bin/*/chrome.dll',] 155 'Chrome-bin/*/chrome.dll',]
156 RunSystemCommand(cmd) 156 RunSystemCommand(cmd, options.verbose)
157 dll_path = glob.glob(os.path.join(temp_dir, 'Chrome-bin', '*', 'chrome.dll')) 157 dll_path = glob.glob(os.path.join(temp_dir, 'Chrome-bin', '*', 'chrome.dll'))
158 return os.path.split(os.path.split(dll_path[0])[0])[1] 158 return os.path.split(os.path.split(dll_path[0])[0])[1]
159 159
160 def MakeStagingDirectories(staging_dir): 160 def MakeStagingDirectories(staging_dir):
161 """Creates a staging path for installer archive. If directory exists already, 161 """Creates a staging path for installer archive. If directory exists already,
162 deletes the existing directory. 162 deletes the existing directory.
163 """ 163 """
164 file_path = os.path.join(staging_dir, TEMP_ARCHIVE_DIR) 164 file_path = os.path.join(staging_dir, TEMP_ARCHIVE_DIR)
165 if os.path.exists(file_path): 165 if os.path.exists(file_path):
166 shutil.rmtree(file_path) 166 shutil.rmtree(file_path)
(...skipping 10 matching lines...) Expand all
177 global variabes. 177 global variabes.
178 """ 178 """
179 variables = {} 179 variables = {}
180 variables['ChromeDir'] = CHROME_DIR 180 variables['ChromeDir'] = CHROME_DIR
181 variables['VersionDir'] = os.path.join(variables['ChromeDir'], 181 variables['VersionDir'] = os.path.join(variables['ChromeDir'],
182 current_version) 182 current_version)
183 config = ConfigParser.SafeConfigParser(variables) 183 config = ConfigParser.SafeConfigParser(variables)
184 config.read(input_file) 184 config.read(input_file)
185 return config 185 return config
186 186
187 def RunSystemCommand(cmd, **kw): 187 def RunSystemCommand(cmd, verbose):
188 print 'Running', cmd 188 """Runs |cmd|, prints the |cmd| and its output if |verbose|; otherwise
189 exit_code = subprocess.call(cmd, **kw) 189 captures its output and only emits it on failure.
190 if (exit_code != 0): 190 """
191 raise Exception("Error while running cmd: %s, exit_code: %s" % 191 if verbose:
192 (cmd, exit_code)) 192 print 'Running', cmd
193
194 try:
195 # Run |cmd|, redirecting stderr to stdout in order for captured errors to be
196 # inline with corresponding stdout.
197 output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
198 if verbose:
199 print output
200 except subprocess.CalledProcessError as e:
201 raise Exception("Error while running cmd: %s\n"
202 "Exit code: %s\n"
203 "Command output:\n%s" %
204 (e.cmd, e.returncode, e.output))
193 205
194 def CreateArchiveFile(options, staging_dir, current_version, prev_version): 206 def CreateArchiveFile(options, staging_dir, current_version, prev_version):
195 """Creates a new installer archive file after deleting any existing old file. 207 """Creates a new installer archive file after deleting any existing old file.
196 """ 208 """
197 # First create an uncompressed archive file for the current build (chrome.7z) 209 # First create an uncompressed archive file for the current build (chrome.7z)
198 lzma_exec = GetLZMAExec(options.build_dir) 210 lzma_exec = GetLZMAExec(options.build_dir)
199 archive_file = os.path.join(options.output_dir, 211 archive_file = os.path.join(options.output_dir,
200 options.output_name + ARCHIVE_SUFFIX) 212 options.output_name + ARCHIVE_SUFFIX)
201 if options.depfile: 213 if options.depfile:
202 # If a depfile was requested, do the glob of the staging dir and generate 214 # If a depfile was requested, do the glob of the staging dir and generate
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 250
239 cmd = [lzma_exec, 251 cmd = [lzma_exec,
240 'a', 252 'a',
241 '-t7z', 253 '-t7z',
242 archive_file, 254 archive_file,
243 os.path.join(staging_dir, CHROME_DIR), 255 os.path.join(staging_dir, CHROME_DIR),
244 '-mx0',] 256 '-mx0',]
245 # There doesnt seem to be any way in 7za.exe to override existing file so 257 # There doesnt seem to be any way in 7za.exe to override existing file so
246 # we always delete before creating a new one. 258 # we always delete before creating a new one.
247 if not os.path.exists(archive_file): 259 if not os.path.exists(archive_file):
248 RunSystemCommand(cmd) 260 RunSystemCommand(cmd, options.verbose)
249 elif options.skip_rebuild_archive != "true": 261 elif options.skip_rebuild_archive != "true":
250 os.remove(archive_file) 262 os.remove(archive_file)
251 RunSystemCommand(cmd) 263 RunSystemCommand(cmd, options.verbose)
252 264
253 # Do not compress the archive in developer (component) builds. 265 # Do not compress the archive in developer (component) builds.
254 if options.component_build == '1': 266 if options.component_build == '1':
255 compressed_file = os.path.join( 267 compressed_file = os.path.join(
256 options.output_dir, options.output_name + COMPRESSED_ARCHIVE_SUFFIX) 268 options.output_dir, options.output_name + COMPRESSED_ARCHIVE_SUFFIX)
257 if os.path.exists(compressed_file): 269 if os.path.exists(compressed_file):
258 os.remove(compressed_file) 270 os.remove(compressed_file)
259 return os.path.basename(archive_file) 271 return os.path.basename(archive_file)
260 272
261 # If we are generating a patch, run bsdiff against previous build and 273 # If we are generating a patch, run bsdiff against previous build and
262 # compress the resulting patch file. If this is not a patch just compress the 274 # compress the resulting patch file. If this is not a patch just compress the
263 # uncompressed archive file. 275 # uncompressed archive file.
264 patch_name_prefix = options.output_name + CHROME_PATCH_FILE_SUFFIX 276 patch_name_prefix = options.output_name + CHROME_PATCH_FILE_SUFFIX
265 if options.last_chrome_installer: 277 if options.last_chrome_installer:
266 prev_archive_file = os.path.join(options.last_chrome_installer, 278 prev_archive_file = os.path.join(options.last_chrome_installer,
267 options.output_name + ARCHIVE_SUFFIX) 279 options.output_name + ARCHIVE_SUFFIX)
268 patch_file = os.path.join(options.build_dir, patch_name_prefix + 280 patch_file = os.path.join(options.build_dir, patch_name_prefix +
269 PATCH_FILE_EXT) 281 PATCH_FILE_EXT)
270 GenerateDiffPatch(options, prev_archive_file, archive_file, patch_file) 282 GenerateDiffPatch(options, prev_archive_file, archive_file, patch_file)
271 compressed_archive_file = patch_name_prefix + '_' + \ 283 compressed_archive_file = patch_name_prefix + '_' + \
272 current_version + '_from_' + prev_version + \ 284 current_version + '_from_' + prev_version + \
273 COMPRESSED_FILE_EXT 285 COMPRESSED_FILE_EXT
274 orig_file = patch_file 286 orig_file = patch_file
275 else: 287 else:
276 compressed_archive_file = options.output_name + COMPRESSED_ARCHIVE_SUFFIX 288 compressed_archive_file = options.output_name + COMPRESSED_ARCHIVE_SUFFIX
277 orig_file = archive_file 289 orig_file = archive_file
278 290
279 compressed_archive_file_path = os.path.join(options.output_dir, 291 compressed_archive_file_path = os.path.join(options.output_dir,
280 compressed_archive_file) 292 compressed_archive_file)
281 CompressUsingLZMA(options.build_dir, compressed_archive_file_path, orig_file) 293 CompressUsingLZMA(options.build_dir, compressed_archive_file_path, orig_file,
294 options.verbose)
282 295
283 return compressed_archive_file 296 return compressed_archive_file
284 297
285 298
286 def PrepareSetupExec(options, current_version, prev_version): 299 def PrepareSetupExec(options, current_version, prev_version):
287 """Prepares setup.exe for bundling in mini_installer based on options.""" 300 """Prepares setup.exe for bundling in mini_installer based on options."""
288 if options.setup_exe_format == "FULL": 301 if options.setup_exe_format == "FULL":
289 setup_file = SETUP_EXEC 302 setup_file = SETUP_EXEC
290 elif options.setup_exe_format == "DIFF": 303 elif options.setup_exe_format == "DIFF":
291 if not options.last_chrome_installer: 304 if not options.last_chrome_installer:
292 raise Exception( 305 raise Exception(
293 "To use DIFF for setup.exe, --last_chrome_installer is needed.") 306 "To use DIFF for setup.exe, --last_chrome_installer is needed.")
294 prev_setup_file = os.path.join(options.last_chrome_installer, SETUP_EXEC) 307 prev_setup_file = os.path.join(options.last_chrome_installer, SETUP_EXEC)
295 new_setup_file = os.path.join(options.build_dir, SETUP_EXEC) 308 new_setup_file = os.path.join(options.build_dir, SETUP_EXEC)
296 patch_file = os.path.join(options.build_dir, SETUP_PATCH_FILE_PREFIX + 309 patch_file = os.path.join(options.build_dir, SETUP_PATCH_FILE_PREFIX +
297 PATCH_FILE_EXT) 310 PATCH_FILE_EXT)
298 GenerateDiffPatch(options, prev_setup_file, new_setup_file, patch_file) 311 GenerateDiffPatch(options, prev_setup_file, new_setup_file, patch_file)
299 setup_file = SETUP_PATCH_FILE_PREFIX + '_' + current_version + \ 312 setup_file = SETUP_PATCH_FILE_PREFIX + '_' + current_version + \
300 '_from_' + prev_version + COMPRESSED_FILE_EXT 313 '_from_' + prev_version + COMPRESSED_FILE_EXT
301 setup_file_path = os.path.join(options.build_dir, setup_file) 314 setup_file_path = os.path.join(options.build_dir, setup_file)
302 CompressUsingLZMA(options.build_dir, setup_file_path, patch_file) 315 CompressUsingLZMA(options.build_dir, setup_file_path, patch_file,
316 options.verbose)
303 else: 317 else:
304 cmd = ['makecab.exe', 318 cmd = ['makecab.exe',
305 '/D', 'CompressionType=LZX', 319 '/D', 'CompressionType=LZX',
306 '/V1', 320 '/V1',
307 '/L', options.output_dir, 321 '/L', options.output_dir,
308 os.path.join(options.build_dir, SETUP_EXEC),] 322 os.path.join(options.build_dir, SETUP_EXEC),]
309 # Send useless makecab progress on stdout to the bitbucket. 323 RunSystemCommand(cmd, options.verbose)
310 RunSystemCommand(cmd, stdout=open(os.devnull, "w"))
311 setup_file = SETUP_EXEC[:-1] + "_" 324 setup_file = SETUP_EXEC[:-1] + "_"
312 return setup_file 325 return setup_file
313 326
314 327
315 _RESOURCE_FILE_HEADER = """\ 328 _RESOURCE_FILE_HEADER = """\
316 // This file is automatically generated by create_installer_archive.py. 329 // This file is automatically generated by create_installer_archive.py.
317 // It contains the resource entries that are going to be linked inside 330 // It contains the resource entries that are going to be linked inside
318 // mini_installer.exe. For each file to be linked there should be two 331 // mini_installer.exe. For each file to be linked there should be two
319 // lines: 332 // lines:
320 // - The first line contains the output filename (without path) and the 333 // - The first line contains the output filename (without path) and the
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 help='Whether this archive is packaging a component build. This will ' 632 help='Whether this archive is packaging a component build. This will '
620 'also turn off compression of chrome.7z into chrome.packed.7z and ' 633 'also turn off compression of chrome.7z into chrome.packed.7z and '
621 'helpfully delete any old chrome.packed.7z in |output_dir|.') 634 'helpfully delete any old chrome.packed.7z in |output_dir|.')
622 parser.add_option('--depfile', 635 parser.add_option('--depfile',
623 help='Generate a depfile with the given name listing the implicit inputs ' 636 help='Generate a depfile with the given name listing the implicit inputs '
624 'to the archive process that can be used with a build system.') 637 'to the archive process that can be used with a build system.')
625 parser.add_option('--target_arch', default='x86', 638 parser.add_option('--target_arch', default='x86',
626 help='Specify the target architecture for installer - this is used ' 639 help='Specify the target architecture for installer - this is used '
627 'to determine which CRT runtime files to pull and package ' 640 'to determine which CRT runtime files to pull and package '
628 'with the installer archive {x86|x64}.') 641 'with the installer archive {x86|x64}.')
642 parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
643 default=False)
629 644
630 options, _ = parser.parse_args() 645 options, _ = parser.parse_args()
631 if not options.build_dir: 646 if not options.build_dir:
632 parser.error('You must provide a build dir.') 647 parser.error('You must provide a build dir.')
633 648
634 options.build_dir = os.path.normpath(options.build_dir) 649 options.build_dir = os.path.normpath(options.build_dir)
635 650
636 if not options.staging_dir: 651 if not options.staging_dir:
637 parser.error('You must provide a staging dir.') 652 parser.error('You must provide a staging dir.')
638 653
639 if not options.input_file: 654 if not options.input_file:
640 parser.error('You must provide an input file') 655 parser.error('You must provide an input file')
641 656
642 if not options.output_dir: 657 if not options.output_dir:
643 options.output_dir = options.build_dir 658 options.output_dir = options.build_dir
644 659
645 if not options.resource_file_path: 660 if not options.resource_file_path:
646 options.resource_file_path = os.path.join(options.build_dir, 661 options.resource_file_path = os.path.join(options.build_dir,
647 MINI_INSTALLER_INPUT_FILE) 662 MINI_INSTALLER_INPUT_FILE)
648 663
649 return options 664 return options
650 665
651 666
652 if '__main__' == __name__: 667 if '__main__' == __name__:
653 print sys.argv 668 options = _ParseOptions()
654 sys.exit(main(_ParseOptions())) 669 if options.verbose:
670 print sys.argv
671 sys.exit(main(options))
OLDNEW
« no previous file with comments | « chrome/installer/mini_installer/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698