Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 #include "chrome/installer/test/resource_updater.h" | 53 #include "chrome/installer/test/resource_updater.h" |
| 54 #include "chrome/installer/util/lzma_util.h" | 54 #include "chrome/installer/util/lzma_util.h" |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 const wchar_t k7zaExe[] = L"7za.exe"; | 58 const wchar_t k7zaExe[] = L"7za.exe"; |
| 59 const wchar_t k7zaPathRelative[] = L"..\\..\\third_party\\lzma_sdk\\Executable"; | 59 const wchar_t k7zaPathRelative[] = L"..\\..\\third_party\\lzma_sdk\\Executable"; |
| 60 const wchar_t kB7[] = L"B7"; | 60 const wchar_t kB7[] = L"B7"; |
| 61 const wchar_t kBl[] = L"BL"; | 61 const wchar_t kBl[] = L"BL"; |
| 62 const wchar_t kChromeBin[] = L"Chrome-bin"; | 62 const wchar_t kChromeBin[] = L"Chrome-bin"; |
| 63 const wchar_t kChromePacked7z[] = L"chrome.packed.7z"; | 63 const wchar_t kChromePacked7z[] = L"CHROME.PACKED.7Z"; |
| 64 const wchar_t kChrome7z[] = L"CHROME.7Z"; | |
| 64 const wchar_t kExe[] = L"exe"; | 65 const wchar_t kExe[] = L"exe"; |
| 65 const wchar_t kExpandExe[] = L"expand.exe"; | 66 const wchar_t kExpandExe[] = L"expand.exe"; |
| 66 const wchar_t kExtDll[] = L".dll"; | 67 const wchar_t kExtDll[] = L".dll"; |
| 67 const wchar_t kExtExe[] = L".exe"; | 68 const wchar_t kExtExe[] = L".exe"; |
| 68 const wchar_t kMakeCab[] = L"makecab.exe"; | 69 const wchar_t kMakeCab[] = L"makecab.exe"; |
| 69 const wchar_t kSetupEx_[] = L"setup.ex_"; | 70 const wchar_t kSetupEx_[] = L"setup.ex_"; |
| 70 const wchar_t kSetupExe[] = L"setup.exe"; | 71 const wchar_t kSetupExe[] = L"setup.exe"; |
| 71 const char kSwitch7zaPath[] = "7za_path"; | 72 const char kSwitch7zaPath[] = "7za_path"; |
| 72 const wchar_t kTempDirPrefix[] = L"mini_installer_test_temp"; | 73 const wchar_t kTempDirPrefix[] = L"mini_installer_test_temp"; |
| 73 | 74 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 explicit ChromeVersion(ULONGLONG value) : version_(value) { } | 124 explicit ChromeVersion(ULONGLONG value) : version_(value) { } |
| 124 WORD major() const { return static_cast<WORD>(version_ >> 48); } | 125 WORD major() const { return static_cast<WORD>(version_ >> 48); } |
| 125 WORD minor() const { return static_cast<WORD>(version_ >> 32); } | 126 WORD minor() const { return static_cast<WORD>(version_ >> 32); } |
| 126 WORD build() const { return static_cast<WORD>(version_ >> 16); } | 127 WORD build() const { return static_cast<WORD>(version_ >> 16); } |
| 127 WORD patch() const { return static_cast<WORD>(version_); } | 128 WORD patch() const { return static_cast<WORD>(version_); } |
| 128 DWORD high() const { return static_cast<DWORD>(version_ >> 32); } | 129 DWORD high() const { return static_cast<DWORD>(version_ >> 32); } |
| 129 DWORD low() const { return static_cast<DWORD>(version_); } | 130 DWORD low() const { return static_cast<DWORD>(version_); } |
| 130 ULONGLONG value() const { return version_; } | 131 ULONGLONG value() const { return version_; } |
| 131 void set_value(ULONGLONG value) { version_ = value; } | 132 void set_value(ULONGLONG value) { version_ = value; } |
| 132 std::wstring ToString() const; | 133 std::wstring ToString() const; |
| 134 std::string ToASCII() const; | |
| 135 | |
| 133 private: | 136 private: |
| 134 ULONGLONG version_; | 137 ULONGLONG version_; |
| 135 }; // class ChromeVersion | 138 }; // class ChromeVersion |
| 136 | 139 |
| 137 std::wstring ChromeVersion::ToString() const { | 140 std::wstring ChromeVersion::ToString() const { |
| 138 wchar_t buffer[24]; | 141 wchar_t buffer[24]; |
| 139 int string_len = | 142 int string_len = |
| 140 swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu", | 143 swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu", |
| 141 major(), minor(), build(), patch()); | 144 major(), minor(), build(), patch()); |
| 142 DCHECK_NE(-1, string_len); | 145 DCHECK_NE(-1, string_len); |
| 143 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); | 146 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); |
| 144 return std::wstring(&buffer[0], string_len); | 147 return std::wstring(&buffer[0], string_len); |
| 145 } | 148 } |
| 146 | 149 |
| 150 std::string ChromeVersion::ToASCII() const { | |
| 151 char buffer[24]; | |
| 152 int string_len = sprintf_s(&buffer[0], arraysize(buffer), "%hu.%hu.%hu.%hu", | |
| 153 major(), minor(), build(), patch()); | |
| 154 DCHECK_NE(-1, string_len); | |
| 155 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); | |
| 156 return std::string(&buffer[0], string_len); | |
| 157 } | |
| 147 | 158 |
| 148 // A read/write mapping of a file. | 159 // A read/write mapping of a file. |
| 149 // Note: base::MemoryMappedFile is not used because it doesn't support | 160 // Note: base::MemoryMappedFile is not used because it doesn't support |
| 150 // read/write mappings. Adding such support across all platforms for this | 161 // read/write mappings. Adding such support across all platforms for this |
| 151 // Windows-only test code seems like overkill. | 162 // Windows-only test code seems like overkill. |
| 152 class MappedFile { | 163 class MappedFile { |
| 153 public: | 164 public: |
| 154 MappedFile() : size_(), mapping_(), view_() { } | 165 MappedFile() : size_(), mapping_(), view_() { } |
| 155 ~MappedFile(); | 166 ~MappedFile(); |
| 156 bool Initialize(base::File file); | 167 bool Initialize(base::File file); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 | 281 |
| 271 // Retrieves the version number of setup.exe in |work_dir| from its version | 282 // Retrieves the version number of setup.exe in |work_dir| from its version |
| 272 // resource, placing the value in |version|. Returns true on success. | 283 // resource, placing the value in |version|. Returns true on success. |
| 273 bool GetSetupExeVersion(const base::FilePath& work_dir, | 284 bool GetSetupExeVersion(const base::FilePath& work_dir, |
| 274 ChromeVersion* version) { | 285 ChromeVersion* version) { |
| 275 return GetFileVersion(work_dir.Append(&kSetupExe[0]), version); | 286 return GetFileVersion(work_dir.Append(&kSetupExe[0]), version); |
| 276 } | 287 } |
| 277 | 288 |
| 278 | 289 |
| 279 // Replace all occurrences in the sequence [|dest_first|, |dest_last) that | 290 // Replace all occurrences in the sequence [|dest_first|, |dest_last) that |
| 280 // equals [|src_first|, |src_last) with the sequence at |replacement_first| of | 291 // equals [|src_first|, |src_last) with the sequence at |replacement_first| of |
|
gab
2016/01/25 21:00:12
existing nit : Missing | after "last" in both inst
grt (UTC plus 2)
2016/01/26 00:13:45
Done.
| |
| 281 // the same length. Returns true on success. If non-NULL, |replacements_made| | 292 // the same length. Returns true on success. If non-NULL, |replacements_made| |
|
gab
2016/01/25 21:00:12
Says |replacement_first| has to be the same length
grt (UTC plus 2)
2016/01/26 00:13:45
Correct. This is consistent with various C++ libra
| |
| 282 // is set to true/false accordingly. | 293 // is set to true/false accordingly. |
| 283 bool ReplaceAll(uint8_t* dest_first, | 294 bool ReplaceAll(uint8_t* dest_first, |
| 284 uint8_t* dest_last, | 295 uint8_t* dest_last, |
| 285 const uint8_t* src_first, | 296 const uint8_t* src_first, |
| 286 const uint8_t* src_last, | 297 const uint8_t* src_last, |
| 287 const uint8_t* replacement_first, | 298 const uint8_t* replacement_first, |
| 288 bool* replacements_made) { | 299 bool* replacements_made) { |
| 289 bool result = true; | 300 bool result = true; |
| 290 bool changed = false; | 301 bool changed = false; |
| 291 do { | 302 do { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 313 struct VisitResourceContext { | 324 struct VisitResourceContext { |
| 314 ChromeVersion current_version; | 325 ChromeVersion current_version; |
| 315 std::wstring current_version_str; | 326 std::wstring current_version_str; |
| 316 ChromeVersion new_version; | 327 ChromeVersion new_version; |
| 317 std::wstring new_version_str; | 328 std::wstring new_version_str; |
| 318 }; // struct VisitResourceContext | 329 }; // struct VisitResourceContext |
| 319 | 330 |
| 320 // Replaces the old version with the new in a resource. A first pass is made to | 331 // Replaces the old version with the new in a resource. A first pass is made to |
| 321 // replace the string form (e.g., "9.0.584.0"). If any replacements are made, a | 332 // replace the string form (e.g., "9.0.584.0"). If any replacements are made, a |
| 322 // second pass is made to replace the binary form (e.g., 0x0000024800000009). | 333 // second pass is made to replace the binary form (e.g., 0x0000024800000009). |
| 334 // A final pass is made to replace the ASCII string form. | |
| 323 void VisitResource(const upgrade_test::EntryPath& path, | 335 void VisitResource(const upgrade_test::EntryPath& path, |
| 324 uint8_t* data, | 336 uint8_t* data, |
| 325 DWORD size, | 337 DWORD size, |
| 326 DWORD code_page, | 338 DWORD code_page, |
| 327 uintptr_t context) { | 339 uintptr_t context) { |
| 328 VisitResourceContext& ctx = *reinterpret_cast<VisitResourceContext*>(context); | 340 VisitResourceContext& ctx = *reinterpret_cast<VisitResourceContext*>(context); |
| 329 | 341 |
| 330 // Replace all occurrences of current_version_str with new_version_str | 342 // Replace all occurrences of current_version_str with new_version_str |
| 331 bool changing_version = false; | 343 bool changing_version = false; |
| 332 if (ReplaceAll( | 344 if (ReplaceAll( |
| 333 data, data + size, | 345 data, data + size, |
| 334 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str()), | 346 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str()), |
| 335 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str() + | 347 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str() + |
| 336 ctx.current_version_str.size() + 1), | 348 ctx.current_version_str.size() + 1), |
| 337 reinterpret_cast<const uint8_t*>(ctx.new_version_str.c_str()), | 349 reinterpret_cast<const uint8_t*>(ctx.new_version_str.c_str()), |
| 338 &changing_version) && | 350 &changing_version) && |
| 339 changing_version) { | 351 changing_version) { |
| 340 // Replace all occurrences of current_version with new_version | 352 // Replace all binary occurrences of current_version with new_version. |
| 341 struct VersionPair { | 353 struct VersionPair { |
| 342 DWORD high; | 354 DWORD high; |
| 343 DWORD low; | 355 DWORD low; |
| 344 }; | 356 }; |
| 345 VersionPair cur_ver = { | 357 VersionPair cur_ver = { |
| 346 ctx.current_version.high(), ctx.current_version.low() | 358 ctx.current_version.high(), ctx.current_version.low() |
| 347 }; | 359 }; |
| 348 VersionPair new_ver = { | 360 VersionPair new_ver = { |
| 349 ctx.new_version.high(), ctx.new_version.low() | 361 ctx.new_version.high(), ctx.new_version.low() |
| 350 }; | 362 }; |
| 351 ReplaceAll(data, data + size, reinterpret_cast<const uint8_t*>(&cur_ver), | 363 ReplaceAll(data, data + size, reinterpret_cast<const uint8_t*>(&cur_ver), |
| 352 reinterpret_cast<const uint8_t*>(&cur_ver) + sizeof(cur_ver), | 364 reinterpret_cast<const uint8_t*>(&cur_ver) + sizeof(cur_ver), |
| 353 reinterpret_cast<const uint8_t*>(&new_ver), NULL); | 365 reinterpret_cast<const uint8_t*>(&new_ver), NULL); |
| 354 } | 366 } |
| 367 | |
| 368 // Replace all ASCII occurrences of current_version with new_version. | |
| 369 std::string old_version(ctx.current_version.ToASCII()); | |
|
gab
2016/01/25 21:00:12
s/old_version/current_version/ for consistency
grt (UTC plus 2)
2016/01/26 00:13:45
Done.
| |
| 370 std::string new_version(ctx.new_version.ToASCII()); | |
| 371 ReplaceAll(data, data + size, reinterpret_cast<uint8_t*>(&old_version[0]), | |
| 372 reinterpret_cast<uint8_t*>(&old_version[old_version.size()]), | |
| 373 reinterpret_cast<uint8_t*>(&new_version[0]), NULL); | |
| 355 } | 374 } |
| 356 | 375 |
| 357 // Updates the version strings and numbers in all of |image_file|'s resources. | 376 // Updates the version strings and numbers in all of |image_file|'s resources. |
| 358 bool UpdateVersionIfMatch(const base::FilePath& image_file, | 377 bool UpdateVersionIfMatch(const base::FilePath& image_file, |
| 359 VisitResourceContext* context) { | 378 VisitResourceContext* context) { |
| 360 if (!context || | 379 if (!context || |
| 361 context->current_version_str.size() < context->new_version_str.size()) { | 380 context->current_version_str.size() < context->new_version_str.size()) { |
| 362 return false; | 381 return false; |
| 363 } | 382 } |
| 364 | 383 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 391 } else { | 410 } else { |
| 392 result = true; | 411 result = true; |
| 393 } | 412 } |
| 394 } | 413 } |
| 395 } else { | 414 } else { |
| 396 PLOG(DFATAL) << "Failed to open \"" << image_file.value() << "\""; | 415 PLOG(DFATAL) << "Failed to open \"" << image_file.value() << "\""; |
| 397 } | 416 } |
| 398 return result; | 417 return result; |
| 399 } | 418 } |
| 400 | 419 |
| 420 bool UpdateManifestVersion(const base::FilePath& manifest, | |
| 421 VisitResourceContext* context) { | |
| 422 std::string contents; | |
| 423 if (!base::ReadFileToString(manifest, &contents)) | |
| 424 return false; | |
| 425 std::string old_version(context->current_version.ToASCII()); | |
| 426 std::string new_version(context->new_version.ToASCII()); | |
| 427 bool modified = false; | |
| 428 if (!ReplaceAll(reinterpret_cast<uint8_t*>(&contents[0]), | |
| 429 reinterpret_cast<uint8_t*>(&contents[contents.size()]), | |
| 430 reinterpret_cast<uint8_t*>(&old_version[0]), | |
| 431 reinterpret_cast<uint8_t*>(&old_version[old_version.size()]), | |
|
gab
2016/01/25 21:00:12
Would reinterpret_cast<uint8_t*>(old_version.end()
grt (UTC plus 2)
2016/01/26 00:13:45
I don't think so. While the iterator must act like
| |
| 432 reinterpret_cast<uint8_t*>(&new_version[0]), &modified)) { | |
| 433 return false; | |
| 434 } | |
| 435 DCHECK(modified); | |
| 436 return base::WriteFile(manifest, &contents[0], contents.size()) == | |
| 437 contents.size(); | |
| 438 } | |
| 439 | |
| 401 bool IncrementNewVersion(upgrade_test::Direction direction, | 440 bool IncrementNewVersion(upgrade_test::Direction direction, |
| 402 VisitResourceContext* ctx) { | 441 VisitResourceContext* ctx) { |
| 403 DCHECK(ctx); | 442 DCHECK(ctx); |
| 404 | 443 |
| 405 // Figure out a past or future version with the same string length as this one | 444 // Figure out a past or future version with the same string length as this one |
| 406 // by decrementing or incrementing each component. | 445 // by decrementing or incrementing each component. |
| 407 LONGLONG incrementer = (direction == upgrade_test::PREVIOUS_VERSION ? -1 : 1); | 446 LONGLONG incrementer = (direction == upgrade_test::PREVIOUS_VERSION ? -1 : 1); |
| 408 | 447 |
| 409 do { | 448 do { |
| 410 if (incrementer == 0) { | 449 if (incrementer == 0) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 break; | 485 break; |
| 447 } | 486 } |
| 448 std::wstring extension = file.Extension(); | 487 std::wstring extension = file.Extension(); |
| 449 if (extension == &kExtExe[0] || extension == &kExtDll[0]) { | 488 if (extension == &kExtExe[0] || extension == &kExtDll[0]) { |
| 450 doing_great = UpdateVersionIfMatch(file, &ctx); | 489 doing_great = UpdateVersionIfMatch(file, &ctx); |
| 451 } | 490 } |
| 452 } while (doing_great); | 491 } while (doing_great); |
| 453 | 492 |
| 454 // Change the versioned directory. | 493 // Change the versioned directory. |
| 455 base::FilePath chrome_bin = work_dir.Append(&kChromeBin[0]); | 494 base::FilePath chrome_bin = work_dir.Append(&kChromeBin[0]); |
| 456 doing_great = base::Move(chrome_bin.Append(ctx.current_version_str), | 495 if (doing_great) { |
|
gab
2016/01/25 21:00:12
If we don't do anything and just run to returning
grt (UTC plus 2)
2016/01/26 00:13:45
Good point. I probably wrote this when I was aller
| |
| 457 chrome_bin.Append(ctx.new_version_str)); | 496 doing_great = base::Move(chrome_bin.Append(ctx.current_version_str), |
| 497 chrome_bin.Append(ctx.new_version_str)); | |
| 498 } | |
| 499 | |
| 500 // Update the manifest. | |
| 501 base::FilePath current_manifest = | |
| 502 chrome_bin.Append(ctx.new_version_str) | |
| 503 .Append(ctx.current_version_str + L".manifest"); | |
|
gab
2016/01/25 21:00:12
Please link this CL to http://crbug.com/581133 whi
grt (UTC plus 2)
2016/01/26 00:13:45
Done.
| |
| 504 if (doing_great && base::PathExists(current_manifest)) { | |
| 505 base::FilePath new_manifest = | |
| 506 current_manifest.DirName().Append(ctx.new_version_str + L".manifest"); | |
| 507 doing_great = base::Move(current_manifest, new_manifest) && | |
| 508 UpdateManifestVersion(new_manifest, &ctx); | |
| 509 } | |
| 458 | 510 |
| 459 if (doing_great) { | 511 if (doing_great) { |
| 460 // Report the version numbers if requested. | 512 // Report the version numbers if requested. |
| 461 if (original_version != NULL) | 513 if (original_version != NULL) |
| 462 original_version->assign(ctx.current_version_str); | 514 original_version->assign(ctx.current_version_str); |
| 463 if (new_version != NULL) | 515 if (new_version != NULL) |
| 464 new_version->assign(ctx.new_version_str); | 516 new_version->assign(ctx.new_version_str); |
| 465 } | 517 } |
| 466 | 518 |
| 467 return doing_great; | 519 return doing_great; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 // Copy the original mini_installer. | 582 // Copy the original mini_installer. |
| 531 base::FilePath mini_installer = | 583 base::FilePath mini_installer = |
| 532 work_dir.directory().Append(original_installer_path.BaseName()); | 584 work_dir.directory().Append(original_installer_path.BaseName()); |
| 533 if (!base::CopyFile(original_installer_path, mini_installer)) { | 585 if (!base::CopyFile(original_installer_path, mini_installer)) { |
| 534 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value() | 586 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value() |
| 535 << "\" to \"" << mini_installer.value() << "\""; | 587 << "\" to \"" << mini_installer.value() << "\""; |
| 536 return false; | 588 return false; |
| 537 } | 589 } |
| 538 | 590 |
| 539 base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]); | 591 base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]); |
| 540 base::FilePath chrome_packed_7z = | 592 base::FilePath chrome_packed_7z; // Empty for component builds. |
| 541 work_dir.directory().Append(&kChromePacked7z[0]); | 593 base::FilePath chrome_7z; |
| 594 const wchar_t* archive_resource_name = nullptr; | |
| 595 base::FilePath* archive_file = nullptr; | |
| 542 // Load the original file and extract setup.ex_ and chrome.packed.7z | 596 // Load the original file and extract setup.ex_ and chrome.packed.7z |
| 543 { | 597 { |
| 544 ResourceLoader resource_loader; | 598 ResourceLoader resource_loader; |
| 545 std::pair<const uint8_t*, DWORD> resource_data; | 599 std::pair<const uint8_t*, DWORD> resource_data; |
| 546 | 600 |
| 547 if (!resource_loader.Initialize(mini_installer)) | 601 if (!resource_loader.Initialize(mini_installer)) |
| 548 return false; | 602 return false; |
| 549 | 603 |
| 550 // Write out setup.ex_ | 604 // Write out setup.ex_ |
| 551 if (!resource_loader.Load(&kSetupEx_[0], &kBl[0], &resource_data)) | 605 if (!resource_loader.Load(&kSetupEx_[0], &kBl[0], &resource_data)) |
| 552 return false; | 606 return false; |
| 553 int written = | 607 int written = |
| 554 base::WriteFile(setup_ex_, | 608 base::WriteFile(setup_ex_, |
| 555 reinterpret_cast<const char*>(resource_data.first), | 609 reinterpret_cast<const char*>(resource_data.first), |
| 556 static_cast<int>(resource_data.second)); | 610 static_cast<int>(resource_data.second)); |
| 557 if (written != static_cast<int>(resource_data.second)) { | 611 if (written != static_cast<int>(resource_data.second)) { |
| 558 LOG(DFATAL) << "Failed writing \"" << setup_ex_.value() << "\""; | 612 LOG(DFATAL) << "Failed writing \"" << setup_ex_.value() << "\""; |
| 559 return false; | 613 return false; |
| 560 } | 614 } |
| 561 | 615 |
| 562 // Write out chrome.packed.7z | 616 // Write out chrome.packed.7z (static build) or chrome.7z (component build) |
| 563 if (!resource_loader.Load(&kChromePacked7z[0], &kB7[0], &resource_data)) | 617 if (resource_loader.Load(&kChromePacked7z[0], &kB7[0], &resource_data)) { |
| 618 archive_resource_name = &kChromePacked7z[0]; | |
| 619 chrome_packed_7z = work_dir.directory().Append(archive_resource_name); | |
| 620 archive_file = &chrome_packed_7z; | |
| 621 } else if (resource_loader.Load(&kChrome7z[0], &kB7[0], &resource_data)) { | |
| 622 archive_resource_name = &kChrome7z[0]; | |
| 623 chrome_7z = work_dir.directory().Append(archive_resource_name); | |
| 624 archive_file = &chrome_7z; | |
| 625 } else { | |
| 564 return false; | 626 return false; |
| 565 written = | 627 } |
|
gab
2016/01/25 21:00:12
DCHECK(!archive_resource_name.empty());
DCHECK(!ch
grt (UTC plus 2)
2016/01/26 00:13:45
Done.
| |
| 566 base::WriteFile(chrome_packed_7z, | 628 written = base::WriteFile( |
| 567 reinterpret_cast<const char*>(resource_data.first), | 629 *archive_file, reinterpret_cast<const char*>(resource_data.first), |
| 568 static_cast<int>(resource_data.second)); | 630 static_cast<int>(resource_data.second)); |
| 569 if (written != static_cast<int>(resource_data.second)) { | 631 if (written != static_cast<int>(resource_data.second)) { |
| 570 LOG(DFATAL) << "Failed writing \"" << chrome_packed_7z.value() << "\""; | 632 LOG(DFATAL) << "Failed writing \"" << archive_file->value() << "\""; |
| 571 return false; | 633 return false; |
| 572 } | 634 } |
| 573 } | 635 } |
| 574 | 636 |
| 575 // Expand setup.ex_ | 637 // Expand setup.ex_ |
| 576 base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]); | 638 base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]); |
| 577 std::wstring command_line; | 639 std::wstring command_line; |
| 578 command_line.append(1, L'"') | 640 command_line.append(1, L'"') |
| 579 .append(&kExpandExe[0]) | 641 .append(&kExpandExe[0]) |
| 580 .append(L"\" \"") | 642 .append(L"\" \"") |
| 581 .append(setup_ex_.value()) | 643 .append(setup_ex_.value()) |
| 582 .append(L"\" \"") | 644 .append(L"\" \"") |
| 583 .append(setup_exe.value()) | 645 .append(setup_exe.value()) |
| 584 .append(1, L'\"'); | 646 .append(1, L'\"'); |
| 585 int exit_code; | 647 int exit_code; |
| 586 if (!RunProcessAndWait(NULL, command_line, &exit_code)) | 648 if (!RunProcessAndWait(NULL, command_line, &exit_code)) |
| 587 return false; | 649 return false; |
| 588 if (exit_code != 0) { | 650 if (exit_code != 0) { |
| 589 LOG(DFATAL) << &kExpandExe[0] << " exited with code " << exit_code; | 651 LOG(DFATAL) << &kExpandExe[0] << " exited with code " << exit_code; |
| 590 return false; | 652 return false; |
| 591 } | 653 } |
| 592 | 654 |
| 593 // Unpack chrome.packed.7z | 655 // Unpack chrome.packed.7z (static build only). |
| 594 std::wstring chrome_7z_name; | 656 if (!chrome_packed_7z.empty()) { |
| 595 if (LzmaUtil::UnPackArchive(chrome_packed_7z.value(), | 657 std::wstring chrome_7z_name; |
| 596 work_dir.directory().value(), | 658 if (LzmaUtil::UnPackArchive(chrome_packed_7z.value(), |
| 597 &chrome_7z_name) != NO_ERROR) { | 659 work_dir.directory().value(), |
| 598 LOG(DFATAL) << "Failed unpacking \"" << chrome_packed_7z.value() << "\""; | 660 &chrome_7z_name) != NO_ERROR) { |
| 599 return false; | 661 LOG(DFATAL) << "Failed unpacking \"" << chrome_packed_7z.value() << "\""; |
| 662 return false; | |
| 663 } | |
| 664 chrome_7z = base::FilePath(chrome_7z_name); | |
| 600 } | 665 } |
|
gab
2016/01/25 21:00:12
DCHECK(!chrome_7z.empty());
to document the expec
grt (UTC plus 2)
2016/01/26 00:13:45
Done.
| |
| 601 | 666 |
| 602 // Unpack chrome.7z | 667 // Unpack chrome.7z |
| 603 if (LzmaUtil::UnPackArchive(chrome_7z_name, work_dir.directory().value(), | 668 if (LzmaUtil::UnPackArchive(chrome_7z.value(), work_dir.directory().value(), |
| 604 NULL) != NO_ERROR) { | 669 NULL) != NO_ERROR) { |
| 605 LOG(DFATAL) << "Failed unpacking \"" << chrome_7z_name << "\""; | 670 LOG(DFATAL) << "Failed unpacking \"" << chrome_7z.value() << "\""; |
| 606 return false; | 671 return false; |
| 607 } | 672 } |
| 608 | 673 |
| 609 // Get rid of intermediate files | 674 // Get rid of intermediate files |
| 610 base::FilePath chrome_7z(chrome_7z_name); | |
| 611 if (!base::DeleteFile(chrome_7z, false) || | 675 if (!base::DeleteFile(chrome_7z, false) || |
| 612 !base::DeleteFile(chrome_packed_7z, false) || | 676 (!chrome_packed_7z.empty() && |
| 677 !base::DeleteFile(chrome_packed_7z, false)) || | |
| 613 !base::DeleteFile(setup_ex_, false)) { | 678 !base::DeleteFile(setup_ex_, false)) { |
| 614 LOG(DFATAL) << "Failed deleting intermediate files"; | 679 LOG(DFATAL) << "Failed deleting intermediate files"; |
| 615 return false; | 680 return false; |
| 616 } | 681 } |
| 617 | 682 |
| 618 // Increment the version in all files. | 683 // Increment the version in all files. |
| 619 ApplyAlternateVersion(work_dir.directory(), direction, original_version, | 684 ApplyAlternateVersion(work_dir.directory(), direction, original_version, |
| 620 new_version); | 685 new_version); |
| 621 | 686 |
| 622 // Pack up files into chrome.7z | 687 // Pack up files into chrome.7z |
| 623 if (!CreateArchive(chrome_7z, work_dir.directory().Append(&kChromeBin[0]), 0)) | 688 if (!CreateArchive(chrome_7z, work_dir.directory().Append(&kChromeBin[0]), 0)) |
| 624 return false; | 689 return false; |
| 625 | 690 |
| 626 // Compress chrome.7z into chrome.packed.7z | 691 // Compress chrome.7z into chrome.packed.7z for static builds. |
| 627 if (!CreateArchive(chrome_packed_7z, chrome_7z, 9)) | 692 if (!chrome_packed_7z.empty() && |
| 693 !CreateArchive(chrome_packed_7z, chrome_7z, 9)) { | |
| 628 return false; | 694 return false; |
| 695 } | |
| 629 | 696 |
| 630 // Compress setup.exe into setup.ex_ | 697 // Compress setup.exe into setup.ex_ |
| 631 command_line.assign(1, L'"') | 698 command_line.assign(1, L'"') |
| 632 .append(&kMakeCab[0]) | 699 .append(&kMakeCab[0]) |
| 633 .append(L"\" /D CompressionType=LZX /L \"") | 700 .append(L"\" /D CompressionType=LZX /L \"") |
| 634 .append(work_dir.directory().value()) | 701 .append(work_dir.directory().value()) |
| 635 .append(L"\" \"") | 702 .append(L"\" \"") |
| 636 .append(setup_exe.value()); | 703 .append(setup_exe.value()); |
| 637 if (!RunProcessAndWait(NULL, command_line, &exit_code)) | 704 if (!RunProcessAndWait(NULL, command_line, &exit_code)) |
| 638 return false; | 705 return false; |
| 639 if (exit_code != 0) { | 706 if (exit_code != 0) { |
| 640 LOG(DFATAL) << &kMakeCab[0] << " exited with code " << exit_code; | 707 LOG(DFATAL) << &kMakeCab[0] << " exited with code " << exit_code; |
| 641 return false; | 708 return false; |
| 642 } | 709 } |
| 643 | 710 |
| 644 // Replace the mini_installer's setup.ex_ and chrome.packed.7z resources. | 711 // Replace the mini_installer's setup.ex_ and chrome.packed.7z (or chrome.7z |
| 712 // in component builds) resources. | |
| 645 ResourceUpdater updater; | 713 ResourceUpdater updater; |
| 646 if (!updater.Initialize(mini_installer) || | 714 if (!updater.Initialize(mini_installer) || |
| 647 !updater.Update(&kSetupEx_[0], &kBl[0], | 715 !updater.Update(&kSetupEx_[0], &kBl[0], |
| 648 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), | 716 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), |
| 649 setup_ex_) || | 717 setup_ex_) || |
| 650 !updater.Update(&kChromePacked7z[0], &kB7[0], | 718 !updater.Update(archive_resource_name, &kB7[0], |
| 651 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), | 719 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), |
| 652 chrome_packed_7z) || | 720 *archive_file) || |
| 653 !updater.Commit()) { | 721 !updater.Commit()) { |
| 722 LOG(ERROR) << "It is common for this step to fail for very large resources," | |
| 723 " as is the case for Debug component=shared_library builds. " | |
| 724 "Try with a Release or component=static_library build."; | |
| 654 return false; | 725 return false; |
| 655 } | 726 } |
| 656 | 727 |
| 657 // Finally, move the updated mini_installer into place. | 728 // Finally, move the updated mini_installer into place. |
| 658 return base::Move(mini_installer, target_path); | 729 return base::Move(mini_installer, target_path); |
| 659 } | 730 } |
| 660 | 731 |
| 661 bool GenerateAlternatePEFileVersion(const base::FilePath& original_file, | 732 bool GenerateAlternatePEFileVersion(const base::FilePath& original_file, |
| 662 const base::FilePath& target_file, | 733 const base::FilePath& target_file, |
| 663 Direction direction) { | 734 Direction direction) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 return false; | 769 return false; |
| 699 } | 770 } |
| 700 ctx.current_version_str = ctx.current_version.ToString(); | 771 ctx.current_version_str = ctx.current_version.ToString(); |
| 701 ctx.new_version = ChromeVersion::FromString(version.GetString()); | 772 ctx.new_version = ChromeVersion::FromString(version.GetString()); |
| 702 ctx.new_version_str = ctx.new_version.ToString(); | 773 ctx.new_version_str = ctx.new_version.ToString(); |
| 703 | 774 |
| 704 return UpdateVersionIfMatch(target_file, &ctx); | 775 return UpdateVersionIfMatch(target_file, &ctx); |
| 705 } | 776 } |
| 706 | 777 |
| 707 } // namespace upgrade_test | 778 } // namespace upgrade_test |
| OLD | NEW |