build: move external binaries to S3 (#21829)
This commit is contained in:
parent
c92edc8fc4
commit
dd95a6f034
2 changed files with 29 additions and 42 deletions
|
@ -12,6 +12,7 @@ from lib.util import add_exec_bit, download, extract_zip, rm_rf, \
|
|||
safe_mkdir, tempdir
|
||||
|
||||
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
CONFIG_PATH = os.path.join(SOURCE_ROOT, 'script', 'external-binaries.json')
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
|
@ -25,8 +26,7 @@ def parse_args():
|
|||
|
||||
|
||||
def parse_config():
|
||||
config_path = os.path.join(SOURCE_ROOT, 'script', 'external-binaries.json')
|
||||
with open(config_path, 'r') as config_file:
|
||||
with open(CONFIG_PATH, 'r') as config_file:
|
||||
config = json.load(config_file)
|
||||
return config
|
||||
|
||||
|
@ -36,21 +36,21 @@ def main():
|
|||
config = parse_config()
|
||||
|
||||
base_url = args.base_url if args.base_url is not None else config['baseUrl']
|
||||
version = config['version']
|
||||
|
||||
output_dir = os.path.join(SOURCE_ROOT, 'external_binaries')
|
||||
version_file = os.path.join(output_dir, '.version')
|
||||
config_hash_path = os.path.join(output_dir, '.hash')
|
||||
|
||||
if (is_updated(version_file, version) and not args.force):
|
||||
if (not is_updated(config_hash_path) and not args.force):
|
||||
return
|
||||
|
||||
rm_rf(output_dir)
|
||||
safe_mkdir(output_dir)
|
||||
|
||||
for binary in config['binaries']:
|
||||
for binary in config['files']:
|
||||
if not binary_should_be_downloaded(binary):
|
||||
continue
|
||||
|
||||
temp_path = download_binary(base_url, version, binary['url'], binary['sha'])
|
||||
temp_path = download_binary(base_url, binary['sha'], binary['name'])
|
||||
|
||||
if temp_path.endswith('.zip'):
|
||||
extract_zip(temp_path, output_dir)
|
||||
|
@ -61,22 +61,22 @@ def main():
|
|||
|
||||
# Hack alert. Set exec bit for sccache binaries.
|
||||
# https://bugs.python.org/issue15795
|
||||
if 'sccache' in binary['url']:
|
||||
if 'sccache' in binary['name']:
|
||||
add_exec_bit_to_sccache_binary(output_dir)
|
||||
|
||||
with open(version_file, 'w') as f:
|
||||
f.write(version)
|
||||
with open(config_hash_path, 'w') as f:
|
||||
f.write(sha256(CONFIG_PATH))
|
||||
|
||||
|
||||
def is_updated(version_file, version):
|
||||
existing_version = ''
|
||||
def is_updated(config_hash_path):
|
||||
existing_hash = ''
|
||||
try:
|
||||
with open(version_file, 'r') as f:
|
||||
existing_version = f.readline().strip()
|
||||
with open(config_hash_path, 'r') as f:
|
||||
existing_hash = f.readline().strip()
|
||||
except IOError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
return existing_version == version
|
||||
return not sha256(CONFIG_PATH) == existing_hash
|
||||
|
||||
|
||||
def binary_should_be_downloaded(binary):
|
||||
|
@ -97,9 +97,9 @@ def sha256(file_path):
|
|||
return hash_256.hexdigest()
|
||||
|
||||
|
||||
def download_binary(base_url, version, binary_url, sha):
|
||||
full_url = '{0}/{1}/{2}'.format(base_url, version, binary_url)
|
||||
temp_path = download_to_temp_dir(full_url, filename=binary_url, sha=sha)
|
||||
def download_binary(base_url, sha, binary_name):
|
||||
full_url = '{0}/{1}/{2}'.format(base_url, sha, binary_name)
|
||||
temp_path = download_to_temp_dir(full_url, filename=binary_name, sha=sha)
|
||||
return temp_path
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue