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' 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 file_dir = os.path.dirname(os.path.realpath(__file__)) 37 upload_script = os.path.join(file_dir, '..', 'third_party', 'depot_tools', 38 'upload_to_google_storage.py') 39 upload_args = ['python', upload_script, '-b', bucket] + files 40 return subprocess.call(upload_args) == 0 41 42 43def stage_google_storage_sha1(files): 44 git_exe = get_exe_name('git', '.bat') 45 git_exe = find_file_in_path(git_exe) 46 47 sha1_files = [f + '.sha1' for f in files] 48 return subprocess.call([git_exe, 'add'] + sha1_files) == 0 49