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

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

Issue 1631903002: Add support for component builds in alternate_version_generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: string16 Created 4 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
« no previous file with comments | « no previous file | chrome/installer/test/resource_updater.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 25 matching lines...) Expand all
36 #include "base/command_line.h" 36 #include "base/command_line.h"
37 #include "base/files/file.h" 37 #include "base/files/file.h"
38 #include "base/files/file_enumerator.h" 38 #include "base/files/file_enumerator.h"
39 #include "base/files/file_path.h" 39 #include "base/files/file_path.h"
40 #include "base/files/file_util.h" 40 #include "base/files/file_util.h"
41 #include "base/logging.h" 41 #include "base/logging.h"
42 #include "base/macros.h" 42 #include "base/macros.h"
43 #include "base/path_service.h" 43 #include "base/path_service.h"
44 #include "base/process/launch.h" 44 #include "base/process/launch.h"
45 #include "base/process/process_handle.h" 45 #include "base/process/process_handle.h"
46 #include "base/strings/string16.h"
46 #include "base/strings/string_util.h" 47 #include "base/strings/string_util.h"
47 #include "base/strings/utf_string_conversions.h" 48 #include "base/strings/utf_string_conversions.h"
48 #include "base/version.h" 49 #include "base/version.h"
49 #include "base/win/pe_image.h" 50 #include "base/win/pe_image.h"
50 #include "base/win/scoped_handle.h" 51 #include "base/win/scoped_handle.h"
51 #include "chrome/installer/test/pe_image_resources.h" 52 #include "chrome/installer/test/pe_image_resources.h"
52 #include "chrome/installer/test/resource_loader.h" 53 #include "chrome/installer/test/resource_loader.h"
53 #include "chrome/installer/test/resource_updater.h" 54 #include "chrome/installer/test/resource_updater.h"
54 #include "chrome/installer/util/lzma_util.h" 55 #include "chrome/installer/util/lzma_util.h"
55 56
56 namespace { 57 namespace {
57 58
58 const wchar_t k7zaExe[] = L"7za.exe"; 59 const wchar_t k7zaExe[] = L"7za.exe";
59 const wchar_t k7zaPathRelative[] = L"..\\..\\third_party\\lzma_sdk\\Executable"; 60 const wchar_t k7zaPathRelative[] = L"..\\..\\third_party\\lzma_sdk\\Executable";
60 const wchar_t kB7[] = L"B7"; 61 const wchar_t kB7[] = L"B7";
61 const wchar_t kBl[] = L"BL"; 62 const wchar_t kBl[] = L"BL";
62 const wchar_t kChromeBin[] = L"Chrome-bin"; 63 const wchar_t kChromeBin[] = L"Chrome-bin";
63 const wchar_t kChromePacked7z[] = L"chrome.packed.7z"; 64 const wchar_t kChromePacked7z[] = L"CHROME.PACKED.7Z";
65 const wchar_t kChrome7z[] = L"CHROME.7Z";
64 const wchar_t kExe[] = L"exe"; 66 const wchar_t kExe[] = L"exe";
65 const wchar_t kExpandExe[] = L"expand.exe"; 67 const wchar_t kExpandExe[] = L"expand.exe";
66 const wchar_t kExtDll[] = L".dll"; 68 const wchar_t kExtDll[] = L".dll";
67 const wchar_t kExtExe[] = L".exe"; 69 const wchar_t kExtExe[] = L".exe";
68 const wchar_t kMakeCab[] = L"makecab.exe"; 70 const wchar_t kMakeCab[] = L"makecab.exe";
69 const wchar_t kSetupEx_[] = L"setup.ex_"; 71 const wchar_t kSetupEx_[] = L"setup.ex_";
70 const wchar_t kSetupExe[] = L"setup.exe"; 72 const wchar_t kSetupExe[] = L"setup.exe";
71 const char kSwitch7zaPath[] = "7za_path"; 73 const char kSwitch7zaPath[] = "7za_path";
72 const wchar_t kTempDirPrefix[] = L"mini_installer_test_temp"; 74 const wchar_t kTempDirPrefix[] = L"mini_installer_test_temp";
73 75
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 explicit ChromeVersion(ULONGLONG value) : version_(value) { } 125 explicit ChromeVersion(ULONGLONG value) : version_(value) { }
124 WORD major() const { return static_cast<WORD>(version_ >> 48); } 126 WORD major() const { return static_cast<WORD>(version_ >> 48); }
125 WORD minor() const { return static_cast<WORD>(version_ >> 32); } 127 WORD minor() const { return static_cast<WORD>(version_ >> 32); }
126 WORD build() const { return static_cast<WORD>(version_ >> 16); } 128 WORD build() const { return static_cast<WORD>(version_ >> 16); }
127 WORD patch() const { return static_cast<WORD>(version_); } 129 WORD patch() const { return static_cast<WORD>(version_); }
128 DWORD high() const { return static_cast<DWORD>(version_ >> 32); } 130 DWORD high() const { return static_cast<DWORD>(version_ >> 32); }
129 DWORD low() const { return static_cast<DWORD>(version_); } 131 DWORD low() const { return static_cast<DWORD>(version_); }
130 ULONGLONG value() const { return version_; } 132 ULONGLONG value() const { return version_; }
131 void set_value(ULONGLONG value) { version_ = value; } 133 void set_value(ULONGLONG value) { version_ = value; }
132 std::wstring ToString() const; 134 std::wstring ToString() const;
135 std::string ToASCII() const;
136
133 private: 137 private:
134 ULONGLONG version_; 138 ULONGLONG version_;
135 }; // class ChromeVersion 139 }; // class ChromeVersion
136 140
137 std::wstring ChromeVersion::ToString() const { 141 std::wstring ChromeVersion::ToString() const {
138 wchar_t buffer[24]; 142 wchar_t buffer[24];
139 int string_len = 143 int string_len =
140 swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu", 144 swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu",
141 major(), minor(), build(), patch()); 145 major(), minor(), build(), patch());
142 DCHECK_NE(-1, string_len); 146 DCHECK_NE(-1, string_len);
143 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); 147 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len);
144 return std::wstring(&buffer[0], string_len); 148 return std::wstring(&buffer[0], string_len);
145 } 149 }
146 150
151 std::string ChromeVersion::ToASCII() const {
152 char buffer[24];
153 int string_len = sprintf_s(&buffer[0], arraysize(buffer), "%hu.%hu.%hu.%hu",
154 major(), minor(), build(), patch());
155 DCHECK_NE(-1, string_len);
156 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len);
157 return std::string(&buffer[0], string_len);
158 }
147 159
148 // A read/write mapping of a file. 160 // A read/write mapping of a file.
149 // Note: base::MemoryMappedFile is not used because it doesn't support 161 // Note: base::MemoryMappedFile is not used because it doesn't support
150 // read/write mappings. Adding such support across all platforms for this 162 // read/write mappings. Adding such support across all platforms for this
151 // Windows-only test code seems like overkill. 163 // Windows-only test code seems like overkill.
152 class MappedFile { 164 class MappedFile {
153 public: 165 public:
154 MappedFile() : size_(), mapping_(), view_() { } 166 MappedFile() : size_(), mapping_(), view_() { }
155 ~MappedFile(); 167 ~MappedFile();
156 bool Initialize(base::File file); 168 bool Initialize(base::File file);
157 void* data() const { return view_; } 169 void* data() const { return view_; }
158 size_t size() const { return size_; } 170 size_t size() const { return size_; }
159 171
160 private: 172 private:
161 size_t size_; 173 size_t size_;
162 base::File file_; 174 base::File file_;
163 HANDLE mapping_; 175 HANDLE mapping_;
164 void* view_; 176 void* view_;
165 DISALLOW_COPY_AND_ASSIGN(MappedFile); 177 DISALLOW_COPY_AND_ASSIGN(MappedFile);
166 }; // class MappedFile 178 }; // class MappedFile
167 179
168 MappedFile::~MappedFile() { 180 MappedFile::~MappedFile() {
169 if (view_ != NULL) { 181 if (view_ && !UnmapViewOfFile(view_))
170 if (UnmapViewOfFile(view_) == 0) { 182 PLOG(DFATAL) << "MappedFile failed to unmap view.";
171 PLOG(DFATAL) << "MappedFile failed to unmap view."; 183 if (mapping_ && !CloseHandle(mapping_))
172 } 184 PLOG(DFATAL) << "Could not close file mapping handle.";
173 }
174 if (mapping_ != NULL) {
175 if (CloseHandle(mapping_) == 0) {
176 PLOG(DFATAL) << "Could not close file mapping handle.";
177 }
178 }
179 } 185 }
180 186
181 bool MappedFile::Initialize(base::File file) { 187 bool MappedFile::Initialize(base::File file) {
182 DCHECK(mapping_ == NULL); 188 DCHECK(mapping_ == NULL);
183 bool result = false; 189 bool result = false;
184 base::File::Info file_info; 190 base::File::Info file_info;
185 191
186 if (file.GetInfo(&file_info)) { 192 if (file.GetInfo(&file_info)) {
187 if (file_info.size <= 193 if (file_info.size <=
188 static_cast<int64_t>(std::numeric_limits<DWORD>::max())) { 194 static_cast<int64_t>(std::numeric_limits<DWORD>::max())) {
189 mapping_ = CreateFileMapping(file.GetPlatformFile(), NULL, PAGE_READWRITE, 195 mapping_ = CreateFileMapping(file.GetPlatformFile(), NULL, PAGE_READWRITE,
190 0, static_cast<DWORD>(file_info.size), NULL); 196 0, static_cast<DWORD>(file_info.size), NULL);
191 if (mapping_ != NULL) { 197 if (mapping_ != NULL) {
192 view_ = MapViewOfFile(mapping_, FILE_MAP_WRITE, 0, 0, 198 view_ = MapViewOfFile(mapping_, FILE_MAP_WRITE, 0, 0,
193 static_cast<size_t>(file_info.size)); 199 static_cast<size_t>(file_info.size));
194 if (view_ != NULL) { 200 if (view_)
195 result = true; 201 result = true;
196 } else { 202 else
197 PLOG(DFATAL) << "MapViewOfFile failed"; 203 PLOG(DFATAL) << "MapViewOfFile failed";
198 }
199 } else { 204 } else {
200 PLOG(DFATAL) << "CreateFileMapping failed"; 205 PLOG(DFATAL) << "CreateFileMapping failed";
201 } 206 }
202 } else { 207 } else {
203 LOG(DFATAL) << "Files larger than " << std::numeric_limits<DWORD>::max() 208 LOG(DFATAL) << "Files larger than " << std::numeric_limits<DWORD>::max()
204 << " are not supported."; 209 << " are not supported.";
205 } 210 }
206 } else { 211 } else {
207 PLOG(DFATAL) << "file.GetInfo failed"; 212 PLOG(DFATAL) << "file.GetInfo failed";
208 } 213 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return result; 273 return result;
269 } 274 }
270 275
271 // Retrieves the version number of setup.exe in |work_dir| from its version 276 // Retrieves the version number of setup.exe in |work_dir| from its version
272 // resource, placing the value in |version|. Returns true on success. 277 // resource, placing the value in |version|. Returns true on success.
273 bool GetSetupExeVersion(const base::FilePath& work_dir, 278 bool GetSetupExeVersion(const base::FilePath& work_dir,
274 ChromeVersion* version) { 279 ChromeVersion* version) {
275 return GetFileVersion(work_dir.Append(&kSetupExe[0]), version); 280 return GetFileVersion(work_dir.Append(&kSetupExe[0]), version);
276 } 281 }
277 282
278 283 // Replace all occurrences in the sequence [|dest_first|, |dest_last|) that
279 // Replace all occurrences in the sequence [|dest_first|, |dest_last) that 284 // equals [|src_first|, |src_last|) with the sequence at |replacement_first| of
280 // equals [|src_first|, |src_last) with the sequence at |replacement_first| of
281 // the same length. Returns true on success. If non-NULL, |replacements_made| 285 // the same length. Returns true on success. If non-NULL, |replacements_made|
282 // is set to true/false accordingly. 286 // is set to true/false accordingly.
283 bool ReplaceAll(uint8_t* dest_first, 287 bool ReplaceAll(uint8_t* dest_first,
284 uint8_t* dest_last, 288 uint8_t* dest_last,
285 const uint8_t* src_first, 289 const uint8_t* src_first,
286 const uint8_t* src_last, 290 const uint8_t* src_last,
287 const uint8_t* replacement_first, 291 const uint8_t* replacement_first,
288 bool* replacements_made) { 292 bool* replacements_made) {
289 bool result = true; 293 bool result = true;
290 bool changed = false; 294 bool changed = false;
291 do { 295 do {
292 dest_first = std::search(dest_first, dest_last, src_first, src_last); 296 dest_first = std::search(dest_first, dest_last, src_first, src_last);
293 if (dest_first == dest_last) { 297 if (dest_first == dest_last)
294 break; 298 break;
295 }
296 changed = true; 299 changed = true;
297 if (memcpy_s(dest_first, dest_last - dest_first, 300 if (memcpy_s(dest_first, dest_last - dest_first,
298 replacement_first, src_last - src_first) != 0) { 301 replacement_first, src_last - src_first) != 0) {
299 result = false; 302 result = false;
300 break; 303 break;
301 } 304 }
302 dest_first += (src_last - src_first); 305 dest_first += (src_last - src_first);
303 } while (true); 306 } while (true);
304 307
305 if (replacements_made != NULL) { 308 if (replacements_made != NULL)
306 *replacements_made = changed; 309 *replacements_made = changed;
307 }
308 310
309 return result; 311 return result;
310 } 312 }
311 313
312 // A context structure in support of our EnumResource_Fn callback. 314 // A context structure in support of our EnumResource_Fn callback.
313 struct VisitResourceContext { 315 struct VisitResourceContext {
314 ChromeVersion current_version; 316 ChromeVersion current_version;
315 std::wstring current_version_str; 317 std::wstring current_version_str;
316 ChromeVersion new_version; 318 ChromeVersion new_version;
317 std::wstring new_version_str; 319 std::wstring new_version_str;
318 }; // struct VisitResourceContext 320 }; // struct VisitResourceContext
319 321
320 // Replaces the old version with the new in a resource. A first pass is made to 322 // 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 323 // 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). 324 // second pass is made to replace the binary form (e.g., 0x0000024800000009).
325 // A final pass is made to replace the ASCII string form.
323 void VisitResource(const upgrade_test::EntryPath& path, 326 void VisitResource(const upgrade_test::EntryPath& path,
324 uint8_t* data, 327 uint8_t* data,
325 DWORD size, 328 DWORD size,
326 DWORD code_page, 329 DWORD code_page,
327 uintptr_t context) { 330 uintptr_t context) {
328 VisitResourceContext& ctx = *reinterpret_cast<VisitResourceContext*>(context); 331 VisitResourceContext& ctx = *reinterpret_cast<VisitResourceContext*>(context);
329 332
330 // Replace all occurrences of current_version_str with new_version_str 333 // Replace all occurrences of current_version_str with new_version_str
331 bool changing_version = false; 334 bool changing_version = false;
332 if (ReplaceAll( 335 if (ReplaceAll(
333 data, data + size, 336 data, data + size,
334 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str()), 337 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str()),
335 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str() + 338 reinterpret_cast<const uint8_t*>(ctx.current_version_str.c_str() +
336 ctx.current_version_str.size() + 1), 339 ctx.current_version_str.size() + 1),
337 reinterpret_cast<const uint8_t*>(ctx.new_version_str.c_str()), 340 reinterpret_cast<const uint8_t*>(ctx.new_version_str.c_str()),
338 &changing_version) && 341 &changing_version) &&
339 changing_version) { 342 changing_version) {
340 // Replace all occurrences of current_version with new_version 343 // Replace all binary occurrences of current_version with new_version.
341 struct VersionPair { 344 struct VersionPair {
342 DWORD high; 345 DWORD high;
343 DWORD low; 346 DWORD low;
344 }; 347 };
345 VersionPair cur_ver = { 348 VersionPair cur_ver = {
346 ctx.current_version.high(), ctx.current_version.low() 349 ctx.current_version.high(), ctx.current_version.low()
347 }; 350 };
348 VersionPair new_ver = { 351 VersionPair new_ver = {
349 ctx.new_version.high(), ctx.new_version.low() 352 ctx.new_version.high(), ctx.new_version.low()
350 }; 353 };
351 ReplaceAll(data, data + size, reinterpret_cast<const uint8_t*>(&cur_ver), 354 ReplaceAll(data, data + size, reinterpret_cast<const uint8_t*>(&cur_ver),
352 reinterpret_cast<const uint8_t*>(&cur_ver) + sizeof(cur_ver), 355 reinterpret_cast<const uint8_t*>(&cur_ver) + sizeof(cur_ver),
353 reinterpret_cast<const uint8_t*>(&new_ver), NULL); 356 reinterpret_cast<const uint8_t*>(&new_ver), NULL);
354 } 357 }
358
359 // Replace all ASCII occurrences of current_version with new_version.
360 std::string current_version(ctx.current_version.ToASCII());
361 std::string new_version(ctx.new_version.ToASCII());
362 ReplaceAll(
363 data, data + size, reinterpret_cast<uint8_t*>(&current_version[0]),
364 reinterpret_cast<uint8_t*>(&current_version[current_version.size()]),
365 reinterpret_cast<uint8_t*>(&new_version[0]), NULL);
355 } 366 }
356 367
357 // Updates the version strings and numbers in all of |image_file|'s resources. 368 // Updates the version strings and numbers in all of |image_file|'s resources.
358 bool UpdateVersionIfMatch(const base::FilePath& image_file, 369 bool UpdateVersionIfMatch(const base::FilePath& image_file,
359 VisitResourceContext* context) { 370 VisitResourceContext* context) {
360 if (!context || 371 if (!context ||
361 context->current_version_str.size() < context->new_version_str.size()) { 372 context->current_version_str.size() < context->new_version_str.size()) {
362 return false; 373 return false;
363 } 374 }
364 375
(...skipping 26 matching lines...) Expand all
391 } else { 402 } else {
392 result = true; 403 result = true;
393 } 404 }
394 } 405 }
395 } else { 406 } else {
396 PLOG(DFATAL) << "Failed to open \"" << image_file.value() << "\""; 407 PLOG(DFATAL) << "Failed to open \"" << image_file.value() << "\"";
397 } 408 }
398 return result; 409 return result;
399 } 410 }
400 411
412 bool UpdateManifestVersion(const base::FilePath& manifest,
413 VisitResourceContext* context) {
414 std::string contents;
415 if (!base::ReadFileToString(manifest, &contents))
416 return false;
417 std::string old_version(context->current_version.ToASCII());
418 std::string new_version(context->new_version.ToASCII());
419 bool modified = false;
420 if (!ReplaceAll(reinterpret_cast<uint8_t*>(&contents[0]),
421 reinterpret_cast<uint8_t*>(&contents[contents.size()]),
422 reinterpret_cast<uint8_t*>(&old_version[0]),
423 reinterpret_cast<uint8_t*>(&old_version[old_version.size()]),
424 reinterpret_cast<uint8_t*>(&new_version[0]), &modified)) {
425 return false;
426 }
427 DCHECK(modified);
428 return base::WriteFile(manifest, &contents[0], contents.size()) ==
429 contents.size();
430 }
431
401 bool IncrementNewVersion(upgrade_test::Direction direction, 432 bool IncrementNewVersion(upgrade_test::Direction direction,
402 VisitResourceContext* ctx) { 433 VisitResourceContext* ctx) {
403 DCHECK(ctx); 434 DCHECK(ctx);
404 435
405 // Figure out a past or future version with the same string length as this one 436 // Figure out a past or future version with the same string length as this one
406 // by decrementing or incrementing each component. 437 // by decrementing or incrementing each component.
407 LONGLONG incrementer = (direction == upgrade_test::PREVIOUS_VERSION ? -1 : 1); 438 LONGLONG incrementer = (direction == upgrade_test::PREVIOUS_VERSION ? -1 : 1);
408 439
409 do { 440 do {
410 if (incrementer == 0) { 441 if (incrementer == 0) {
411 LOG(DFATAL) << "Improbable version at the cusp of complete rollover"; 442 LOG(DFATAL) << "Improbable version at the cusp of complete rollover";
412 return false; 443 return false;
413 } 444 }
414 ctx->new_version.set_value(ctx->current_version.value() + incrementer); 445 ctx->new_version.set_value(ctx->current_version.value() + incrementer);
415 ctx->new_version_str = ctx->new_version.ToString(); 446 ctx->new_version_str = ctx->new_version.ToString();
416 incrementer <<= 16; 447 incrementer <<= 16;
417 } while (ctx->new_version_str.size() != ctx->current_version_str.size()); 448 } while (ctx->new_version_str.size() != ctx->current_version_str.size());
418 449
419 return true; 450 return true;
420 } 451 }
421 452
422 // Raises or lowers the version of all .exe and .dll files in |work_dir| as well 453 // Raises or lowers the version of all .exe and .dll files in |work_dir| as well
423 // as the |work-dir|\Chrome-bin\w.x.y.z directory. |original_version| and 454 // as the |work-dir|\Chrome-bin\w.x.y.z directory. |original_version| and
424 // |new_version|, when non-NULL, are given the original and new version numbers 455 // |new_version|, when non-null, are given the original and new version numbers
425 // on success. 456 // on success.
426 bool ApplyAlternateVersion(const base::FilePath& work_dir, 457 bool ApplyAlternateVersion(const base::FilePath& work_dir,
427 upgrade_test::Direction direction, 458 upgrade_test::Direction direction,
428 std::wstring* original_version, 459 std::wstring* original_version,
429 std::wstring* new_version) { 460 std::wstring* new_version) {
430 VisitResourceContext ctx; 461 VisitResourceContext ctx;
431 if (!GetSetupExeVersion(work_dir, &ctx.current_version)) { 462 if (!GetSetupExeVersion(work_dir, &ctx.current_version))
432 return false; 463 return false;
433 }
434 ctx.current_version_str = ctx.current_version.ToString(); 464 ctx.current_version_str = ctx.current_version.ToString();
435 465
436 if (!IncrementNewVersion(direction, &ctx)) { 466 if (!IncrementNewVersion(direction, &ctx))
467 return false;
468
469 // Modify all .dll and .exe files with the current version.
470 base::FileEnumerator all_files(work_dir, true, base::FileEnumerator::FILES);
471 while (true) {
472 base::FilePath file = all_files.Next();
473 if (file.empty())
474 break;
475 std::wstring extension = file.Extension();
476 if ((extension == &kExtExe[0] || extension == &kExtDll[0]) &&
477 !UpdateVersionIfMatch(file, &ctx)) {
478 return false;
479 }
480 }
481
482 // Change the versioned directory.
483 base::FilePath chrome_bin = work_dir.Append(&kChromeBin[0]);
484 if (!base::Move(chrome_bin.Append(ctx.current_version_str),
485 chrome_bin.Append(ctx.new_version_str))) {
437 return false; 486 return false;
438 } 487 }
439 488
440 // Modify all .dll and .exe files with the current version. 489 // Update the manifest (revise post-XP; see https://crbug.com/581133).
441 bool doing_great = true; 490 base::FilePath current_manifest =
442 base::FileEnumerator all_files(work_dir, true, base::FileEnumerator::FILES); 491 chrome_bin.Append(ctx.new_version_str)
443 do { 492 .Append(ctx.current_version_str + L".manifest");
444 base::FilePath file = all_files.Next(); 493 if (base::PathExists(current_manifest)) {
445 if (file.empty()) { 494 base::FilePath new_manifest =
446 break; 495 current_manifest.DirName().Append(ctx.new_version_str + L".manifest");
496 if (!base::Move(current_manifest, new_manifest) ||
497 !UpdateManifestVersion(new_manifest, &ctx)) {
498 return false;
447 } 499 }
448 std::wstring extension = file.Extension();
449 if (extension == &kExtExe[0] || extension == &kExtDll[0]) {
450 doing_great = UpdateVersionIfMatch(file, &ctx);
451 }
452 } while (doing_great);
453
454 // Change the versioned directory.
455 base::FilePath chrome_bin = work_dir.Append(&kChromeBin[0]);
456 doing_great = base::Move(chrome_bin.Append(ctx.current_version_str),
457 chrome_bin.Append(ctx.new_version_str));
458
459 if (doing_great) {
460 // Report the version numbers if requested.
461 if (original_version != NULL)
462 original_version->assign(ctx.current_version_str);
463 if (new_version != NULL)
464 new_version->assign(ctx.new_version_str);
465 } 500 }
466 501
467 return doing_great; 502 // Report the version numbers if requested.
503 if (original_version)
504 original_version->assign(ctx.current_version_str);
505 if (new_version)
506 new_version->assign(ctx.new_version_str);
507
508 return true;
468 } 509 }
469 510
470 // Returns the path to the directory holding the 7za executable. By default, it 511 // Returns the path to the directory holding the 7za executable. By default, it
471 // is assumed that the test resides in the tree's output directory, so the 512 // is assumed that the test resides in the tree's output directory, so the
472 // relative path "..\..\third_party\lzma_sdk\Executable" is applied to the host 513 // relative path "..\..\third_party\lzma_sdk\Executable" is applied to the host
473 // executable's directory. This can be overridden with the --7za_path 514 // executable's directory. This can be overridden with the --7za_path
474 // command-line switch. 515 // command-line switch.
475 base::FilePath Get7zaPath() { 516 base::FilePath Get7zaPath() {
476 base::FilePath l7za_path = 517 base::FilePath l7za_path =
477 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( 518 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // Copy the original mini_installer. 571 // Copy the original mini_installer.
531 base::FilePath mini_installer = 572 base::FilePath mini_installer =
532 work_dir.directory().Append(original_installer_path.BaseName()); 573 work_dir.directory().Append(original_installer_path.BaseName());
533 if (!base::CopyFile(original_installer_path, mini_installer)) { 574 if (!base::CopyFile(original_installer_path, mini_installer)) {
534 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value() 575 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value()
535 << "\" to \"" << mini_installer.value() << "\""; 576 << "\" to \"" << mini_installer.value() << "\"";
536 return false; 577 return false;
537 } 578 }
538 579
539 base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]); 580 base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]);
540 base::FilePath chrome_packed_7z = 581 base::FilePath chrome_packed_7z; // Empty for component builds.
541 work_dir.directory().Append(&kChromePacked7z[0]); 582 base::FilePath chrome_7z;
583 const wchar_t* archive_resource_name = nullptr;
584 base::FilePath* archive_file = nullptr;
542 // Load the original file and extract setup.ex_ and chrome.packed.7z 585 // Load the original file and extract setup.ex_ and chrome.packed.7z
543 { 586 {
544 ResourceLoader resource_loader; 587 ResourceLoader resource_loader;
545 std::pair<const uint8_t*, DWORD> resource_data; 588 std::pair<const uint8_t*, DWORD> resource_data;
546 589
547 if (!resource_loader.Initialize(mini_installer)) 590 if (!resource_loader.Initialize(mini_installer))
548 return false; 591 return false;
549 592
550 // Write out setup.ex_ 593 // Write out setup.ex_
551 if (!resource_loader.Load(&kSetupEx_[0], &kBl[0], &resource_data)) 594 if (!resource_loader.Load(&kSetupEx_[0], &kBl[0], &resource_data))
552 return false; 595 return false;
553 int written = 596 int written =
554 base::WriteFile(setup_ex_, 597 base::WriteFile(setup_ex_,
555 reinterpret_cast<const char*>(resource_data.first), 598 reinterpret_cast<const char*>(resource_data.first),
556 static_cast<int>(resource_data.second)); 599 static_cast<int>(resource_data.second));
557 if (written != static_cast<int>(resource_data.second)) { 600 if (written != static_cast<int>(resource_data.second)) {
558 LOG(DFATAL) << "Failed writing \"" << setup_ex_.value() << "\""; 601 LOG(DFATAL) << "Failed writing \"" << setup_ex_.value() << "\"";
559 return false; 602 return false;
560 } 603 }
561 604
562 // Write out chrome.packed.7z 605 // Write out chrome.packed.7z (static build) or chrome.7z (component build)
563 if (!resource_loader.Load(&kChromePacked7z[0], &kB7[0], &resource_data)) 606 if (resource_loader.Load(&kChromePacked7z[0], &kB7[0], &resource_data)) {
607 archive_resource_name = &kChromePacked7z[0];
608 chrome_packed_7z = work_dir.directory().Append(archive_resource_name);
609 archive_file = &chrome_packed_7z;
610 } else if (resource_loader.Load(&kChrome7z[0], &kB7[0], &resource_data)) {
611 archive_resource_name = &kChrome7z[0];
612 chrome_7z = work_dir.directory().Append(archive_resource_name);
613 archive_file = &chrome_7z;
614 } else {
564 return false; 615 return false;
565 written = 616 }
566 base::WriteFile(chrome_packed_7z, 617 DCHECK(archive_resource_name);
567 reinterpret_cast<const char*>(resource_data.first), 618 DCHECK(!chrome_packed_7z.empty() || !chrome_7z.empty());
568 static_cast<int>(resource_data.second)); 619 DCHECK(archive_file);
620 written = base::WriteFile(
621 *archive_file, reinterpret_cast<const char*>(resource_data.first),
622 static_cast<int>(resource_data.second));
569 if (written != static_cast<int>(resource_data.second)) { 623 if (written != static_cast<int>(resource_data.second)) {
570 LOG(DFATAL) << "Failed writing \"" << chrome_packed_7z.value() << "\""; 624 LOG(DFATAL) << "Failed writing \"" << archive_file->value() << "\"";
571 return false; 625 return false;
572 } 626 }
573 } 627 }
574 628
575 // Expand setup.ex_ 629 // Expand setup.ex_
576 base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]); 630 base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]);
577 std::wstring command_line; 631 std::wstring command_line;
578 command_line.append(1, L'"') 632 command_line.append(1, L'"')
579 .append(&kExpandExe[0]) 633 .append(&kExpandExe[0])
580 .append(L"\" \"") 634 .append(L"\" \"")
581 .append(setup_ex_.value()) 635 .append(setup_ex_.value())
582 .append(L"\" \"") 636 .append(L"\" \"")
583 .append(setup_exe.value()) 637 .append(setup_exe.value())
584 .append(1, L'\"'); 638 .append(1, L'\"');
585 int exit_code; 639 int exit_code;
586 if (!RunProcessAndWait(NULL, command_line, &exit_code)) 640 if (!RunProcessAndWait(NULL, command_line, &exit_code))
587 return false; 641 return false;
588 if (exit_code != 0) { 642 if (exit_code != 0) {
589 LOG(DFATAL) << &kExpandExe[0] << " exited with code " << exit_code; 643 LOG(DFATAL) << &kExpandExe[0] << " exited with code " << exit_code;
590 return false; 644 return false;
591 } 645 }
592 646
593 // Unpack chrome.packed.7z 647 // Unpack chrome.packed.7z (static build only).
594 std::wstring chrome_7z_name; 648 if (!chrome_packed_7z.empty()) {
595 if (LzmaUtil::UnPackArchive(chrome_packed_7z.value(), 649 base::string16 chrome_7z_name;
596 work_dir.directory().value(), 650 if (LzmaUtil::UnPackArchive(chrome_packed_7z.value(),
597 &chrome_7z_name) != NO_ERROR) { 651 work_dir.directory().value(),
598 LOG(DFATAL) << "Failed unpacking \"" << chrome_packed_7z.value() << "\""; 652 &chrome_7z_name) != NO_ERROR) {
599 return false; 653 LOG(DFATAL) << "Failed unpacking \"" << chrome_packed_7z.value() << "\"";
654 return false;
655 }
656 chrome_7z = base::FilePath(chrome_7z_name);
600 } 657 }
658 DCHECK(!chrome_7z.empty());
601 659
602 // Unpack chrome.7z 660 // Unpack chrome.7z
603 if (LzmaUtil::UnPackArchive(chrome_7z_name, work_dir.directory().value(), 661 if (LzmaUtil::UnPackArchive(chrome_7z.value(), work_dir.directory().value(),
604 NULL) != NO_ERROR) { 662 NULL) != NO_ERROR) {
605 LOG(DFATAL) << "Failed unpacking \"" << chrome_7z_name << "\""; 663 LOG(DFATAL) << "Failed unpacking \"" << chrome_7z.value() << "\"";
606 return false; 664 return false;
607 } 665 }
608 666
609 // Get rid of intermediate files 667 // Get rid of intermediate files
610 base::FilePath chrome_7z(chrome_7z_name);
611 if (!base::DeleteFile(chrome_7z, false) || 668 if (!base::DeleteFile(chrome_7z, false) ||
612 !base::DeleteFile(chrome_packed_7z, false) || 669 (!chrome_packed_7z.empty() &&
670 !base::DeleteFile(chrome_packed_7z, false)) ||
613 !base::DeleteFile(setup_ex_, false)) { 671 !base::DeleteFile(setup_ex_, false)) {
614 LOG(DFATAL) << "Failed deleting intermediate files"; 672 LOG(DFATAL) << "Failed deleting intermediate files";
615 return false; 673 return false;
616 } 674 }
617 675
618 // Increment the version in all files. 676 // Increment the version in all files.
619 ApplyAlternateVersion(work_dir.directory(), direction, original_version, 677 ApplyAlternateVersion(work_dir.directory(), direction, original_version,
620 new_version); 678 new_version);
621 679
622 // Pack up files into chrome.7z 680 // Pack up files into chrome.7z
623 if (!CreateArchive(chrome_7z, work_dir.directory().Append(&kChromeBin[0]), 0)) 681 if (!CreateArchive(chrome_7z, work_dir.directory().Append(&kChromeBin[0]), 0))
624 return false; 682 return false;
625 683
626 // Compress chrome.7z into chrome.packed.7z 684 // Compress chrome.7z into chrome.packed.7z for static builds.
627 if (!CreateArchive(chrome_packed_7z, chrome_7z, 9)) 685 if (!chrome_packed_7z.empty() &&
686 !CreateArchive(chrome_packed_7z, chrome_7z, 9)) {
628 return false; 687 return false;
688 }
629 689
630 // Compress setup.exe into setup.ex_ 690 // Compress setup.exe into setup.ex_
631 command_line.assign(1, L'"') 691 command_line.assign(1, L'"')
632 .append(&kMakeCab[0]) 692 .append(&kMakeCab[0])
633 .append(L"\" /D CompressionType=LZX /L \"") 693 .append(L"\" /D CompressionType=LZX /L \"")
634 .append(work_dir.directory().value()) 694 .append(work_dir.directory().value())
635 .append(L"\" \"") 695 .append(L"\" \"")
636 .append(setup_exe.value()); 696 .append(setup_exe.value());
637 if (!RunProcessAndWait(NULL, command_line, &exit_code)) 697 if (!RunProcessAndWait(NULL, command_line, &exit_code))
638 return false; 698 return false;
639 if (exit_code != 0) { 699 if (exit_code != 0) {
640 LOG(DFATAL) << &kMakeCab[0] << " exited with code " << exit_code; 700 LOG(DFATAL) << &kMakeCab[0] << " exited with code " << exit_code;
641 return false; 701 return false;
642 } 702 }
643 703
644 // Replace the mini_installer's setup.ex_ and chrome.packed.7z resources. 704 // Replace the mini_installer's setup.ex_ and chrome.packed.7z (or chrome.7z
705 // in component builds) resources.
645 ResourceUpdater updater; 706 ResourceUpdater updater;
646 if (!updater.Initialize(mini_installer) || 707 if (!updater.Initialize(mini_installer) ||
647 !updater.Update(&kSetupEx_[0], &kBl[0], 708 !updater.Update(&kSetupEx_[0], &kBl[0],
648 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 709 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
649 setup_ex_) || 710 setup_ex_) ||
650 !updater.Update(&kChromePacked7z[0], &kB7[0], 711 !updater.Update(archive_resource_name, &kB7[0],
651 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 712 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
652 chrome_packed_7z) || 713 *archive_file) ||
653 !updater.Commit()) { 714 !updater.Commit()) {
715 LOG(ERROR) << "It is common for this step to fail for very large resources,"
716 " as is the case for Debug component=shared_library builds. "
717 "Try with a Release or component=static_library build.";
654 return false; 718 return false;
655 } 719 }
656 720
657 // Finally, move the updated mini_installer into place. 721 // Finally, move the updated mini_installer into place.
658 return base::Move(mini_installer, target_path); 722 return base::Move(mini_installer, target_path);
659 } 723 }
660 724
661 bool GenerateAlternatePEFileVersion(const base::FilePath& original_file, 725 bool GenerateAlternatePEFileVersion(const base::FilePath& original_file,
662 const base::FilePath& target_file, 726 const base::FilePath& target_file,
663 Direction direction) { 727 Direction direction) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 return false; 762 return false;
699 } 763 }
700 ctx.current_version_str = ctx.current_version.ToString(); 764 ctx.current_version_str = ctx.current_version.ToString();
701 ctx.new_version = ChromeVersion::FromString(version.GetString()); 765 ctx.new_version = ChromeVersion::FromString(version.GetString());
702 ctx.new_version_str = ctx.new_version.ToString(); 766 ctx.new_version_str = ctx.new_version.ToString();
703 767
704 return UpdateVersionIfMatch(target_file, &ctx); 768 return UpdateVersionIfMatch(target_file, &ctx);
705 } 769 }
706 770
707 } // namespace upgrade_test 771 } // namespace upgrade_test
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/test/resource_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698