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

Side by Side Diff: chrome/installer/test/alternate_version_generator.cc

Issue 6338020: Command-line tool to generate a newly versioned mini_installer.exe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The file contains the implementation of the mini_installer re-versioner. 5 // The file contains the implementation of the mini_installer re-versioner.
6 // The main function (GenerateNextVersion) does the following in a temp dir: 6 // The main function (GenerateNextVersion) does the following in a temp dir:
7 // - Extracts and unpacks setup.exe and the Chrome-bin folder from 7 // - Extracts and unpacks setup.exe and the Chrome-bin folder from
8 // mini_installer.exe. 8 // mini_installer.exe.
9 // - Inspects setup.exe to determine the current version. 9 // - Inspects setup.exe to determine the current version.
10 // - Runs through all .dll and .exe files: 10 // - Runs through all .dll and .exe files:
11 // - Replacing all occurrences of the Unicode version string in the files' 11 // - Replacing all occurrences of the Unicode version string in the files'
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } else { 336 } else {
337 result = true; 337 result = true;
338 } 338 }
339 } 339 }
340 } else { 340 } else {
341 PLOG(DFATAL) << "Failed to open \"" << image_file.value() << "\""; 341 PLOG(DFATAL) << "Failed to open \"" << image_file.value() << "\"";
342 } 342 }
343 return result; 343 return result;
344 } 344 }
345 345
346 // Bumps the version of all .exe and .dll files in |work_dir| as well as the 346 // Raises or lowers the version of all .exe and .dll files in |work_dir| as well
347 // |work-dir|\Chrome-bin\w.x.y.z directory. 347 // as the |work-dir|\Chrome-bin\w.x.y.z directory. |original_version| and
348 bool ApplyNextVersion(const FilePath& work_dir) { 348 // |new_version|, when non-NULL, are given the original and new version numbers
349 // on success.
350 bool ApplyAlternateVersion(const FilePath& work_dir,
351 upgrade_test::Direction direction,
352 std::wstring* original_version,
353 std::wstring* new_version) {
349 VisitResourceContext ctx; 354 VisitResourceContext ctx;
350 if (!GetSetupExeVersion(work_dir, &ctx.current_version)) { 355 if (!GetSetupExeVersion(work_dir, &ctx.current_version)) {
351 return false; 356 return false;
352 } 357 }
353 ctx.current_version_str = ctx.current_version.ToString(); 358 ctx.current_version_str = ctx.current_version.ToString();
354 359
355 // Figure out a future version with the same string length as this one by 360 // Figure out a past or future version with the same string length as this one
356 // incrementing each component. 361 // by decrementing or incrementing each component.
357 ULONGLONG incrementer = 1; 362 LONGLONG incrementer = (direction == upgrade_test::PREVIOUS_VERSION ? -1 : 1);
358 363
359 do { 364 do {
360 if (incrementer == 0) { 365 if (incrementer == 0) {
361 LOG(DFATAL) << "Improbable version composed of only 9s and/or USHRT_MAX"; 366 LOG(DFATAL) << "Improbable version at the cusp of complete rollover";
362 return false; 367 return false;
363 } 368 }
364 ctx.new_version.set_value(ctx.current_version.value() + incrementer); 369 ctx.new_version.set_value(ctx.current_version.value() + incrementer);
365 ctx.new_version_str = ctx.new_version.ToString(); 370 ctx.new_version_str = ctx.new_version.ToString();
366 incrementer <<= 16; 371 incrementer <<= 16;
367 } while (ctx.new_version_str.size() != ctx.current_version_str.size()); 372 } while (ctx.new_version_str.size() != ctx.current_version_str.size());
368 373
369 // Modify all .dll and .exe files with the current version. 374 // Modify all .dll and .exe files with the current version.
370 bool doing_great = true; 375 bool doing_great = true;
371 file_util::FileEnumerator all_files(work_dir, true, 376 file_util::FileEnumerator all_files(work_dir, true,
372 file_util::FileEnumerator::FILES); 377 file_util::FileEnumerator::FILES);
373 do { 378 do {
374 FilePath file = all_files.Next(); 379 FilePath file = all_files.Next();
375 if (file.empty()) { 380 if (file.empty()) {
376 break; 381 break;
377 } 382 }
378 std::wstring extension = file.Extension(); 383 std::wstring extension = file.Extension();
379 if (extension == &kExtExe[0] || extension == &kExtDll[0]) { 384 if (extension == &kExtExe[0] || extension == &kExtDll[0]) {
380 doing_great = UpdateVersionIfMatch(file, &ctx); 385 doing_great = UpdateVersionIfMatch(file, &ctx);
381 } 386 }
382 } while (doing_great); 387 } while (doing_great);
383 388
384 // Change the versioned directory. 389 // Change the versioned directory.
385 FilePath chrome_bin = work_dir.Append(&kChromeBin[0]); 390 FilePath chrome_bin = work_dir.Append(&kChromeBin[0]);
386 doing_great = file_util::Move(chrome_bin.Append(ctx.current_version_str), 391 doing_great = file_util::Move(chrome_bin.Append(ctx.current_version_str),
387 chrome_bin.Append(ctx.new_version_str)); 392 chrome_bin.Append(ctx.new_version_str));
388 393
394 if (doing_great) {
395 // Report the version numbers if requested.
396 if (original_version != NULL)
397 original_version->assign(ctx.current_version_str);
398 if (new_version != NULL)
399 new_version->assign(ctx.new_version_str);
400 }
401
389 return doing_great; 402 return doing_great;
390 } 403 }
391 404
392 // Returns the path to the directory holding the 7za executable. By default, it 405 // Returns the path to the directory holding the 7za executable. By default, it
393 // is assumed that the test resides in the tree's output directory, so the 406 // is assumed that the test resides in the tree's output directory, so the
394 // relative path "..\..\third_party\lzma_sdk\Executable" is applied to the host 407 // relative path "..\..\third_party\lzma_sdk\Executable" is applied to the host
395 // executable's directory. This can be overridden with the --7za_path 408 // executable's directory. This can be overridden with the --7za_path
396 // command-line switch. 409 // command-line switch.
397 FilePath Get7zaPath() { 410 FilePath Get7zaPath() {
398 FilePath l7za_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath( 411 FilePath l7za_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 << " while creating " << output_file.value(); 443 << " while creating " << output_file.value();
431 return false; 444 return false;
432 } 445 }
433 return true; 446 return true;
434 } 447 }
435 448
436 } // namespace 449 } // namespace
437 450
438 namespace upgrade_test { 451 namespace upgrade_test {
439 452
440 bool GenerateNextVersion(const FilePath& original_installer_path, 453 bool GenerateAlternateVersion(const FilePath& original_installer_path,
441 const FilePath& target_path) { 454 const FilePath& target_path,
455 Direction direction,
456 std::wstring* original_version,
457 std::wstring* new_version) {
442 // Create a temporary directory in which we'll do our work. 458 // Create a temporary directory in which we'll do our work.
443 ScopedTempDirectory work_dir; 459 ScopedTempDirectory work_dir;
444 if (!work_dir.Initialize()) 460 if (!work_dir.Initialize())
445 return false; 461 return false;
446 462
447 // Copy the original mini_installer. 463 // Copy the original mini_installer.
448 FilePath mini_installer = 464 FilePath mini_installer =
449 work_dir.directory().Append(original_installer_path.BaseName()); 465 work_dir.directory().Append(original_installer_path.BaseName());
450 if (!file_util::CopyFile(original_installer_path, mini_installer)) { 466 if (!file_util::CopyFile(original_installer_path, mini_installer)) {
451 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value() 467 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value()
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 // Get rid of intermediate files 541 // Get rid of intermediate files
526 FilePath chrome_7z(chrome_7z_name); 542 FilePath chrome_7z(chrome_7z_name);
527 if (!file_util::Delete(chrome_7z, false) || 543 if (!file_util::Delete(chrome_7z, false) ||
528 !file_util::Delete(chrome_packed_7z, false) || 544 !file_util::Delete(chrome_packed_7z, false) ||
529 !file_util::Delete(setup_ex_, false)) { 545 !file_util::Delete(setup_ex_, false)) {
530 LOG(DFATAL) << "Failed deleting intermediate files"; 546 LOG(DFATAL) << "Failed deleting intermediate files";
531 return false; 547 return false;
532 } 548 }
533 549
534 // Increment the version in all files. 550 // Increment the version in all files.
535 ApplyNextVersion(work_dir.directory()); 551 ApplyAlternateVersion(work_dir.directory(), direction, original_version,
552 new_version);
536 553
537 // Pack up files into chrome.7z 554 // Pack up files into chrome.7z
538 if (!CreateArchive(chrome_7z, work_dir.directory().Append(&kChromeBin[0]), 0)) 555 if (!CreateArchive(chrome_7z, work_dir.directory().Append(&kChromeBin[0]), 0))
539 return false; 556 return false;
540 557
541 // Compress chrome.7z into chrome.packed.7z 558 // Compress chrome.7z into chrome.packed.7z
542 if (!CreateArchive(chrome_packed_7z, chrome_7z, 9)) 559 if (!CreateArchive(chrome_packed_7z, chrome_7z, 9))
543 return false; 560 return false;
544 561
545 // Compress setup.exe into setup.ex_ 562 // Compress setup.exe into setup.ex_
(...skipping 21 matching lines...) Expand all
567 chrome_packed_7z) || 584 chrome_packed_7z) ||
568 !updater.Commit()) { 585 !updater.Commit()) {
569 return false; 586 return false;
570 } 587 }
571 588
572 // Finally, move the updated mini_installer into place. 589 // Finally, move the updated mini_installer into place.
573 return file_util::Move(mini_installer, target_path); 590 return file_util::Move(mini_installer, target_path);
574 } 591 }
575 592
576 } // namespace upgrade_test 593 } // namespace upgrade_test
OLDNEW
« no previous file with comments | « chrome/installer/test/alternate_version_generator.h ('k') | chrome/installer/test/alternate_version_generator_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698