mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00

Always use gn.py in depot_tools instead of just gn. The https://cs.chromium.org/chromium/src/build/find_depot_tools.py is looking up the DEPS-pinned copy in third_party/depot_tools and adds it to the path when add_depot_tools_to_path() is called. Similar use: https: //cs.chromium.org/search/?q=%22find_depot_tools.add_depot_tools_to_path()%22&sq=package:chromium&type=cs Bug: webrtc:8393 Change-Id: I3cfa3d96b4d0f60e8099e556876bc94340b1bbb5 Reviewed-on: https://webrtc-review.googlesource.com/12540 Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Patrik Höglund <phoglund@google.com> Commit-Queue: Henrik Kjellander <kjellander@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20333}
132 lines
3.9 KiB
Python
Executable file
132 lines
3.9 KiB
Python
Executable file
#!/usr/bin/env python
|
|
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
|
#
|
|
# Use of this source code is governed by a BSD-style license
|
|
# that can be found in the LICENSE file in the root of the source
|
|
# tree. An additional intellectual property rights grant can be found
|
|
# in the file PATENTS. All contributing project authors may
|
|
# be found in the AUTHORS file in the root of the source tree.
|
|
|
|
"""Utilities for all our deps-management stuff."""
|
|
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import subprocess
|
|
import tarfile
|
|
import time
|
|
import zipfile
|
|
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
SRC_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
|
|
sys.path.append(os.path.join(SRC_DIR, 'build'))
|
|
|
|
|
|
import find_depot_tools
|
|
|
|
|
|
def RunSubprocessWithRetry(cmd):
|
|
"""Invokes the subprocess and backs off exponentially on fail."""
|
|
for i in range(5):
|
|
try:
|
|
subprocess.check_call(cmd)
|
|
return
|
|
except subprocess.CalledProcessError as exception:
|
|
backoff = pow(2, i)
|
|
print 'Got %s, retrying in %d seconds...' % (exception, backoff)
|
|
time.sleep(backoff)
|
|
|
|
print 'Giving up.'
|
|
raise exception
|
|
|
|
|
|
def DownloadFilesFromGoogleStorage(path, auto_platform=True):
|
|
print 'Downloading files in %s...' % path
|
|
|
|
cmd = [
|
|
sys.executable,
|
|
os.path.join(find_depot_tools.DEPOT_TOOLS_PATH,
|
|
'download_from_google_storage.py'),
|
|
'--bucket=chromium-webrtc-resources',
|
|
'--directory',
|
|
path,
|
|
]
|
|
if auto_platform:
|
|
cmd += ['--auto_platform', '--recursive']
|
|
subprocess.check_call(cmd)
|
|
|
|
|
|
# Code partially copied from
|
|
# https://cs.chromium.org#chromium/build/scripts/common/chromium_utils.py
|
|
def RemoveDirectory(*path):
|
|
"""Recursively removes a directory, even if it's marked read-only.
|
|
|
|
Remove the directory located at *path, if it exists.
|
|
|
|
shutil.rmtree() doesn't work on Windows if any of the files or directories
|
|
are read-only, which svn repositories and some .svn files are. We need to
|
|
be able to force the files to be writable (i.e., deletable) as we traverse
|
|
the tree.
|
|
|
|
Even with all this, Windows still sometimes fails to delete a file, citing
|
|
a permission error (maybe something to do with antivirus scans or disk
|
|
indexing). The best suggestion any of the user forums had was to wait a
|
|
bit and try again, so we do that too. It's hand-waving, but sometimes it
|
|
works. :/
|
|
"""
|
|
file_path = os.path.join(*path)
|
|
print 'Deleting `{}`.'.format(file_path)
|
|
if not os.path.exists(file_path):
|
|
print '`{}` does not exist.'.format(file_path)
|
|
return
|
|
|
|
if sys.platform == 'win32':
|
|
# Give up and use cmd.exe's rd command.
|
|
file_path = os.path.normcase(file_path)
|
|
for _ in xrange(3):
|
|
print 'RemoveDirectory running %s' % (' '.join(
|
|
['cmd.exe', '/c', 'rd', '/q', '/s', file_path]))
|
|
if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', file_path]):
|
|
break
|
|
print ' Failed'
|
|
time.sleep(3)
|
|
return
|
|
else:
|
|
shutil.rmtree(file_path, ignore_errors=True)
|
|
|
|
|
|
def UnpackArchiveTo(archive_path, output_dir):
|
|
extension = os.path.splitext(archive_path)[1]
|
|
if extension == '.zip':
|
|
_UnzipArchiveTo(archive_path, output_dir)
|
|
else:
|
|
_UntarArchiveTo(archive_path, output_dir)
|
|
|
|
|
|
def _UnzipArchiveTo(archive_path, output_dir):
|
|
print 'Unzipping {} in {}.'.format(archive_path, output_dir)
|
|
zip_file = zipfile.ZipFile(archive_path)
|
|
try:
|
|
zip_file.extractall(output_dir)
|
|
finally:
|
|
zip_file.close()
|
|
|
|
|
|
def _UntarArchiveTo(archive_path, output_dir):
|
|
print 'Untarring {} in {}.'.format(archive_path, output_dir)
|
|
tar_file = tarfile.open(archive_path, 'r:gz')
|
|
try:
|
|
tar_file.extractall(output_dir)
|
|
finally:
|
|
tar_file.close()
|
|
|
|
|
|
def GetPlatform():
|
|
if sys.platform.startswith('win'):
|
|
return 'win'
|
|
if sys.platform.startswith('linux'):
|
|
return 'linux'
|
|
if sys.platform.startswith('darwin'):
|
|
return 'mac'
|
|
raise Exception("Can't run on platform %s." % sys.platform)
|