1#!/usr/bin/python2
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'
16
17
18def find_file_in_path(filename):
19    """ Finds |filename| by searching the environment paths """
20    path_delimiter = ';' if is_windows else ':'
21    for env_path in os.environ['PATH'].split(path_delimiter):
22        full_path = os.path.join(env_path, filename)
23        if os.path.isfile(full_path):
24            return full_path
25    raise Exception('Cannot find %s in environment' % filename)
26
27
28def get_exe_name(file_name, windows_extension):
29    exe_name = file_name
30    if is_windows:
31        exe_name += windows_extension
32    return exe_name
33
34
35def upload_to_google_storage(bucket, files):
36    upload_script = find_file_in_path('upload_to_google_storage.py')
37    upload_args = ['python', upload_script, '-b', bucket] + files
38    return subprocess.call(upload_args) == 0
39
40
41def stage_google_storage_sha1(files):
42    git_exe = get_exe_name('git', '.bat')
43    git_exe = find_file_in_path(git_exe)
44
45    sha1_files = [f + '.sha1' for f in files]
46    return subprocess.call([git_exe, 'add'] + sha1_files) == 0
47