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 = [ 39 'libc++_chrome.dylib', 40 'libchrome_zlib.dylib', 41 'libthird_party_abseil-cpp_absl.dylib', 42 'libvk_swiftshader.dylib', 43 ] 44 45else: 46 # Must be Linux 47 chrome_folder = '/opt/google/chrome-unstable' 48 libs_to_copy = ['libGLESv2.so', 'libEGL.so'] 49 optional_libs_to_copy = ['libchrome_zlib.so', 'libabsl.so', 'libc++.so'] 50 51# Find the most recent ANGLE DLLs 52binary_name = libs_to_copy[0] 53newest_folder = None 54newest_mtime = None 55for path in source_paths: 56 binary_path = os.path.join(path, binary_name) 57 if os.path.exists(binary_path): 58 binary_mtime = os.path.getmtime(binary_path) 59 if (newest_folder is None) or (binary_mtime > newest_mtime): 60 newest_folder = path 61 newest_mtime = binary_mtime 62 63if newest_folder is None: 64 sys.exit("Could not find ANGLE binaries!") 65 66source_folder = newest_folder 67 68if is_windows: 69 # Is a folder a chrome binary directory? 70 def is_chrome_bin(str): 71 chrome_file = os.path.join(chrome_folder, str) 72 return os.path.isdir(chrome_file) and all([char.isdigit() or char == '.' for char in str]) 73 74 sorted_chrome_bins = sorted( 75 [folder for folder in os.listdir(chrome_folder) if is_chrome_bin(folder)], reverse=True) 76 77 dest_folder = os.path.join(chrome_folder, sorted_chrome_bins[0]) 78else: 79 dest_folder = chrome_folder 80 81print('Copying binaries from ' + source_folder + ' to ' + dest_folder + '.') 82 83 84def copy_file(src, dst): 85 print(' - ' + src + ' --> ' + dst) 86 if is_macos and os.path.isfile(dst): 87 # For the codesign to work, the original file must be removed 88 os.remove(dst) 89 shutil.copyfile(src, dst) 90 91 92def do_copy(filename, is_optional): 93 src = os.path.join(source_folder, filename) 94 if os.path.exists(src): 95 # No backup is made. Any backup becomes stale on the next update and could be a cause for 96 # confusion. Reintall Chromium if it needs to be recovered. 97 dst = os.path.join(dest_folder, filename) 98 copy_file(src, dst) 99 100 if is_windows: 101 copy_file(src + '.pdb', dst + '.pdb') 102 103 elif not is_optional: 104 print(' - COULD NOT FIND "' + src + '"') 105 106 107for filename in libs_to_copy: 108 do_copy(filename, False) 109# Optionally copy the following, which are needed for a component build 110# (i.e. is_component_build = true, which is the default) 111for filename in optional_libs_to_copy: 112 do_copy(filename, True) 113 114if is_macos: 115 # Clear all attributes, codesign doesn't work otherwise 116 os.system('xattr -cr /Applications/Google\ Chrome\ Canary.app') 117 # Re-sign the bundle 118 os.system('codesign --force --sign - --deep /Applications/Google\ Chrome\ Canary.app') 119