1#!/usr/bin/python3 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_chrome_angle.py: 8# Helper script that copies ANGLE libraries into the Chromium Canary (on Windows and macOS) 9# or Dev (on Linux) installed directory. Testing ANGLE this way is much faster than compiling 10# Chromium from source. The script checks for the most recent build in a set of search paths, 11# and copies that into: 12# 13# - /opt/google/chrome-unstable on Linux 14# - the most recent Canary installation folder on Windows. 15# - /Applications/Google\ Chrome\ Canary.app on macOS 16# 17 18import glob, sys, os, shutil 19 20# Set of search paths. 21script_dir = os.path.dirname(sys.argv[0]) 22os.chdir(os.path.join(script_dir, "..")) 23 24source_paths = glob.glob('out/*') 25 26is_windows = sys.platform == 'cygwin' or sys.platform.startswith('win') 27is_macos = sys.platform == 'darwin' 28 29if is_windows: 30 # Default Canary installation path. 31 chrome_folder = os.path.join(os.environ['LOCALAPPDATA'], 'Google', 'Chrome SxS', 'Application') 32 libs_to_copy = ['libGLESv2.dll', 'libEGL.dll'] 33 optional_libs_to_copy = [] 34 35elif is_macos: 36 chrome_folder = '/Applications/Google Chrome Canary.app/Contents/Frameworks/Google Chrome Framework.framework/Libraries' 37 libs_to_copy = ['libGLESv2.dylib', 'libEGL.dylib'] 38 optional_libs_to_copy = ['libchrome_zlib.dylib', 'libabsl.dylib', 'libc++.dylib'] 39 40else: 41 # Must be Linux 42 chrome_folder = '/opt/google/chrome-unstable' 43 libs_to_copy = ['libGLESv2.so', 'libEGL.so'] 44 optional_libs_to_copy = ['libchrome_zlib.so', 'libabsl.so', 'libc++.so'] 45 46# Find the most recent ANGLE DLLs 47binary_name = libs_to_copy[0] 48newest_folder = None 49newest_mtime = None 50for path in source_paths: 51 binary_path = os.path.join(path, binary_name) 52 if os.path.exists(binary_path): 53 binary_mtime = os.path.getmtime(binary_path) 54 if (newest_folder is None) or (binary_mtime > newest_mtime): 55 newest_folder = path 56 newest_mtime = binary_mtime 57 58if newest_folder is None: 59 sys.exit("Could not find ANGLE binaries!") 60 61source_folder = newest_folder 62 63if is_windows: 64 # Is a folder a chrome binary directory? 65 def is_chrome_bin(str): 66 chrome_file = os.path.join(chrome_folder, str) 67 return os.path.isdir(chrome_file) and all([char.isdigit() or char == '.' for char in str]) 68 69 sorted_chrome_bins = sorted( 70 [folder for folder in os.listdir(chrome_folder) if is_chrome_bin(folder)], reverse=True) 71 72 dest_folder = os.path.join(chrome_folder, sorted_chrome_bins[0]) 73else: 74 dest_folder = chrome_folder 75 76print('Copying binaries from ' + source_folder + ' to ' + dest_folder + '.') 77 78 79def copy_file(src, dst): 80 print(' - ' + src + ' --> ' + dst) 81 if is_macos and os.path.isfile(dst): 82 # For the codesign to work, the original file must be removed 83 os.remove(dst) 84 shutil.copyfile(src, dst) 85 86 87def do_copy(filename, is_optional): 88 src = os.path.join(source_folder, filename) 89 if os.path.exists(src): 90 # No backup is made. Any backup becomes stale on the next update and could be a cause for 91 # confusion. Reintall Chromium if it needs to be recovered. 92 dst = os.path.join(dest_folder, filename) 93 copy_file(src, dst) 94 95 if is_windows: 96 copy_file(src + '.pdb', dst + '.pdb') 97 98 elif not is_optional: 99 print(' - COULD NOT FIND "' + src + '"') 100 101 102for filename in libs_to_copy: 103 do_copy(filename, False) 104# Optionally copy the following, which are needed for a component build 105# (i.e. is_component_build = true, which is the default) 106for filename in optional_libs_to_copy: 107 do_copy(filename, True) 108 109if is_macos: 110 # Clear all attributes, codesign doesn't work otherwise 111 os.system('xattr -cr /Applications/Google\ Chrome\ Canary.app') 112 # Re-sign the bundle 113 os.system('codesign --force --sign - --deep /Applications/Google\ Chrome\ Canary.app') 114