OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 | |
7 """Download recipe prerequisites and run a single recipe.""" | |
8 | |
9 | |
10 import base64 | |
11 import json | |
12 import os | |
13 import subprocess | |
14 import sys | |
15 import tarfile | |
16 import urllib2 | |
17 import zlib | |
18 | |
19 | |
20 def download(source, dest): | |
21 u = urllib2.urlopen(source) # TODO: Verify certificate? | |
22 with open(dest, 'wb') as f: | |
23 while True: | |
24 buf = u.read(8192) | |
25 if not buf: | |
26 break | |
27 f.write(buf) | |
28 | |
29 | |
30 def unzip(source, dest): | |
31 with tarfile.open(source, 'r') as z: | |
32 z.extractall(dest) | |
33 | |
34 | |
35 def get_infra(dt_dir, root_dir): | |
36 fetch = os.path.join(dt_dir, 'fetch.py') | |
37 subprocess.check_call([sys.executable, fetch, 'infra'], cwd=root_dir) | |
38 | |
39 | |
40 def seed_properties(args): | |
41 # Assumes args[0] is factory properties and args[1] is build properties. | |
42 fact_prop_str = args[0][len('--factory-properties-gz='):] | |
43 build_prop_str = args[1][len('--build-properties-gz='):] | |
44 fact_prop = json.loads(zlib.decompress(base64.b64decode(fact_prop_str))) | |
45 build_prop = json.loads(zlib.decompress(base64.b64decode(build_prop_str))) | |
46 for k, v in fact_prop.iteritems(): | |
47 print '@@@SET_BUILD_PROPERTY@%s@%s@@@' % (k, v) | |
48 for k, v in build_prop.iteritems(): | |
49 print '@@@SET_BUILD_PROPERTY@%s@%s@@@' % (k, v) | |
50 | |
51 | |
52 def main(args): | |
53 cwd = os.getcwd() | |
54 | |
55 # Bootstrap depot tools (required for fetching build/infra) | |
56 dt_url = 'https://storage.googleapis.com/dumbtest/depot_tools.tar.gz' | |
57 dt_dir = os.path.join(cwd, 'staging') | |
58 os.makedirs(dt_dir) | |
59 dt_zip = os.path.join(dt_dir, 'depot_tools.tar.gz') | |
60 download(dt_url, os.path.join(dt_zip)) | |
61 unzip(dt_zip, dt_dir) | |
62 dt_path = os.path.join(dt_dir, 'depot_tools') | |
63 os.environ['PATH'] = '%s:%s' % (dt_path, os.environ['PATH']) | |
64 | |
65 # Fetch infra (which comes with build, which comes with recipes) | |
66 root_dir = os.path.join(cwd, 'b') | |
67 os.makedirs(root_dir) | |
68 get_infra(dt_path, root_dir) | |
69 work_dir = os.path.join(root_dir, 'build', 'slave', 'bot', 'build') | |
70 os.makedirs(work_dir) | |
71 | |
72 # Emit annotations that encapsulates build properties. | |
73 seed_properties(args) | |
74 | |
75 # JUST DO IT. | |
76 cmd = [sys.executable, '-u', '../../../scripts/slave/annotated_run.py'] | |
77 cmd.extend(args) | |
78 subprocess.check_call(cmd, cwd=work_dir) | |
79 | |
80 if __name__ == '__main__': | |
81 sys.exit(main(sys.argv[1:])) | |
OLD | NEW |