Debian Codegraph @

infra/bots/assets/linux_vulkan_sdk/create.py

raw
1 #!/usr/bin/env python
2 #
3 # Copyright 2016 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """Create the asset."""
10
11
12 import argparse
13 import hashlib
14 import os
15 import subprocess
16 import sys
17
18 FILE_DIR = os.path.dirname(os.path.abspath(__file__))
19 INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
20 sys.path.insert(0, INFRA_BOTS_DIR)
21 import utils
22
23 # https://vulkan.lunarg.com/sdk/home
24 SDK_VERSION='1.4.321.1'
25 SDK_SHA256='f22a3625bd4d7a32e7a0d926ace16d5278c149e938dac63cecc00537626cbf73'
26 SDK_URL=('https://sdk.lunarg.com/sdk/download/%s/linux/'
27 'vulkansdk-linux-x86_64-%s.tar.xz' % (SDK_VERSION, SDK_VERSION))
28
29
30 def create_asset(target_dir):
31 """Create the asset."""
32 with utils.tmp_dir():
33 tarball = 'vulkansdk-linux.tar.xz'
34 # Use -L to follow redirects.
35 subprocess.check_call(['curl', '-L', SDK_URL, '--output', tarball])
36
37 # Verify the SHA256 hash.
38 with open(tarball, 'rb') as f:
39 actual_hash = hashlib.sha256(f.read()).hexdigest()
40 if actual_hash != SDK_SHA256:
41 raise Exception('SHA256 mismatch for %s. Expected %s, got %s' %
42 (tarball, SDK_SHA256, actual_hash))
43
44 subprocess.check_call(['tar', '--extract', '--verbose',
45 '--file=%s' % tarball,
46 '--directory=%s' % target_dir,
47 '--strip-components=2',
48 '%s/x86_64' % SDK_VERSION])
49
50
51 def main():
52 if 'linux' not in sys.platform:
53 print('This script only runs on Linux.', file=sys.stderr)
54 sys.exit(1)
55 parser = argparse.ArgumentParser()
56 parser.add_argument('--target_dir', '-t', required=True)
57 args = parser.parse_args()
58 create_asset(args.target_dir)
59
60
61 if __name__ == '__main__':
62 main()