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) or Dev (on 9# Linux) installed directory. Testing ANGLE this way is much faster than compiling Chromium from 10# source. The script checks for the most recent build in a set of search paths, and copies that 11# into: 12# 13# - /opt/google/chrome-unstable on Linux 14# - the most recent Canary installation folder on Windows. 15# 16# Only works on Linux and Windows. 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') 27 28if is_windows: 29 # Default Canary installation path. 30 chrome_folder = os.path.join(os.environ['LOCALAPPDATA'], 'Google', 'Chrome SxS', 'Application') 31 libs_to_copy = ['libGLESv2.dll', 'libEGL.dll'] 32 optional_libs_to_copy = [] 33 34else: 35 # Must be Linux 36 chrome_folder = '/opt/google/chrome-unstable' 37 libs_to_copy = ['libGLESv2.so', 'libEGL.so'] 38 # Optionally copy the following, which are needed for a component build 39 # (i.e. is_component_build = true, which is the default) 40 optional_libs_to_copy = ['libchrome_zlib.so', 'libabsl.so', 'libc++.so'] 41 42# Find the most recent ANGLE DLLs 43binary_name = libs_to_copy[0] 44newest_folder = None 45newest_mtime = None 46for path in source_paths: 47 binary_path = os.path.join(path, binary_name) 48 if os.path.exists(binary_path): 49 binary_mtime = os.path.getmtime(binary_path) 50 if (newest_folder is None) or (binary_mtime > newest_mtime): 51 newest_folder = path 52 newest_mtime = binary_mtime 53 54if newest_folder is None: 55 sys.exit("Could not find ANGLE binaries!") 56 57source_folder = newest_folder 58 59if is_windows: 60 # Is a folder a chrome binary directory? 61 def is_chrome_bin(str): 62 chrome_file = os.path.join(chrome_folder, str) 63 return os.path.isdir(chrome_file) and all([char.isdigit() or char == '.' for char in str]) 64 65 sorted_chrome_bins = sorted( 66 [folder for folder in os.listdir(chrome_folder) if is_chrome_bin(folder)], reverse=True) 67 68 dest_folder = os.path.join(chrome_folder, sorted_chrome_bins[0]) 69else: 70 dest_folder = chrome_folder 71 72print('Copying binaries from ' + source_folder + ' to ' + dest_folder + '.') 73 74 75def copy_file(src, dst): 76 print(' - ' + src + ' --> ' + dst) 77 shutil.copyfile(src, dst) 78 79 80def do_copy(filename, is_optional): 81 src = os.path.join(source_folder, filename) 82 if os.path.exists(src): 83 # No backup is made. Any backup becomes stale on the next update and could be a cause for 84 # confusion. Reintall Chromium if it needs to be recovered. 85 dst = os.path.join(dest_folder, filename) 86 copy_file(src, dst) 87 88 if is_windows: 89 copy_file(src + '.pdb', dst + '.pdb') 90 91 elif not is_optional: 92 print(' - COULD NOT FIND "' + src + '"') 93 94 95for filename in libs_to_copy: 96 do_copy(filename, False) 97for filename in optional_libs_to_copy: 98 do_copy(filename, True) 99