xref: /aosp_15_r20/external/angle/tools/angle_tools.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1#!/usr/bin/python3
2#
3# Copyright 2019 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# angle_tools.py:
8#   Common functionality to scripts in angle/tools directory.
9
10import os
11import platform
12import subprocess
13
14is_windows = platform.system() == 'Windows'
15is_linux = platform.system() == 'Linux'
16is_mac = platform.system() == 'Darwin'
17
18
19def find_file_in_path(filename):
20    """ Finds |filename| by searching the environment paths """
21    path_delimiter = ';' if is_windows else ':'
22    for env_path in os.environ['PATH'].split(path_delimiter):
23        full_path = os.path.join(env_path, filename)
24        if os.path.isfile(full_path):
25            return full_path
26    raise Exception('Cannot find %s in environment' % filename)
27
28
29def get_exe_name(file_name, windows_extension):
30    exe_name = file_name
31    if is_windows:
32        exe_name += windows_extension
33    return exe_name
34
35
36def upload_to_google_storage(bucket, files):
37    file_dir = os.path.dirname(os.path.realpath(__file__))
38    upload_script = os.path.join(file_dir, '..', 'third_party', 'depot_tools',
39                                 'upload_to_google_storage.py')
40    upload_args = ['python3', upload_script, '-b', bucket] + files
41    return subprocess.call(upload_args) == 0
42
43
44def stage_google_storage_sha1(files):
45    git_exe = get_exe_name('git', '.bat')
46    git_exe = find_file_in_path(git_exe)
47
48    sha1_files = [f + '.sha1' for f in files]
49    return subprocess.call([git_exe, 'add'] + sha1_files) == 0
50