Jamie Madill | 2be8c8c | 2016-04-28 14:39:15 -0400 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2016 The ANGLE Project Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
| 7 | # update_canary_angle.py: |
| 8 | # Helper script that copies Windows ANGLE DLLs into the Canary |
| 9 | # application directory. Much faster than compiling Chrome from |
| 10 | # source. The script checks for the most recent DLLs in a set of |
| 11 | # search paths, and copies that into the most recent Canary |
| 12 | # binary folder. Only works on Windows. |
| 13 | |
| 14 | import sys, os, shutil |
| 15 | |
| 16 | # Set of search paths. |
| 17 | source_paths = [ |
| 18 | os.path.join('..', 'build', 'Debug_x64'), |
| 19 | os.path.join('..', 'build', 'Debug_Win32'), |
| 20 | os.path.join('..', 'build', 'Release_x64'), |
| 21 | os.path.join('..', 'build', 'Release_Win32'), |
| 22 | os.path.join('..', 'out', 'Debug'), |
| 23 | os.path.join('..', 'out', 'Debug_x64'), |
| 24 | os.path.join('..', 'out', 'Release'), |
| 25 | os.path.join('..', 'out', 'Release_x64'), |
| 26 | ] |
| 27 | |
| 28 | # Default Canary installation path. |
| 29 | chrome_folder = os.path.join(os.environ['LOCALAPPDATA'], 'Google', 'Chrome SxS', 'Application') |
| 30 | |
| 31 | # Find the most recent ANGLE DLLs |
| 32 | binary_name = 'libGLESv2.dll' |
| 33 | newest_folder = None |
| 34 | newest_mtime = None |
| 35 | for path in source_paths: |
| 36 | binary_path = os.path.join(path, binary_name) |
| 37 | if os.path.exists(binary_path): |
| 38 | binary_mtime = os.path.getmtime(binary_path) |
| 39 | if (newest_folder is None) or (binary_mtime > newest_mtime): |
| 40 | newest_folder = path |
| 41 | newest_mtime = binary_mtime |
| 42 | |
| 43 | source_folder = newest_folder |
| 44 | |
| 45 | # Is a folder a chrome binary directory? |
| 46 | def is_chrome_bin(str): |
| 47 | chrome_file = os.path.join(chrome_folder, str) |
| 48 | return os.path.isdir(chrome_file) and all([char.isdigit() or char == '.' for char in str]) |
| 49 | |
| 50 | sorted_chrome_bins = sorted([folder for folder in os.listdir(chrome_folder) if is_chrome_bin(folder)], reverse=True) |
| 51 | |
| 52 | dest_folder = os.path.join(chrome_folder, sorted_chrome_bins[0]) |
| 53 | |
| 54 | print('Copying DLLs from ' + source_folder + ' to ' + dest_folder + '.') |
| 55 | |
| 56 | # Translator.dll appears if we build in component=shared_library mode. |
| 57 | for dll in ['libGLESv2.dll', 'libEGL.dll', 'translator.dll']: |
| 58 | src = os.path.join(source_folder, dll) |
| 59 | if os.path.exists(src): |
| 60 | # Make a backup of the original unmodified DLLs if they are present. |
| 61 | backup = os.path.join(source_folder, dll + '.backup') |
| 62 | if not os.path.exists(backup): |
| 63 | shutil.copyfile(src, backup) |
| 64 | shutil.copyfile(src, os.path.join(dest_folder, dll)) |