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